为什么要重新初始化多进程工作者?
Why reinitialize multiprocess workers?
我在 Python 多处理池库文档中找到了这条注释:
Worker processes within a Pool typically live for the complete
duration of the Pool’s work queue. A frequent pattern found in other
systems (such as Apache, mod_wsgi, etc) to free resources held by
workers is to allow a worker within a pool to complete only a set
amount of work before being exiting, being cleaned up and a new
process spawned to replace the old one. The maxtasksperchild argument
to the Pool exposes this ability to the end user.
它说 Apache 和其他人重新初始化多进程实体,这使它成为一个很好的模式。是关于重新初始化对象(比如 "OOP" 对象)来调用垃圾收集器吗?它为什么如此重要?存在多处理对象时不能使用 GC?
主要用例之一是避免小泄漏(内存、fd、...)影响长 运行 服务。
由于软件并不完美,经常会出现某些库未正确清理的情况。由于这些问题不在开发人员的控制范围内,因此一个简单的解决方法是定期终止泄漏进程并重新开始。
另一个用例是控制服务的内存消耗。 Python 例如,内存碎片通常会导致工作人员消耗比需要更多的内存。
我在 Python 多处理池库文档中找到了这条注释:
Worker processes within a Pool typically live for the complete duration of the Pool’s work queue. A frequent pattern found in other systems (such as Apache, mod_wsgi, etc) to free resources held by workers is to allow a worker within a pool to complete only a set amount of work before being exiting, being cleaned up and a new process spawned to replace the old one. The maxtasksperchild argument to the Pool exposes this ability to the end user.
它说 Apache 和其他人重新初始化多进程实体,这使它成为一个很好的模式。是关于重新初始化对象(比如 "OOP" 对象)来调用垃圾收集器吗?它为什么如此重要?存在多处理对象时不能使用 GC?
主要用例之一是避免小泄漏(内存、fd、...)影响长 运行 服务。
由于软件并不完美,经常会出现某些库未正确清理的情况。由于这些问题不在开发人员的控制范围内,因此一个简单的解决方法是定期终止泄漏进程并重新开始。
另一个用例是控制服务的内存消耗。 Python 例如,内存碎片通常会导致工作人员消耗比需要更多的内存。