如果我有一个有 10 个进程和 10 个线程的 Web 服务器,这意味着什么?
http://pypi.python.org/pypi/Spawning/
所以我正在玩产卵... 如果我用 10 个进程和 10 个线程运行它,这意味着什么?
我正在构建一个聊天室(使用 eventlet 进行长轮询)。这是否意味着聊天室中只能有 10 个人?
http://pypi.python.org/pypi/Spawning/
So I'm playing with Spawning...
If I run it with 10 process and 10 threads, what does that mean?
I'm building a chat room (long-polling using eventlet). Does that mean that only 10 people can be present in the chat room?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不。这完全取决于您的应用程序的架构。基于事件的应用程序可以在单个线程中支持大量连接(用户、会话、应用程序中的任何重要内容)。
当执行阻塞 IO 操作时,通常需要多个线程;当需要真正的计算负载分配时,通常需要多个进程。在诸如聊天应用程序之类的简单应用中,您可以轻松地避免两者的需要。标准 Python 库具有您可能会感兴趣的
asyncore
和asynchat
模块。 Twisted 库是一种更全面的方法。No. It all depends on the architecture of your application. Event-based apps can support large amounts of connections (users, sessions, whatever matters in your app) in a single thread.
You usually need multiple threads when you're performing blocking IO operations, and multiple processes when you need true computational load distribution. In something simple like a chat application, you can easily avoid the need for both. The standard Python library has the
asyncore
andasynchat
modules which you may find interesting. The Twisted library is a more comprehensive approach.不会。拥有一定数量的线程/进程不会对内容或客户端产生或更改任何类型的限制。拥有更多线程/进程可以在平衡应用程序时提高应用程序的性能,特别是在单线程或单进程架构仅限于一个 CPU 的 SMP 系统上。
No. Having a certain number of threads/processes doesn't create or change any kind of limit on the content or clients. Having more threads/processes can improve the performance of an application when balanced across them, especially on SMP systems where a single-thread or single-process architecture would be limited to one CPU.