tcp调优:
net.core.somaxconn = 2048
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 4096 16777216
net.ipv4.tcp_wmem = 4096 4096 16777216
//这两个参数可以减少为1024,减少内存的开销,但速度会下降
net.ipv4.tcp_mem = 786432 2097152 3145728
//这个值很重要,可以在运行时通过 cat /proc/net/sockstat查看,最大值需要有内存的支持,
//如果内存支持不了3145728,一样会失败,产生oom错误。
//内核只使用物理内存,不使用swap,oom产生后,swap的内存仍然很大
net.core.netdev_max_backlog = 20000
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_max_syn_backlog = 16384
//这个值设置的太大没有用,因为nginx里面定义了#define NGX_LISTEN_BACKLOG 511
//需修改代码,重新编译。
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_max_orphans = 131072
Nginx 设置:
pid logs/nginx.pid; error_log logs/error.log info;
# Development Mode #master_process off; #daemon off; #worker_rlimit_core 500M; #working_directory /tmp/nginx;
worker_processes 8; worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000; worker_priority -1;
events { worker_connections 1000000; use epoll; }
tcp_nopush off; tcp_nodelay on; keepalive_timeout 1800000; #send_timeout 10; client_body_timeout 18000000; client_header_timeout 18000000; sendfile on; client_header_buffer_size 40k; large_client_header_buffers 40 80k; client_max_body_size 40k; client_body_buffer_size 40k; ignore_invalid_headers on;
push_stream_shared_memory_size 2000m;
......
消息大小:512bytes推送模块使用的内存较多,使用命令:ulimit -m unlimitedulimit -v unlimited去掉对用户的内存限制。2、测试环境通过LVS转发,server的内存为16G,4个client内存为4G,CPU为8核3、测试结果
连接数 | 连接创建时间(millisecond) | 推送时间(millisecond) | 推送速度 (条/毫秒) | CPU活跃数 | 消息到达率 |
1万 | 1902 | 585 | 17 | 1 | 100% |
5万 | 9513 | 2884 | 17 | 1 | 100% |
10万 | 10007/ 13343 | 3204 | 31 | 2 | 100% |
15万 | 10317/14587 /9906 | 14194 | 10 | 4 | 100% |
20万 | 11020/ 31242 / 53399/ 68179 | 4909 | 40 | 4 | 100% |
channel数 | 连接数 | CPU活跃数 | 推送时间(millisecond) | 推送速度 (条/毫秒) | 消息到达率 |
100 | 10000 | 1 | 705 | 14 | 100% |
1000 | 10000 | 1 | 1142 | 8 | 100% |
10000 | 10000 | 1 | 124845 | 0.08 | 100% |
连接数 | 消息数/管道数 | 消息数 | 推送时间(millisecond) | 推送速度 (条/毫秒) | CPU活跃数 | 消息到达率 |
1万 | 100/100 | 100万 | 44699 | 22 | 1 | 100% |
5万 | 100/100 | 500万 | 222304 | 22 | 1 | 100% |
10万 | 100/100 | 1000万 | 208355 | 48 | 4 | 100% |
20万 | 100/100 | 2000万 | 675115 | 30 | 4 | 100% |
连接数 | 消息数/管道数 | 消息数 | 推送时间(millisecond) | 推送速度 (条/毫秒) | CPU活跃数 | 消息到达率 |
1万 | 100/100 | 100万 | 45479 | 21 | 1 | 100% |
5万 | 100/100 | 500万 | 225211 | 22 | 1 | 100% |
10万 | 100/100 | 1000万 | 287552 | 34 | 2 | 100% |
20万 | 100/100 | 2000万 | 565293 | 41 | 5 | 100% |