nginx看最大并发量-凯发k8官方网
测试机器为腾讯云服务器1核1g内存,swap分区2g,停用除ssh外的所有服务,仅保留nginx,优化思路主要包括两个层面:系统层面 nginx层面。
一、系统层面
1、调整同时打开文件数量
ulimit -n 20480
2、tcp最大连接数(somaxconn)
echo 10000 > /proc/sys/net/core/somaxconn
3、tcp连接立即回收、回用(recycle、reuse)
echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse
echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
4、不做tcp洪水抵御
echo 0 > /proc/sys/net/ipv4/tcp_syncookies
也可以直接使用优化后的配置,在/etc/sysctl.conf中加入:
net.core.somaxconn = 20480
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
net.ipv4.tcp_mem = 786432 2097152 3145728
net.ipv4.tcp_max_syn_backlog = 16384
net.core.netdev_max_backlog = 20000
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_max_orphans = 131072
net.ipv4.tcp_syncookies = 0
使用:sysctl -p 生效
sysctl -p
二、nginx层面
修改nginx配置文件,nginx.conf
增加work_rlimit_nofile和worker_connections数量,并禁用keepalive_timeout。
worker_processes 1;
worker_rlimit_nofile 20000;
events {
use epoll;
worker_connections 20000;
multi_accept on;
}
http {
keepalive_timeout 0;
}
重启nginx
/usr/local/nginx/sbin/nginx -s reload
使用ab压力测试
ab -c 10000 -n 150000 http://127.0.0.1/index.html
测试结果:
this is apachebench, version 2.3
凯发k8官方网 copyright 1996 adam twiss, zeus technology ltd, http://www.zeustech.net/
licensed to the apache software foundation, http://www.apache.org/
benchmarking 127.0.0.1 (be patient)
completed 15000 requests
completed 30000 requests
completed 45000 requests
completed 60000 requests
completed 75000 requests
completed 90000 requests
completed 105000 requests
completed 120000 requests
completed 135000 requests
completed 150000 requests
finished 150000 requests
server software: nginx/1.8.0
server hostname: 127.0.0.1
server port: 80
document path: /index.html
document length: 612 bytes
concurrency level: 10000
time taken for tests: 19.185 seconds
complete requests: 150000
failed requests: 0
write errors: 0
total transferred: 131180388 bytes
html transferred: 95121324 bytes
requests per second: 7818.53 [#/sec] (mean)
time per request: 1279.013 [ms] (mean)
time per request: 0.128 [ms] (mean, across all concurrent requests)
transfer rate: 6677.33 [kbytes/sec] received
connection times (ms)
min mean[ /-sd] median max
connect: 0 650 547.9 522 7427
processing: 212 519 157.4 496 958
waiting: 0 404 139.7 380 845
total: 259 1168 572.1 1066 7961
percentage of the requests served within a certain time (ms)
50% 1066
66% 1236
75% 1295
80% 1320
90% 1855
95% 2079
98% 2264
99% 2318
100% 7961 (longest request)
总结
以上是凯发k8官方网为你收集整理的nginx看最大并发量_nginx高并发配置思路(轻松应对1万并发量)的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇:
- 下一篇: