我有一個在 Gunicorn 和 Nginx 上運行的 django 應用程式。應用程式中有一個請求需要 10 分鐘來加載頁面 [有很多資料要處理],我已將 Gunicorn 的作業時間增加到 1200 秒,以使其需要足夠的時間來加載頁面。它作業正常,但在該請求得到處理之前,其他用戶無法訪問該應用程式:
504 網關超時 nginx/1.21.4
這是我的碼頭工人
version: '3.8'
services:
web:
volumes:
- static:/static
command: python manage.py makemigrations /
&& python manage.py migrate && python manage.py collectstatic --noinput/
&& python manage.py crontab add /
&& exec gunicorn DrDNAC.wsgi:application --bind 0.0.0.0:8000 --timeout 1200"
build:
context: .
ports:
- "8000:8000"
depends_on:
- db
db:
image: postgres:13.0-alpine
nginx:
build: ./nginx
volumes:
- static:/static
ports:
- "80:80"
depends_on:
- web
volumes:
postgres_data:
static:
這是 nginx:
upstream app {
server web:8000;
}
server {
listen 80;
location / {
proxy_pass https://app;
proxy_connect_timeout 75s;
proxy_read_timeout 300s;
}
location /static/ {
alias /static/;
}
}
uj5u.com熱心網友回復:
這可能是因為工人數量不夠。
嘗試通過添加--workers=4到 gunicorn 呼叫來增加數量。
gunicorn DrDNAC.wsgi:application --workers=4 --bind 0.0.0.0:8000 --timeout 1200
您可以在以下鏈接下找到更多資訊:https : //docs.gunicorn.org/en/stable/settings.html#worker-processes
此外,您還可以通過使用增加執行緒數 --threads 4
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/392555.html
