Skip to content Skip to sidebar Skip to footer

Bottle With Cherrypy Does Not Behave Multi-threaded When Same End-point Is Called

As far as I know Bottle when used with CherryPy server should behave multi-threaded. I have a simple test program: from bottle import Bottle, run import time app = Bottle() @app.

Solution 1:

I already met this behaviour answering one question and it had gotten me confused. If you would have searched around for related questions the list would go on and on.

The suspect was some incorrect server-side handling of Keep-Alive, HTTP pipelining, cache policy or the like. But in fact it has nothing to do with server-side at all. The concurrent requests coming to the same URL are serialised because of a browser cache implementation (Firefox, Chromium). The best answer I've found before searching bugtrackers directly, says:

Necko's cache can only handle one writer per cache entry. So if you make multiple requests for the same URL, the first one will open the cache entry for writing and the later ones will block on the cache entry open until the first one finishes.

Indeed, if you disable cache in Firebug or DevTools, the effect doesn't persist.

Thus, if your clients are not browsers, API for example, just ignore the issue. Otherwise, if you really need to do concurrent requests from one browser to the same URL (normal requests or XHRs) add random query string parameter to make request URLs unique, e.g. http://example.com/concurrent/page?nocache=1433247395.

Solution 2:

It's almost certainly your browser that's serializing the request. Try using two different ones, or better yet a real client. It doesn't reproduce for me using curl.

Post a Comment for "Bottle With Cherrypy Does Not Behave Multi-threaded When Same End-point Is Called"