Tornado is “a relatively simple, non-blocking web server framework written in Python”--can somewhat explain what that means?

StackOverflow https://stackoverflow.com/questions/1419624

  •  07-07-2019
  •  | 
  •  

Question

This is probably a stupid question, but what exactly is a "non-blocking web server"? All web servers are technically non-blocking, arent they? otherwise how could they handle simultaneous connections? Apache2 achieves this using a combination of fork() and pthreads. How exactly are Tornado (and Twisted also) different? Do they just set a bunch of sockets to non-bocking mode, build an FD list (or equivalent), and then loop over that with one big select() sys call?

Where would you use a framework like these, and what advantages can they give you over Apache2 (or other popular servers)? Thanks

Was it helpful?

Solution

This article on EventMachine may also give you a hint:

Steeped in the tradition of forking / threaded web-servers I found myself rather surprised when I joined one of the research projects at University of Waterloo a couple of years back: we were benchmarking different web-server architectures, and top performers were all event-driven servers.

As I pestered everyone with questions, I quickly realized why - in an environment with hundreds of thousands requests a second, forking and context switching associated with thread management become prohibitively expensive (fork is worst performer, as it does a memory copy on the parent process every time). Whereas by comparison, a tight and highly optimized event-loop really shines when it comes to performance under heavy loads.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top