Ubuntu Ap压力测试

压力测试主要是指当测试多用户并发访问同一个应用、模块、数据时是否产生隐藏的并发问题,如内存泄漏、线程锁、资源争用问题,几乎所有的性能测试都会涉及并发测试。

这里使用apache2-utils进行测试

安装ab

sudo apt-get install apache2-utils

压力测试www.lubaogui.top的http访问性能

ab -n 10000 -c 100 http://www.lubaogui.top/

-n 10000 总共请求数10000 -c 100个并发线程同时访问 意思是启动 ab ,向 www.beimeibang.com 发送100个请求(-n 100) ,并每次发送10个请求(-c 10)——也就是说分10次发过去。

性能测试报告如下:

This is ApacheBench, Version 2.3 <$Revision: 1796539 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.lubaogui.top (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:        nginx/1.10.3
Server Hostname:        www.lubaogui.top
Server Port:            80

Document Path:          /
Document Length:        0 bytes

Concurrency Level:      1000
Time taken for tests:   105.491 seconds
Complete requests:      10000
Failed requests:        144
   (Connect: 0, Receive: 72, Length: 0, Exceptions: 72)
Non-2xx responses:      9840
Total transferred:      2420640 bytes
HTML transferred:       0 bytes
Requests per second:    94.79 [#/sec] (mean)
Time per request:       10549.090 [ms] (mean)
Time per request:       10.549 [ms] (mean, across all concurrent requests)
Transfer rate:          22.41 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0 1170 3266.8    193   31734
Processing:   106 1449 6337.1    215   77144
Waiting:        0  755 1364.5    211   28561
Total:        212 2619 7250.0    948   85486

Percentage of the requests served within a certain time (ms)
  50%    948
  66%   1404
  75%   1960
  80%   2366
  90%   4160
  95%   8191
  98%  29144
  99%  36540
 100%  85486 (longest request)

测试某个POST请求性能

#先将post参数写入postfile文件
ab -r -n 10000 -c 1000 -p postfile -m POST http://www.lubaogui.top/accounts/login/?next=/

性能测试报告如下:

This is ApacheBench, Version 2.3 <$Revision: 1796539 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.lubaogui.top (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:        nginx/1.10.3
Server Hostname:        www.lubaogui.top
Server Port:            80

Document Path:          /accounts/login/?next=/
Document Length:        1342 bytes

Concurrency Level:      1000
Time taken for tests:   182.479 seconds
Complete requests:      9316
Failed requests:        1121
   (Connect: 0, Receive: 120, Length: 853, Exceptions: 148)
Non-2xx responses:      9127
Total transferred:      13270890 bytes
Total body sent:        2140000
HTML transferred:       11561923 bytes
Requests per second:    51.05 [#/sec] (mean)
Time per request:       19587.681 [ms] (mean)
Time per request:       19.588 [ms] (mean, across all concurrent requests)
Transfer rate:          71.02 [Kbytes/sec] received
                        11.45 kb/s sent
                        82.47 kb/s total

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       12  595 3486.7    173   66075
Processing:    17 5113 10260.5   1436  104496
Waiting:        0 4510 9230.4   1236  101318
Total:         34 5707 10961.8   1818  119194

Percentage of the requests served within a certain time (ms)
  50%   1818
  66%   3352
  75%   5282
  80%   6893
  90%  14596
  95%  27129
  98%  43190
  99%  54945
 100%  119194 (longest request)

补充:

今天在用Apache自带的ab工具做以下简单的压测,本来是随便填几个参数,发现ab在1000并发以上报错:apr_socket_recv “connection reset by peer” 104 其中有一个是修改源代码的,通过这个答案的启发,我发现根本不用修改任何代码或者被测webserver的系统配置(这里仅针对ab出现的这个错误,如果是要调优webserver不在此范围内)

ab提供了一个参数:-r

这个参数的意思是当出现“receive error”,即接收数据错误时是否退出,默认是退出的,所以会出现上述的问题,加上这个标志就表示不退出了,有源码为证,如下:

源码路径: {apache_root_path}/support/ab.c

点赞

发表评论

电子邮件地址不会被公开。 必填项已用*标注

Title - Artist
0:00