views:

726

answers:

2

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

+1  A: 

First google search revealed http://bret.appspot.com/entry/tornado-web-server

Rohin
+4  A: 

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.

Tristan
Thanks, I was wondering what was so remarkable about an event-loop select()/epoll() architecture (something I read about yeaaaars ago in a TCP book), and why it might be better than threads.

related questions