facebook/tornado — pull request #698 by rhettg (2013-03-15 23:35:52+00:00)
Title: Do a single accept() per callback

Starting with 57f5c57d89be095dc3cb5621364ccedc065f3d47 , accept()ing new connections is done in a loop, accepting everything that's available in a single call.

The problem with this is if you have multiple processes, all bound to the same socket, the first process that is available will accept all the connections.

To test this out, I did the following:

* Create a simple request handler that sleeps for 2 seconds.
* Start two processes:

http_server.bind(8080)
http_server.start(2)

* Then I used ab as follows:

ab -c 4 -n 4 http://localhost:8080

What you would expect, is for this to take exactly 4 seconds. With my patch, that's what you get. Without the patch, it takes between 6 and 8 depending on how lucky you get.