我尝试增加我的服务器可以处理的并发连接数。
$uname -a Linux debian 3.16.0-4-amd64 #1 SMP Debian 3.16.36-1+deb8u2 (2016-10-19) x86_64 GNU/Linux $ulimit -Sn 65536 $ulimit -Hn 65536
Nginx的configuration有以下几行:
worker_processes 4; # or 8 worker_rlimit_nofile 60000; events { worker_connections 1024; }
还有一个困(无限睡觉)通过上游使用的python asyncio HTTP后端。
经过几秒钟的负载testing:
2016/11/03 05:13:44 [alert] 15#15: 1024 worker_connections are not enough 2016/11/03 05:13:44 [alert] 15#15: 1024 worker_connections are not enough
而
$netstat -anvpt | wc -l 1156 # or twice bigger if there is 8 worker processes.
htop显示有4个(或8个)nginx工作进程,只有1个CPU核心的50%被使用(而另外3个核心空闲)。 对netstat输出的更详细的调查显示,只有2个工作进程被使用,并且它们都不超过1024个允许的连接的一半(从客户端到nginx,从nginx到上游)。
另外,nginx和后端在docker容器里面工作。
UPD:如果我将worker_connections提高到10240,我将处理更多的客户端,CPU性能将成为瓶颈。 但问题是为什么我面临着1024 worker_connections are not enough而仍然有2或6个闲置的工人。