Search code examples
pythoncherrypy

Start CherryPy with different request_queue_size and timeout


I have a CherryPy application that I start with:

cherrypy.tree.mount(None, "/", config=conf) 
cherrypy.quickstart(None, config=conf)

I recently introduced a page to the application that takes a considerable time to load (10 to 15 seconds in some cases) and started seeing random failures on the production server under moderate load. I suspect this may be due to too many requests getting queued when several users request these long-running pages.

I'd like to experiment with allowing more requests to queue up. I discovered that the built-in server has a request_queue_size setting that may control what I want. However, I can't figure out how to change this setting using cherrypy.quickstart.


Solution

  • You can set it in your conf dictionary:

    conf = {'server.socket_queue_size': 10, ...}
    

    Or you can programmatically change it:

    cherrypy.server.socket_queue_size = 10
    

    Using the dictionary is the better approach.

    In CherryPy 3, you use configuration (files or dicts) to set attributes directly on the engine, server, request, response, and log objects. So the best way to know the full range of what’s available in the config file is to simply import those objects and see what help(obj) tells you.

    From CherryPy v3.2.0 documentation » Tutorial and Concepts » Configuration