
저는 API 엔드포인트 역할을 하는 Django-App을 호스팅하고 있습니다. 불행하게도 API를 사용하는 앱은 페이지 로드 시 많은 동시 요청을 수행합니다(80-90개 요청 영역).
Nginx는 gunicorn 앞에서 역방향 프록시로 실행 중이며 다음 문제를 보고합니다.
kevent() reported that connect() failed (54: Connection reset by peer) while connecting to upstream
그로 인해 나는 gunicorn을 확장하게 되었습니다. -k gevent
늘려보려고 노력했지만 --worker-connections
별로 도움이 되지 않았습니다. 나는 --threads
sync-workers 와 거의 동일한 성공을 거두었습니다 .
Listen queue overflow: 16 already in queue awaiting acceptance (55 occurrences)
나는 에서 몇 가지 발생을 발견했고 이로 인해 최대 4096까지 dmesg
증가했지만 다시 성공하지 못했습니다.kern.ipc.somaxconn
gunicorn-documentation에 따라 hey
프록시가 올바른 작업을 수행하고 엔드포인트를 로드 테스트하는지 확인하는 데 사용합니다.
hey -c 100 -n 200 -H "Authorization: token ${token}" 'https://example.com/api/'
해당 라인에 따라 무언가를 반환합니다(때로는 조금 더 좋고 때로는 조금 더 나쁩니다).
Status code distribution:
[200] 126 responses
[502] 74 responses
관련 nginx-config:
worker_processes auto;
events {
worker_connections 1024;
accept_mutex on;
use kqueue;
}
upstream backend-api {
server 127.0.0.1:8000 fail_timeout=0;
}
server {
listen 443 ssl http2 accept_filter=httpready;
server_name example.com;
ssl_certificate /usr/local/etc/nginx/sites/example.com.crt;
ssl_certificate_key /usr/local/etc/nginx/sites/example.com.key;
location = /favicon.ico { access_log off; log_not_found off; }
root /usr/local/www/example.com/web;
index index.html ;
keepalive_timeout 5;
location ~ ^/(static|assets|index.html|$) {
root /usr/local/www/example.com/web;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_intercept_errors on;
proxy_pass http://backend-api;
}
}
다음을 사용하여 gunicorn을 실행합니다.
gunicorn --workers=9 --bind 0.0.0.0:8000 --forwarded-allow-ips='*' -k gevent --worker-connections=1000 api.wsgi'
이에 대한 해결책을 찾을 수 없는 것 같습니다. 내가 무엇을 시도하든 페이지 로드 시 "적은" 502만 얻을 수 있지만 안정적으로 아무것도 얻을 수는 없습니다. 내가 무엇을 놓치고 있나요?
Gunicorn은 어떤 문제도 보고하지 않습니다. 요청이 그렇게까지 진행되지는 않는 것 같습니다.