Fork me on GitHub

gunicorn dango nginx 实现同时处理并发请求

项目是采用 gunicorn dango nginx 方式部署的。

gunicorn.py采用如下方式配置,

workers = 1
bind = '0.0.0.0:8000'
backlog = 2048
timeout = 6000
keepalive = 6000
errorlog = '../error.log'
loglevel = 'info'
logFile = '../sys.log'
accesslog = '../access.log'
worker_class = 'gthread'
worker_connections = 1000

/etc/systemd/system/cmdb.service

[root@localhost system]# cat cmdb.service 
[Unit]
Description=cmdb
After=network.target

[Service]
User=root
Group=root
Environment="APP_ENV=prd"
WorkingDirectory=/data/cmdb/
ExecStart=/usr/local/bin/gunicorn  cmdb.wsgi:application -c  /data/cmdb/gunicorn.py

[Install]
WantedBy=multi-user.target

之后启动systemctl start cmdb。程序没问题,有问题的地方是有一个耗时很长的同步任务,会导致页面,程序接口都卡着。就很好奇,gunicorn不就是异步的么,难道不能处理类似的并发请求

经过一番折腾,python - 如何让 Flask/Gunicorn 处理同一路由的并发请求?      gunicorn使用

 

解决办法:

加上threads就解决了

把gunicorn.py 改下,重启systemctl restart cmdb,完美解决。

workers = 1
bind = '0.0.0.0:8000'
backlog = 2048
timeout = 6000
keepalive = 6000
errorlog = '../error.log'
loglevel = 'info'
logFile = '../sys.log'
accesslog = '../access.log'
worker_class = 'gthread'
worker_connections = 1000
threads = 2

 

posted @ 2023-09-26 17:48  神雕爱大侠  阅读(38)  评论(0编辑  收藏  举报