Strange lag / delay / delay / regardless of wsgiref.simple_server after a couple of requests

I have an unpleasant problem. I have this simple server code (say):

#!/usr/bin/env python3
import wsgiref.simple_server

def my_func(env, start_response):
  start_response('200 OK', [])
  return [''.encode()]

server = wsgiref.simple_server.make_server(
  '0.0.0.0',
  19891,
  my_func,
)

server.serve_forever()

However, 1 time out of 5 attempts (approximately 20% of requests) are submitted very, very slowly. When I interrupt server processing when this huge delay is in place, I always get the following exception:

Exception happened during processing of request from ('192.168.1.100', 3540)
Traceback (most recent call last):
  File "/usr/lib/python3.5/socketserver.py", line 313, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python3.5/socketserver.py", line 341, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python3.5/socketserver.py", line 354, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.5/socketserver.py", line 681, in __init__
    self.handle()
  File "/usr/lib/python3.5/wsgiref/simple_server.py", line 119, in handle
    self.raw_requestline = self.rfile.readline(65537)
  File "/usr/lib/python3.5/socket.py", line 575, in readinto
    return self._sock.recv_into(b)
KeyboardInterrupt

Do you have an idea how to avoid this unpleasant thing? Or what could be causing this behavior?

Update1: I tried TCP_NODELAY with changing the function simple_server.py -> WSGIServer-> server_bind, as shown below:

def server_bind(self):
    """Override server_bind to store the server name."""
    import socket
    self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY,1)
    HTTPServer.server_bind(self)
    self.setup_environ()

Unfortunately, no changes :(

+6
source share
1 answer

3540, "TCP/UDP Port Finder". / .

80, 8000, 8080... -.

0

All Articles