简体   繁体   中英

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. 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.

  • My first question is that is this tornado/eventlet similar to nio library in java and is a java nio server non-blocking and fast.
  • My second question is that since this event based Server are single thread If one connection blocks on file io or solw client will it hang the entire server
  • My third question is that what is the trade off , if non blocking server is fast why isn't it is more common than apache

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. 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. Not all of the libraries available are asynchronous which makes it difficult to use tornado/eventlet for all usecases. 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. There is one conceptual difference between a Tornado and Eventlet. Tornado follows a reactor pattern where the single process waits for IO(socket) events and dispatches them to appropriate handlers. 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.

Eventlet performs the same task but with a cleaner interface. 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).

Apache webapps are more popular that these because of few reasons

  • It is relatively easy to write synchronous code
  • Not all required libraries are asynchronous.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM