[Tutor] Issue with wsgi_ref.simple_server - sometimes very slow!

Attila Szabó szattila88 at gmail.com
Fri Jun 2 02:20:03 EDT 2017


Hi All,

I'm facing a really strange behavior with python's wsgi_ref.simple_server
module.

I have the following setup:
- Raspberry Pi 2
- Ubuntu Mate 16.04
- Python3.5
-

I have the following simple source:
#!/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()
After several requests (around every ~5 requests) the response time is
getting really-really slow (1-60sec) compared to the average 0.1s response,
the server serves the request and then quick again for couple of new
requests and then again....getting to be slow...

I'm trying to reach the node via my router, and also from outside internet
and the latency is there.

I have tried the same code also on Windows10 with same python version, from
behind the same router and the issue was not present.
Also I have removed the router and connected internet directly to Raspberry
PI and I faced the same issue.
So I think I can say that that is not because of the router for sure.

Also, always when I interrupt the running server I'm getting 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
That's why I think there is some issue with that recv_into function, but I
cannot figure it out how to resolve this... :/


Does anybody faced this same issue? Or anybody has an idea what should I
try or what should I modify in python source to solve this issue?

Thanks,
Attila


More information about the Tutor mailing list