[英]Non-blocking http server , java nio , python tornado eventlet
Hi I am trying to Understand if tornado/eventlet based http sever are better than threaded sever. 嗨,我想了解基于tornado / eventlet的http服务器是否优于线程服务器。 While goggling the subject I am seeing that these are single thread event base server which run a single handler function after select/poll/epoll on socket.
在看到主题时,我看到这些是单线程事件基本服务器,它在套接字上的select / poll / epoll之后运行单个处理函数。
These questions are related and I would apprecite as I am not understanding these issues correctly 这些问题是相关的,我会很感激,因为我没有正确理解这些问题
Thanks 谢谢
Nonblocking servers are the best choice provided all your libraries provides nonblocking apis. 如果所有库都提供非阻塞apis,则非阻塞服务器是最佳选择。 As mentioned in your second question if a library blocks (eg database lib making a blocking call), the entire process/thread blocks and the system hangs.
如第二个问题所述,如果库阻塞(例如数据库lib进行阻塞调用),则整个进程/线程块和系统挂起。 Not all of the libraries available are asynchronous which makes it difficult to use tornado/eventlet for all usecases.
并非所有可用的库都是异步的,因此很难对所有用例使用tornado / eventlet。 Also in a multi-core box multiple instances of nonblocking servers needs to be started to use the box capacity completly.
此外,在多核盒中,需要启动多个非阻塞服务器实例以完全使用盒容量。
Tornado/Event servers are similar to java nio based servers. Tornado / Event服务器类似于基于java nio的服务器。 There is one conceptual difference between a Tornado and Eventlet.
Tornado和Eventlet之间存在一个概念上的区别。 Tornado follows a reactor pattern where the single process waits for IO(socket) events and dispatches them to appropriate handlers.
Tornado遵循反应器模式,其中单个进程等待IO(套接字)事件并将它们分派给适当的处理程序。 If handlers are nonblocking, best performance can be expected.
如果处理程序是非阻塞的,则可以获得最佳性能。 Typically code written for these frameworks consists of a series of callbacks making it a bit less readable than a synchronous server .Java NIO servers comes under this category.
通常,为这些框架编写的代码包含一系列回调,使其比同步服务器的可读性低一些.Java NIO服务器属于此类别。
Eventlet performs the same task but with a cleaner interface. Eventlet执行相同的任务,但界面更清晰。 Code can be written as in the case of synchronous server without using callbacks.
代码可以像同步服务器一样编写而不使用回调。 When an IO is encountered, eventlet schedules another userspace process(not right terminology).
遇到IO时,eventlet会调度另一个用户空间进程(不是正确的术语)。
Apache webapps are more popular that these because of few reasons 由于几个原因,Apache webapps更受欢迎
But for writing a chat application which handles lots of connections a multi-threaded server will not scale. 但是,对于编写处理大量连接的聊天应用程序,多线程服务器将无法扩展。 You have to use async frameworks like twisted/event/Java NIO.
您必须使用twisted / event / Java NIO等异步框架。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.