nginx+uwsgi高并发配置
配置
系统层面
-
修改TCP最大连接数
echo 10000 > /proc/sys/net/core/somaxconn
-
TCP连接立即回收、回用
echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
nginx配置
worker_rlimit_nofile 65535; #一个nginx 进程打开的最多文件描述符数目
events {
worker_connections 20000;#每个进程允许的最多连接数
}
location / {
uwsgi_send_timeout 600; # 指定向uWSGI传送请求的超时时间,完成握手后向uWSGI传送请求的超时时间。
uwsgi_connect_timeout 600; # 指定连接到后端uWSGI的超时时间。
uwsgi_read_timeout 600; # 指定接收uWSGI应答的超时时间,完成握手后接收uWSGI应答的超时时间。
}
uwsgi配置
workers/processes = 24 # 并发处理进程数
listen = 1000 # 并发的socket 连接数。默认为100。优化需要根据系统配置
timeout = 60*60
backlog = 10000
问题对应配置
(nginx error_log)
-
worker_rlimit_nofile 没改:
socket() failed (24: Too many open files) while connecting to upstream
-
worker_connections 没改:
worker_connections are not enough while connecting to upstream
-
uwsgi listen没改
connect() to unix:///root/TsingE-Backend/TsingeManager/uwsgi.sock failed (11: Resource temporarily unavailable) while connecting to upstream
-
超时时间没改
upstream timed out (110: Connection timed out) while reading response header from upstream