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