我已经设置了gunicorn与3个工人,30个工人连接和使用eventlet工人类。它被设置在Nginx后面。每请求几次,我就会在日志里看到这个。
[ERROR] gunicorn.error: WORKER TIMEOUT (pid:23475)
None
[INFO] gunicorn.error: Booting worker with pid: 23514
为什么会这样?我怎样才能知道哪里出了问题呢?
我已经设置了gunicorn与3个工人,30个工人连接和使用eventlet工人类。它被设置在Nginx后面。每请求几次,我就会在日志里看到这个。
[ERROR] gunicorn.error: WORKER TIMEOUT (pid:23475)
None
[INFO] gunicorn.error: Booting worker with pid: 23514
为什么会这样?我怎样才能知道哪里出了问题呢?
当前回答
对我来说,这是因为我忘记在数据库服务器上为我的Django设置防火墙规则。
其他回答
这个端点是否花费了太多时间?
也许你使用的flask没有异步支持,所以每个请求都会阻塞调用。要创建异步支持而不让make变得困难,可以添加gevent worker。
使用gevent,一个新的调用将产生一个新的线程,你的应用程序将能够接收更多的请求
pip install gevent
gunicon .... --worker-class gevent
如果你已经更改了django项目的名称,你也应该去
cd /etc/systemd/system/
then
sudo nano gunicorn.service
然后验证在绑定行的末尾,应用程序名称已更改为新的应用程序名称
WORKER TIMEOUT表示应用程序不能在规定的时间内响应请求。你可以使用gunicorn超时设置来设置。一些应用程序需要比另一个应用程序更多的时间来响应。
另一个可能影响这一点的因素是员工类型的选择
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.
当我遇到与您相同的问题时(我试图使用Docker Swarm部署我的应用程序),我尝试增加超时并使用另一种类型的工人类。但都失败了。
然后我突然意识到我的资源限制太低在我的撰写文件中的服务。在我的例子中,这就是减慢应用程序的原因
deploy:
replicas: 5
resources:
limits:
cpus: "0.1"
memory: 50M
restart_policy:
condition: on-failure
所以我建议你先检查一下是什么减慢了你的应用程序
使用——log-level debug运行Gunicorn。
它应该会给你一个应用程序堆栈跟踪。
对我来说,这是因为我忘记在数据库服务器上为我的Django设置防火墙规则。