Gunicorn worker timeout error

后端 未结 15 2043
梦谈多话
梦谈多话 2020-11-29 16:07

I have setup gunicorn with 3 workers 30 worker connections and using eventlet worker class. It is setup behind Nginx. After every few requests, I see this in the logs.

15条回答
  •  生来不讨喜
    2020-11-29 16:40

    WORKER TIMEOUT means your application cannot response to the request in a defined amount of time. You can set this using gunicorn timeout settings. Some application need more time to response than another.

    Another thing that may affect this is choosing the worker type

    The default synchronous workers assume that your application is resource-bound in terms of CPU and network bandwidth. Generally this means that your application shouldn’t do anything that takes an undefined amount of time. An example of something that takes an undefined amount of time is a request to the internet. At some point the external network will fail in such a way that clients will pile up on your servers. So, in this sense, any web application which makes outgoing requests to APIs will benefit from an asynchronous worker.

    When I got the same problem as yours (I was trying to deploy my application using Docker Swarm), I've tried to increase the timeout and using another type of worker class. But all failed.

    And then I suddenly realised I was limitting my resource too low for the service inside my compose file. This is the thing slowed down the application in my case

    deploy:
      replicas: 5
      resources:
        limits:
          cpus: "0.1"
          memory: 50M
      restart_policy:
        condition: on-failure
    

    So I suggest you to check what thing slowing down your application in the first place

提交回复
热议问题