Nginx服务器10000 并发 优化测试(ab测试工具)

1)编译nginx,加上参数 --with-http_stub_status_module  

#/usr/local/nginx/sbin/nginx -V ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module #配置指令 ./configure --prefix=/usr/local --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --http-client-body-temp-path=/usr/local/var/tmp/nginx/client --http-proxy-temp-path=/usr/local/var/tmp/nginx/proxy --http-fastcgi-temp-path=/usr/local/var/tmp/nginx/fcgi --http-scgi-temp-path=/usr/local/var/tmp/nginx/scgi --http-uwsgi-temp-path=/usr/local/var/tmp/nginx/uwsgi --with-http_geoip_module --with-http_stub_status_module

2)修改nginx配置文件,添加监控状态配置

在nginx.conf的server块中添加如下代码

location /nginx_status { # Turn on nginx stats stub_status on; # I do not need logs for stats access_log off; # Security: Only allow access from 192.168.1.100 IP # #allow 192.168.1.100; # Send rest of the world to /dev/null # #deny all; }

Nginx服务器10000 并发 优化测试(ab测试工具)


解释:
Active connections:对后端发起的活动连接数。
Server accepts handled requests:Nginx总共处理了655个连接,成功创建655次握手(证明中间没有失败的),总共处理了1985个请求。
Reading:Nginx 读取到客户端的Header信息数。
Writing:Nginx 返回给客户端的Header信息数。
Waiting:开启keep-alive的情况下,这个值等于 active – (reading + writing),意思就是Nginx已经处理完成,正在等候下一次请求指令的驻留连接。
/usr/local/nginx/sbin/nginx -t //测试配置是否正确 /usr/local/nginx/sbin/nginx -s reload

2.设置最大连接数(50000)/加快tcp连接数的回收/让空的tcp允许回收利用/关闭洪水攻击抵御

echo 50000 > /proc/sys/net/core/somaxconn

echo 1 > /proc/sys/net/ipv4/tcp_tw/recycle echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse echo 0 > /proc/sys/net/ipv4/tcp_syncookies

3.设置打开更多文件数 ulimit -n 50000

vim /etc/nginx/nginx.conf worker_rlimit_nofile 10000; //nginx允许打开最大文件数10000-->写在全局 不是在events events{

worker_connections 10240; }

/usr/sbin/nginx -t /usr/sbin/nginx -s reload

4.ab -c 5000 -n 100000 //压力测试 测试结果:

Server Software: nginx/1.4.6
Server Hostname: 192.168.63.129
Server Port: 80

Document Path: /index.html
Document Length: 65 bytes

Concurrency Level: 5000
Time taken for tests: 46.416 seconds
Complete requests: 100000
Failed requests: 90202
(Connect: 0, Receive: 0, Length: 90202, Exceptions: 0)
Write errors: 0
Non-2xx responses: 90282
Total transferred: 36624606 bytes
HTML transferred: 18815922 bytes
Requests per second: 2154.42 [#/sec] (mean)
Time per request: 2320.813 [ms] (mean)
Time per request: 0.464 [ms] (mean, across all concurrent requests)
Transfer rate: 770.55 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 18 1251 2273.8 824 31950
Processing: 298 839 299.1 855 6307
Waiting: 1 648 298.8 651 6194
Total: 408 2090 2323.2 1697 36083

Percentage of the requests served within a certain time (ms)
50% 1697
66% 1758
75% 1802
80% 1843
90% 2583
95% 4601
98% 8399
99% 8807
100% 36083 (longest request)

5000并发100000连接数 失败请求90202  幸好这个是测试服务器

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/6f37749768a0deae5e3dbf30fa0fd3ac.html