nginx压力测试

安装ab命令            

[root@master ~]# yum -y install httpd-tools

硬件配置型号          

[root@master ~]# dmidecode | grep "Product Name"
        Product Name: VMware Virtual Platform
        Product Name: 440BX Desktop Reference Platform

CPU                  

[root@master ~]# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq
 Intel(R) Core(TM) i3-2348M CPU @ 2.30GHz

内存                  

[root@master ~]# dmidecode|grep -P -A5 "Memorys+Device" | grep Size |grep -v Range | cat -n
     1          Size: 512 MB

软件环境            

操作系统                  

[root@master ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core) 

服务版本                  

[root@master ~]# /usr/local/nginx/sbin/nginx -v
nginx version: liujunjun/1.0

测试软件                  

[root@master ~]# ab -V
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/

并发测试

说明:测试基于Linux系统。

1000并发

测试1000并发,处理10000请求:

[root@master ~]#  ab -c 1000 -n 10000 http://192.168.1.222/static/index.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 192.168.1.222 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        liujunjun/1.0      (服务器软件名称及版本信息)
Server Hostname:        192.168.1.222        (服务器主机名)
Server Port:            80           (服务器端口)

Document Path:          /static/index.html    (供测试的URL路径)
Document Length:        14 bytes         (供测试的URL返回的文档大小)

Concurrency Level:      1000          (并发数)
Time taken for tests:   1.476 seconds      (压力测试消耗的总时间)
Complete requests:      10000          (压力测试的的总次数)
Failed requests:        0            (失败的请求数)
Write errors:           0            
Total transferred:      2450000 bytes    (传输的总数据量)
HTML transferred:       140000 bytes      (HTML文档的总数据量)
Requests per second:    6776.24 [#/sec] (mean)  (平均每秒的请求数)
Time per request:       147.574 [ms] (mean)  (所有并发用户(这里是1000)都请求一次的平均时间)
Time per request:       0.148 [ms] (mean, across all concurrent requests)  (单个用户请求一次的平均时间)
Transfer rate:          1621.27 [Kbytes/sec] received      (传输速率,单位:KB/s)

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        1   76 253.6      4    1020
Processing:     2   20  28.9     13     418
Waiting:        1   16  28.2     10     418
Total:          8   96 266.0     16    1425

Percentage of the requests served within a certain time (ms)  这个表第一行表示有50%的请求都是在16ms内完成的,可以看到这个值是比较接近平均系统响应时间,以此类推。
  50%     16
  66%     16
  75%     17
  80%     19
  90%    106
  95%   1030
  98%   1037
  99%   1218
 100%   1425 (longest request)

2000并发                    

[root@master ~]# cat /proc/sys/fs/file-max
44685
[root@master ~]# ulimit -n
1024
临时修改
[root@master ~]# ulimit -HSn 2048
永久修改
[root@master ~]# ulimit -a 65535
[root@master ~]# ab -c 2000 -n 40000 http://192.168.1.222/static/index.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 192.168.1.222 (be patient)
Completed 4000 requests
Completed 8000 requests
Completed 12000 requests
Completed 16000 requests
Completed 20000 requests
Completed 24000 requests
Completed 28000 requests
Completed 32000 requests
Completed 36000 requests
Completed 40000 requests
Finished 40000 requests


Server Software:        liujunjun/1.0
Server Hostname:        192.168.1.222
Server Port:            80

Document Path:          /static/index.html
Document Length:        14 bytes

Concurrency Level:      2000
Time taken for tests:   5.719 seconds
Complete requests:      40000
Failed requests:        1
   (Connect: 0, Receive: 0, Length: 1, Exceptions: 0)
Write errors:           0
Non-2xx responses:      1
Total transferred:      9800112 bytes
HTML transferred:       560180 bytes
Requests per second:    6993.66 [#/sec] (mean)
Time per request:       285.973 [ms] (mean)
Time per request:       0.143 [ms] (mean, across all concurrent requests)
Transfer rate:          1673.31 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  158 443.7      4    3021
Processing:     6   19  40.6     13    1832
Waiting:        1   16  40.4     10    1832
Total:         11  177 451.5     17    3427

Percentage of the requests served within a certain time (ms)
  50%     17
  66%     18
  75%     20
  80%     21
  90%   1023
  95%   1029
  98%   1048
  99%   3023
 100%   3427 (longest request)

测试总结

数据汇总

请求连接数 并发数 请求失败数 每秒处理请求数 一次并发数请求响应时间(ms) 全体请求完成时间(s) 请求成功率
10000 1000 0
6994
147.574
1.476
100%
40000   2000 0 6994
285.973
5.719
100%
原文地址:https://www.cnblogs.com/liujunjun/p/11954559.html