静,是一种休息,更是一种修行。所有的烦恼,都来自于喧嚣,所有的伤痛,都来自于躁动。身体奔波太久会劳累,灵魂游离太久会成伤。红尘淹没了纯洁,欲望吞噬了安详,经年后,心若一动,泪已千行。 停一停追逐的脚步,缓一缓紧绷的心弦,让心宁静,让伤口复原,让灵魂升华。

使用apache自带的ab做压力测试

| 发表于:2017-03-27 17:38:40 | 日志分类:测试开发 | 阅读量:(339)

看下linux主机上的ulimit -n 的数据是多少,为改动过的是1024,最好要改的大一点。这个是linux下最大线程数,如果过小的话无法进行大并量的测试。


ab常用参数的介绍:

-n :总共的请求执行数,缺省是1;

-c: 并发数,缺省是1;

-t:测试所进行的总时间,秒为单位,缺省50000s

-p:POST时的数据文件

-w: 以HTML表的格式输出结果

===========第一部分==============

wanghaifengdeiMac:~ chinaskin$ ab -n 5000  -c 300  -p json.ab http://192.168.63.134:1818/api/classify
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.63.134 (be patient)
Completed 500 requests
Completed 1000 requests
Completed 1500 requests
Completed 2000 requests
Completed 2500 requests
Completed 3000 requests
Completed 3500 requests
Completed 4000 requests
Completed 4500 requests
Completed 5000 requests
Finished 5000 requests


Server Software:        
Server Hostname:        192.168.63.134
Server Port:            1818

Document Path:          /api/classify
Document Length:        263 bytes

Concurrency Level:      300
Time taken for tests:   1.182 seconds
Complete requests:      5000
Failed requests:        0
Total transferred:      2000000 bytes
Total body sent:        1895000
HTML transferred:       1315000 bytes
Requests per second:    4230.70 [#/sec] (mean)
Time per request:         70.910 [ms] (mean)
Time per request:         0.236 [ms] (mean, across all concurrent requests)
Transfer rate:          1652.62 [Kbytes/sec] received
                             1565.85 kb/s sent
                             3218.47 kb/s total

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   1.8      2      10
Processing:     2   34  41.7     32    1105
Waiting:        1   30  41.7     28    1105
Total:          5   36  41.9     33    1109

Percentage of the requests served within a certain time (ms)
  50%     33
  66%     39
  75%     42
  80%     44
  90%     50
  95%     57
  98%     68
  99%     71
 100%   1109 (longest request)

================第二部份================不带keepAlive

wanghaifengdeiMac:~ chinaskin$ ab -n 500 -c 100  -T  "application/json"  -p asyncContact.ab   http://192.168.63.134:2348/api/v1/asyncContact
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.63.134 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Finished 500 requests


Server Software:        
Server Hostname:        192.168.63.134
Server Port:            2348

Document Path:          /api/v1/asyncContact
Document Length:        90 bytes

Concurrency Level:      100
Time taken for tests:   2.768 seconds
Complete requests:      500
Failed requests:        0
Total transferred:      116000 bytes
Total body sent:        213000
HTML transferred:       45000 bytes
Requests per second:    180.63 [#/sec] (mean)
Time per request:       553.605 [ms] (mean)
Time per request:       5.536 [ms] (mean, across all concurrent requests)
Transfer rate:          40.92 [Kbytes/sec] received
                             75.15 kb/s sent
                             116.07 kb/s total

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.7      0       3
Processing:    71  467 291.3    544     860
Waiting:       71  467 291.3    543     859
Total:         71  468 291.1    545     860
WARNING: The median and mean for the initial connection time are not within a normal deviation
        These results are probably not that reliable.

Percentage of the requests served within a certain time (ms)
  50%    545
  66%    734
  75%    764
  80%    778
  90%    801
  95%    810
  98%    831
  99%    838
 100%    860 (longest request)

================第三部分=================带上keepAlive

wanghaifengdeiMac:~ chinaskin$ ab -n 500 -c 100  -T  "application/json" -k  -p asyncContact.ab   http://192.168.63.134:2348/api/v1/asyncContact
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.63.134 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Finished 500 requests


Server Software:        
Server Hostname:        192.168.63.134
Server Port:            2348

Document Path:          /api/v1/asyncContact
Document Length:        90 bytes

Concurrency Level:      100
Time taken for tests:   2.541 seconds
Complete requests:      500
Failed requests:        0
Keep-Alive requests:    500
Total transferred:      118500 bytes
Total body sent:        225000
HTML transferred:       45000 bytes
Requests per second:    196.79 [#/sec] (mean)
Time per request:       508.146 [ms] (mean)
Time per request:       5.081 [ms] (mean, across all concurrent requests)
Transfer rate:          45.55 [Kbytes/sec] received
                             86.48 kb/s sent
                             132.03 kb/s total

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    3  15.5      0     101
Processing:   109  462  90.1    469     731
Waiting:      108  462  90.1    469     731
Total:        111  465  95.7    469     782

Percentage of the requests served within a certain time (ms)
  50%    469
  66%    487
  75%    498
  80%    507
  90%    536
  95%    633
  98%    731
  99%    736

 100%    782 (longest request)



============附带POST请求的JSON==============

{
"total":2,
"messages":[
                    {
                        "type":1,
                        "text":"现在为什么越来越多女生喜欢过于秀气的男生?",
                        "code":"001"
                    }
                 ]
}