Gunicorn worker timeout error

后端 未结 15 1927
梦谈多话
梦谈多话 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:36

    Frank's answer pointed me in the right direction. I have a Digital Ocean droplet accessing a managed Digital Ocean Postgresql database. All I needed to do was add my droplet to the database's "Trusted Sources".

    (click on database in DO console, then click on settings. Edit Trusted Sources and select droplet name (click in editable area and it will be suggested to you)).

    0 讨论(0)
  • 2020-11-29 16:37

    For me, it was because I forgot to setup firewall rule on database server for my Django.

    0 讨论(0)
  • 2020-11-29 16:39

    I had very similar problem, I also tried using "runserver" to see if I could find anything but all I had was a message Killed

    So I thought it could be resource problem, and I went ahead to give more RAM to the instance, and it worked.

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-11-29 16:42

    Could it be this? http://docs.gunicorn.org/en/latest/settings.html#timeout

    Other possibilities could be your response is taking too long or is stuck waiting.

    0 讨论(0)
  • 2020-11-29 16:45

    This worked for me:

    gunicorn app:app -b :8080 --timeout 120 --workers=3 --threads=3 --worker-connections=1000
    

    If you have eventlet add:

    --worker-class=eventlet
    

    If you have gevent add:

    --worker-class=gevent
    
    0 讨论(0)
提交回复
热议问题