Slow Python HTTP server on localhost

前端 未结 2 765
[愿得一人]
[愿得一人] 2020-12-25 14:57

I am experiencing some performance problems when creating a very simple Python HTTP server. The key issue is that performance is varying depending on which client I use to a

相关标签:
2条回答
  • 2020-12-25 15:10

    The request handler issues a inverse name lookup in order to display the client name in the log. My Windows 7 issues a first DNS lookup that fails with no delay, followed by 2 successive NetBIOS name queries to the HTTP client, and each one run into a 2 sec timeout = 4 seconds delay !!

    Have a look at https://bugs.python.org/issue6085

    Another fix that worked for me is to override BaseHTTPRequestHandler.address_string() in my request handler with a version that does not perform the name lookup

    def address_string(self):
        host, port = self.client_address[:2]
        #return socket.getfqdn(host)
        return host
    

    Philippe

    0 讨论(0)
  • 2020-12-25 15:30

    This does not sound like a problem with the code. A nifty way of troubleshooting an HTTP server is to connect to it to telnet to it on port 80. Then you can type something like:

    GET /index.html HTTP/1.1
    host: www.blah.com
    <enter> <enter>
    

    and observe the server's response. See if you get a delay using this approach.

    You may also want to turn off any firewalls to see if they are responsible for the slowdown.

    Try replacing 127.0.0.1 for localhost. If that solves the problem, then that is a clue that the FQDN lookup may indeed be the possible cause.

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