上一篇说到了部署nginx代理的情况,在实际使用中,如果因为资源问题,或者高频访问,可能会有各种问题,可能通过ab模块进行压测
Apache Bench (ab) 是一个常用的压测工具,可以模拟多个并发访问线程,对某一URL地址进行访问。以下是使用ab进行Nginx压测的步骤:
安装ab工具: yum -y install httpd-tools
ab -n 50000 -c 500 http://10.X.X.X:7777/screens/frameset.html
-c
: 表示并发数-n
: 表示请求总数
[root@test-new ~]# ab -n 50000 -c 500 http://10.X.X.X:7777/screens/frameset.html
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 10.x.x.x (be patient)
Completed 5000 requests
Completed 10000 requests
Completed 15000 requests
Completed 20000 requests
Completed 25000 requests
Completed 30000 requests
Completed 35000 requests
Completed 40000 requests
Completed 45000 requests
Completed 50000 requests
Finished 50000 requests
Server Software: nginx/1.9.9
Server Hostname: 10.x.x.x
Server Port: 7777
Document Path: /screens/frameset.html
Document Length: 200 bytes 页面大小
Concurrency Level: 500 并发数
Time taken for tests: 8.956 seconds 测试总共花费的时间
Complete requests: 50000 完成的请求数
Failed requests: 1139 失败的请求数
(Connect: 0, Receive: 0, Length: 1139, Exceptions: 0)
Write errors: 0 写入错误
Non-2xx responses: 50000
Total transferred: 17762413 bytes 总共传输字节数,包含http的头信息等
HTML transferred: 9968108 bytes html字节数,实际的页面传递字节数
Requests per second: 5583.09 [#/sec] (mean) 每秒处理的请求数,服务器的吞吐量(重要)
Time per request: 89.556 [ms] (mean) 平均数,用户平均请求等待时间
Time per request: 0.179 [ms] (mean, across all concurrent requests) 服务器平均处理时间
Transfer rate: 1936.90 [Kbytes/sec] received 平均传输速率(每秒收到的速率)
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 18 146.8 0 3008
Processing: 1 65 439.2 12 7024
Waiting: 1 65 439.1 12 7024
Total: 1 83 499.9 13 7025
Percentage of the requests served within a certain time (ms)
50% 13
66% 13
75% 14
80% 14
90% 18
95% 49
98% 1019
99% 3014
100% 7025 (longest request)
[root@test-new ~]#