
내 서버가 1500명의 사용자를 처리할 수 있는지 확인하기 위해 locust로 로드 테스트를 수행하고 있습니다.
내가 사용하는 것: Django, Nginx, Gunicorn, Postgresql 내 드롭릿: 24vCPU, 128GB RAM, 25GB SSD
약 1100명의 사용자가 있으면 메뚜기에서 다음과 같은 오류가 발생하기 시작합니다.
GET / HTTPError('502 Server Error: Bad Gateway for url: myurl.here ')
GET /aboutpage/ HTTPError('502 Server Error: Bad Gateway for url: myurl.here ')
내 nginx error.log에 다음 오류가 발생합니다.
2020/01/26 23:14:17 [error] 30465#30465: *167765 connect() to unix:/var/www/file/to/sock/gunicorn failed (11: Resource temporarily unavailable) while connecting to upstream, client: 8x.8x.1xx.3x, server: mysite.here, request: "GET // HTTP/1.1", upstream: "http://unix:/var/www/file/to/sock/gunicorn://", host: "mysite.here"
어떤 이유로 내 리소스를 일시적으로 사용할 수 없다는 메시지가 나타납니다.
내 nginx.conf는 다음과 같습니다.
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 2048;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
# Virtual Host Configs
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
내 서버 블록 구성은 다음과 같습니다.
upstream mysite-production {
server unix:/var/www/path/to/sock/gunicorn;
}
server {
listen [::]:80;
listen 80;
server_name mysite.here;
# set client body size to 100M #
client_max_body_size 100M;
location / {
include proxy_params;
proxy_pass http://unix:/var/www/path/to/sock/gunicorn;
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
}
location /static/ {
root /var/www/site/production/;
expires 30d;
add_header Vary Accept-Encoding;
access_log off;
gzip on;
gzip_comp_level 6;
gzip_vary on;
gzip_types text/plain text/css application/json application/x-javascript application/javascript text/xml application/xml application/rss+xml text/javascript image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype;
}
location /media/ {
root /var/www/site/production/;
expires 30d;
add_header Vary Accept-Encoding;
access_log off;
}
}
내 gunicorn 서비스 파일은 다음과 같습니다.
[Unit]
Description=mysite production daemon
After=network.target
[Service]
User=www-data
Group=www-data
WorkingDirectory=/var/www/path/to/site/src
ExecStart=/var/www/path/to/venv/bin/gunicorn --workers=49 --bind unix:/var/www/path/to/sock/gunicorn --log-level DEBUG --log-file '/var/www/path/to/log/gunicorn.log' mysite.wsgi:application
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
이 문제의 원인은 무엇입니까? 우리는 동시에 사이트에 있을 약 1500-2000명의 동시 사용자를 예측하고 있습니다.
시간을 내주셔서 감사합니다! 나는 당신의 답변을 기대하고 있습니다!
답변1
부하 테스트를 할 때는 항상 한계와 병목 현상에 부딪히게 됩니다.
귀하의 경우에는총니콘 구성backlog
기본값을 서버가 처리할 수 있는 값으로 변경 합니다 2048
.