我的任务是创建一个Django-Gunicorn演示应用程序。在这个任务中,我需要能够在1秒内处理500个并发登录请求。
我必须将应用程序部署在一个具有2 2GB内存和2个核心CPU的虚拟机中(使用Vagrant和VirtualBox,Ubuntu16.04)。我已经尝试了以下部署。
gunicorn --workers 5 --bind "0.0.0.0:8000" --worker-class "gevent" --keep-alive 5 project.wsgi
在主机上使用JMeter测试,测试总是需要大约7-10秒。即使登录端点在没有任何数据库访问的情况下仅返回空响应,所用时间也几乎相同。你能告诉我这是怎么回事吗?
我使用/etc/nginx/nginx.conf的默认设置。
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
multi_accept on;
}
http {
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_disable "msie6";
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}这是我放在sites-available文件夹中的反向代理设置。
server {
listen 80;
location /static {
autoindex on;
alias /vagrant/static/;
}
location /media {
autoindex on;
alias /vagrant/uploads/;
}
location / {
proxy_redirect http://127.0.0.1:8000/ http://127.0.0.1:8080/;
proxy_pass http://127.0.0.1:8000;
}
}谢谢
发布于 2021-10-27 10:47:21
简短的答案是,你错过了worker connections在gunicorn。所以它不能处理更多的并发请求。
对于500个并发登录请求,数据库处理的并发活动连接也很重要。如果数据库不能处理加载,你也会失败。如果使用的是PSQL,则必须更改最大连接数并使用连接池
https://stackoverflow.com/questions/52242626
复制相似问题