Jaymon / endpoints

Lightweight REST api backend framework that automatically maps urls to python modules and classes
MIT License
29 stars 10 forks source link

socketserver.ForkingMixIn doesn't work with caching #88

Closed Jaymon closed 5 years ago

Jaymon commented 5 years ago

I switched the wsgi server from:

class WSGIHTTPServer(socketserver.ThreadingMixIn, WSGIServer):

to:

class WSGIHTTPServer(socketserver.ForkingMixIn, WSGIServer):

and I noticed the requests were not getting faster after the first request, and sure enough, I tracked it down to Router's cache not populating, I think this is because python fork's and then creates the cache and then the master process never inherits the cache back from the forked process, so it has to rebuild the cache on ever request.

Because of this I've gone back to ThreadingMixIn but I might want to figure out if there is an acceptable permanent solution that works across forking and threading.