paste.httpserver and slowdown with HTTP/1.1 Keep-alive; tested with httperf and ab

后端 未结 1 1198
长发绾君心
长发绾君心 2021-02-06 18:26

I have a web server based on paste.httpserver as an adapater between HTTP and WSGI. When I do performance measurements with httperf, I can do over 1,000 requests per second if I

1条回答
  •  旧巷少年郎
    2021-02-06 19:09

    After some effort, it seems to be either Nagle's algorithm or the delayed ACK, or the interactions between them. It goes away if I do something like

    server.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
    

    How did I track it down? First, I instrumented every 'recv' in socket.py, so I could figure out which recv was waiting. I would see about 5 recv's out of 11 had a delay of almost 200ms. I couldn't figure out why there was any delay. I then used Wireshark to watch the messages and noticed that the it was actually the send from the server to the client which had the delay. That meant something in the TCP layer in the outgoing messages from my client.

    A friend suggested the obvious, and I searched for "200ms socket delay" and found descriptions of this problem.

    The paste trac report is at http://trac.pythonpaste.org/pythonpaste/ticket/392 along with a patch which enables TCP_NODELAY when the handler uses HTTP/1.1.

    0 讨论(0)
提交回复
热议问题