Python 多处理队列可扩展到大量工作人员
我有一个启动工作进程的 python(2.6.5 64 位,Windows 2008 Server R2)应用程序。父进程将作业放入作业队列中,工作人员从中获取作业。类似地,它有一个结果队列。每个工作人员通过查询服务器来执行其工作。工作人员的 CPU 使用率较低。
当工作人员数量增加时,服务器上的 CPU 使用率实际上会减少。服务器本身不是瓶颈,因为我可以从其他应用程序进一步加载它们。
还有其他人看到过类似的行为吗?当大量进程读取或写入同一队列时,python 多处理队列是否存在问题?
I have a python (2.6.5 64-bit, Windows 2008 Server R2) app that launches worker processes. The parent process puts jobs in a job queue, from which workers pick them up. Similarly it has a results queue. Each worker performs its job by querying a server. CPU usage by the workers is low.
When the number of workers grows, CPU usage on the servers actually shrinks. The servers themselves are not the bottleneck, as I can load them up further from other applications.
Anyone else seen similar behavior? Is there an issue with python multiprocessing queues when a large number of processes are reading or writing to the same queues?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于性能约束有两种不同的想法:
收集更多信息:
可能的改进:
Two different ideas for performance constraints:
Gathering more information:
Possible improvements:
除非您提供所有详细信息,否则不确定发生了什么。
但是,请记住,真正的并发性受到实际硬件线程数的限制。如果启动的进程数量远大于硬件线程的实际数量,则在某些时候上下文切换开销将超过拥有更多并发进程的好处。
Not exactly sure what is going on unless you provide all the details.
However, remember that the real concurrency is bounded by the actual number of hardware threads. If the number of processes launched is much larger than the actual number of hardware threads, at some point the context-switching overhead will be more than the benefit of having more concurrent processes.
创建新的 thead 是非常昂贵的操作。
控制大量并行网络连接的最简单方法之一是使用支持异步套接字的无堆栈线程。 Python 对此有很好的支持和大量的库。
我最喜欢的是 gevent,它具有出色且完全透明的猴子修补实用程序。
Creating of new thead is very expensive operation.
One of the simplest ways for controling a lot of paralell network connections is to use stackless threads with support of asyncronical sockets. Python had great support and a bunch of libraries for that.
My favorite one is gevent, which has a great and comletely transparent monkey-patching utility.