Ticket #392 (new defect)
keep-alive slowdown caused by Nagle's Algorithm
| Reported by: | dalke | Owned by: | ianb |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.4.1 |
| Component: | paste | Version: | svn-trunk |
| Severity: | normal | Keywords: | |
| Cc: |
Description
When I use this test program
from paste import httpserver def echo_app(environ, start_response):
n = 10000 start_response("200 Ok", [("Content-Type", "text/plain"),
("Content-Length", str(n))])
return ["*" * n]
httpserver.serve(echo_app, protocol_version="HTTP/1.1")
I get about 1,300 request per second with
httperf --server localhost --port 8080 --num-conn 100
but only about 11 request per second with
httperf --server localhost --port 8080 --num-calls 100
There should be no reason for keep-alive to have such a bad performance.
I tracked it down to the outgoing/response in the server. The server wrote the text to the socket but the OS in the TCP layer buffered the text for up to 0.2s hoping to combine multiple packets into one. But the client is just waiting, so eventually the timeout kicks in. But 5 timeouts for out of 11 (on average) gives a performance of about 11 responses per second.
I've attached a fix, which does
self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)

