Python 3.x 使用nginx+;时打开的文件过多;tornado处理5000个websocket连接
我正在测试我的tornado网关服务器,它在没有nginx的情况下可以很好地处理5000个连接。然后我添加nginx并运行2台服务器来处理5000个连接。不幸的是,出现了太多打开的文件 我已经在Python 3.x 使用nginx+;时打开的文件过多;tornado处理5000个websocket连接,python-3.x,nginx,tornado,Python 3.x,Nginx,Tornado,我正在测试我的tornado网关服务器,它在没有nginx的情况下可以很好地处理5000个连接。然后我添加nginx并运行2台服务器来处理5000个连接。不幸的是,出现了太多打开的文件 我已经在/etc/sysctl.conf中修改了kern.maxfiles和kern.maxfilesperproc,这就是为什么我的服务器在没有nginx的情况下可以很好地处理5000个连接 kern.maxfiles=104000 kern.maxfilesperproc=100000 在[Errno 24
/etc/sysctl.conf
中修改了kern.maxfiles和kern.maxfilesperproc,这就是为什么我的服务器在没有nginx的情况下可以很好地处理5000个连接
kern.maxfiles=104000
kern.maxfilesperproc=100000
在[Errno 24]发生后,我已经将worker\u rlimit\u nofile
修改为10000多个,并重新启动了nginx,但错误仍然发生,我现在很困惑
这是我在nginx.conf
中对nginx的配置
worker_processes 5;
worker_rlimit_nofile 10240;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 2048;
use kqueue;
}
http {
#charset utf-8;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
# Enumerate all the Tornado servers here
upstream websocket {
server 127.0.0.1:60000;
server 127.0.0.1:60001;
}
include mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
keepalive_timeout 65;
proxy_read_timeout 200;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
gzip on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain text/css text/xml
application/x-javascript application/xml
application/atom+xml text/javascript;
# Only retry if there was a communication error, not a timeout
# on the Tornado server (to avoid propagating "queries of death"
# to all frontends)
proxy_next_upstream error;
server {
listen 60017;
location ^~ /static/ {
root /path/to/app;
if ($query_string) {
expires max;
}
}
location / {
proxy_pass http://websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
}
我希望这些连接会被发送到我的tornado服务器,并且运行良好。但是错误发生在大约1000个连接上
我不知道如何修复它,如果能得到一些帮助,我将不胜感激。非常感谢 检查通过ulimit打开的文件限制(
ulimit-n
仅在当前会话中工作):
例如,仅为root用户将打开文件限制设置为5000,但在此修复后需要重新启动(不要忘记将root用户替换为您的web用户):
-n:file descriptor 65536
这是我从ulimit-a
中得到的。。。我不认为这是解决问题的方法。。。
root# ulimit -a | grep "open files"
open files (-n) 1024
root# ulimit -n 5000
root# ulimit -a | grep "open files"
open files (-n) 5000
echo -e "root\t\t-\tnofile\t\t 5000" >> /etc/security/limits.conf