get、post请求使用ab工具如何做并发测试

最近确实也有些忙,原来都是利用周末的时间写东西,现在周末的时间被占满,照顾小孩。只能忙中找空,写点东西。

最近正好使用ab性能测试工具测了一个项目,主要用来做并发测试,需求是控制水军用户的并发数,通过nginx配置控制并发量(针对异常ip--双ip),所以为了能够快速上线,就选择了ab工具。觉得ab工具多多少少还是可以快速的运用到工作当中,所以有必要写出来分享给需要的同行。主要介绍下使用ab工具并发发送get和post请求,比如日常工具中做并发测试可以使用(针对活动等相关库存的并发测试)

linux下安装ab性能测试工具

 
 
  1. yum -y install httpd-tools

安装完成后,执行:

 
 
  1. ab -H 'X-Forwarded-For:2.2.2.2' -n 100 -c 30 http://m.1768.com/?act=index&st=login

备注:

2.2.2.2为模拟的ip

查看nginx访问日志:

 
 
  1. m.1768.com 21.58.201.31 - - [18/Sep/2017:18:57:43 +0800] "GET /?act=index&st=login HTTP/1.0" 200 266 "-" "ApacheBench/2.3" 2.2.2.2,47.94.13.33

执行结果如下:

 
 
  1. [root@iZ9q9Z /]# ab -H 'X-Forwarded-For:2.2.2.2' -n 100 -c 30 http://m.1768.com/?

  2. act=index&st=login

  3. [1] 4515

  4. [root@iZ9otb9Z /]# This is ApacheBench, Version 2.3 <$Revision: 1430300 $>

  5. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

  6. Licensed to The Apache Software Foundation, http://www.apache.org/

  7. Benchmarking 10test7-admin.stg3.1768.com (be patient).....done

  8. Server Software:        nginx

  9. Server Hostname:        m.1768.com

  10. Server Port:            80

  11. Document Path:          /?act=index    #请求的资源

  12. Document Length:        0 bytes     #文档返回的长度,不包括相应的头

  13. Concurrency Level:      30          #并发数

  14. Time taken for tests:   0.609 seconds   #总请求时长

  15. Complete requests:      100            #总请求数

  16. Failed requests:        0           #失败的请求数

  17. Write errors:           0          #错误

  18. Non-2xx responses:      100

  19. Total transferred:      45900 bytes   #总共传输数据量

  20. HTML transferred:       0 bytes

  21. Requests per second:    164.18 [#/sec] (mean)   #平均每秒的请求数,重要指标:相当于LR中的每秒事务数,后面的括号中mean表示这是一个平均值

  22. Time per request:       182.725 [ms] (mean)    #平均每个请求消耗的时间,重要指标:LR中的平均事务响应时间

  23. Time per request:       6.091 [ms] (mean, across all concurrent requests)   #上面的请求除以并发数,即服务器平均请求响应时间 在并发量为1时 用户等待时间相同  

  24. Transfer rate:          73.59 [Kbytes/sec] received   #平均每秒多少K,即传输速率

  25. Connection Times (ms)

  26.              min  mean[+/-sd] median   max

  27. Connect:       28   32   1.7     32      36

  28. Processing:    70  106  25.5    100     169

  29. Waiting:       70  106  25.5    100     169

  30. Total:        100  138  25.7    134     202

  31. Percentage of the requests served within a certain time (ms)

  32.  50%    134        #50%的请求都在134ms内完成

  33.  66%    143

  34.  75%    153

  35.  80%    163

  36.  90%    180

  37.  95%    188

  38.  98%    193

  39.  99%    202

  40. 100%    202 (longest request)

具体每个参数的含义可以参考如下地址,里面有很详细的介绍。

 
 
  1. http://www.jb51.net/article/59469.htm

举例

get请求

 
 
  1. ab -H 'X-Forwarded-For:2.2.2.2' -n 100 -c 10 -C "Cookie: appId=3793; track_u_3793=CS1111QXZ591F5C6066AACC1B57273B8; popbeforelogin=aToxOw%3D%3D; Hm_lvt_a52c9eb6cde4f51aa1212ed955bc723c=1504493440,1504503826,1504580247,1505092652; Hm_lpvt_a52c9eb6cde4f51aa1212ed955bc723c=1505121635; YOUXISID=88811fde2b2d2648ae4b4ddefa7da6f28530cb2a; is_visitor=0; point_games_flag_v9_game_circus_5252037600830=2037600830; exchangeReturnUrl=%2F%3Fact%3Dgame_collection; ucenter=newucenter; newucenter_nologout=1; tExchangeBackUrl=newucenter; PHPSESSID=5vqp5j4knn6mldjqt2fovc3ad5; track_u_3783=37yoo; track_u=37yoo; point_games_flag_v9_pinballwap_5252037600830=2037600830; gameHistoryRecord=a%3A3%3A%7Bi%3A0%3Bi%3A3697%3Bi%3A1%3Bi%3A3783%3Bi%3A2%3Bi%3A3793%3B%7D; tExchangeBacToGame=%2F%3Fact%3Dpinballwap; loginReturnUrl=%2F%3Fact%3Dpinballwap%26track_u%3D37yoo; Hm_lvt_be49684f9d9c2de3c96227f9e25c261b=1503630548,1505359432; Hm_lpvt_be49684f9d9c2de3c96227f9e25c261b=1505375090; Hm_lvt_70e5a3dba732ce8be082655aff6ff1e6=1503455932,1504839932,1505186995; Hm_lpvt_70e5a3dba732ce8be082655aff6ff1e6=1505375091" "http://m.1768.com/?act=pinballwap&act=pinballwap&st=play_once&amount=500&newer=1&rndnum=599719"

备注:

1.cookie内容一定要加个双引号;
2.请求url加双引号;

post请求

 
 
  1. ab -H 'X-Forwarded-For:2.2.2.2' -n 1000 -c 100 -p /root/circus.txt -T application/x-www-form-urlencoded -C "Cookie: appId=3793; track_u_3793=CS1111QXZ591F5C6066AACC1B57273B8; popbeforelogin=aToxOw%3D%3D; track_u_3783=37yoo; YOUXISID=14fe43e78bd2e7e41934ac8e9fc809ed881af5fd; is_visitor=0; exchangeReturnUrl=%2F%3Fact%3Dgame_collection; track_u=37yoo; ucenter=newucenter; newucenter_nologout=1; tExchangeBackUrl=newucenter; point_games_flag_v9_game_circus_5252037600830=2037600830; PHPSESSID=5vqp5j4knn6mldjqt2fovc3ad5; gameHistoryRecord=a%3A3%3A%7Bi%3A0%3Bi%3A3783%3Bi%3A1%3Bi%3A3697%3Bi%3A2%3Bi%3A3793%3B%7D; tExchangeBacToGame=%2F%3Fact%3Dgame_circus; loginReturnUrl=%2F%3Fact%3Dgame_circus; Hm_lvt_be49684f9d9c2de3c96227f9e25c261b=1503630548,1505359432; Hm_lpvt_be49684f9d9c2de3c96227f9e25c261b=1505469850; Hm_lvt_70e5a3dba732ce8be082655aff6ff1e6=1503455932,1504839932,1505186995; Hm_lpvt_70e5a3dba732ce8be082655aff6ff1e6=1505469852" "http://m.1768.com/?index.php"

circus.txt文件中保存的参数格式:
 
 
  1. act=game_circus&st=start&amount=1300&isNewUser=0&autoBetFlag=0

执行结果如下:

 
 
  1. [root@iz2zfd6z ~]# ab -H 'X-Forwarded-For:2.2.2.2' -n 1000 -c 100 -C "Cookie: appId=3793; track_u_3793=CS1111QXZ591F5C6066AACC1B57273B8; popbeforelogin=aToxOw%3D%3D; track_u_3783=37yoo; YOUXISID=14fe43e78bd2e7e41934ac8e9fc809ed881af5fd; is_visitor=0; exchangeReturnUrl=%2F%3Fact%3Dgame_collection; track_u=37yoo; ucenter=newucenter; newucenter_nologout=1; tExchangeBackUrl=newucenter; point_games_flag_v9_game_circus_5252037600830=2037600830; PHPSESSID=5vqp5j4knn6mldjqt2fovc3ad5; gameHistoryRecord=a%3A3%3A%7Bi%3A0%3Bi%3A3783%3Bi%3A1%3Bi%3A3697%3Bi%3A2%3Bi%3A3793%3B%7D; tExchangeBacToGame=%2F%3Fact%3Dgame_circus; loginReturnUrl=%2F%3Fact%3Dgame_circus; Hm_lvt_be49684f9d9c2de3c96227f9e25c261b=1503630548,1505359432; Hm_lpvt_be49684f9d9c2de3c96227f9e25c261b=1505469850; Hm_lvt_70e5a3dba732ce8be082655aff6ff1e6=1503455932,1504839932,1505186995; Hm_lpvt_70e5a3dba732ce8be082655aff6ff1e6=1505469852" -p /root/circus.txt -T application/x-www-form-urlencoded "http://m.1768.com/?index.php"

  2. This is ApacheBench, Version 2.3 <$Revision: 1430300 $>

  3. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

  4. Licensed to The Apache Software Foundation, http://www.apache.org/

  5. Benchmarking 10test7-wap.stg3.1768.com (be patient)

  6. Completed 100 requests

  7. Completed 200 requests

  8. Completed 300 requests

  9. Completed 400 requests

  10. Completed 500 requests

  11. Completed 600 requests

  12. Completed 700 requests

  13. Completed 800 requests

  14. Completed 900 requests

  15. Completed 1000 requests

  16. Finished 1000 requests

  17. Server Software:        nginx

  18. Server Hostname:        10test7-wap.stg3.1768.com

  19. Server Port:            80

  20. Document Path:          /?index.php

  21. Document Length:        267 bytes

  22. Concurrency Level:      100

  23. Time taken for tests:   13.657 seconds

  24. Complete requests:      1000

  25. Failed requests:        993

  26.   (Connect: 0, Receive: 0, Length: 993, Exceptions: 0)

  27. Write errors:           0

  28. Total transferred:      365377 bytes

  29. Total body sent:        1098000

  30. HTML transferred:       102377 bytes

  31. Requests per second:    73.22 [#/sec] (mean)

  32. Time per request:       1365.722 [ms] (mean)

  33. Time per request:       13.657 [ms] (mean, across all concurrent requests)

  34. Transfer rate:          26.13 [Kbytes/sec] received

  35.                        78.51 kb/s sent

  36.                        104.64 kb/s total

  37. Connection Times (ms)

  38.              min  mean[+/-sd] median   max

  39. Connect:       25   45 125.7     29    1037

  40. Processing:   115  911 1246.9    637    8654

  41. Waiting:      115  911 1246.9    637    8654

  42. Total:        146  957 1248.8    675    8683

  43. Percentage of the requests served within a certain time (ms)

  44.  50%    675

  45.  66%    834

  46.  75%   1028

  47.  80%   1117

  48.  90%   1476

  49.  95%   3128

  50.  98%   7552

  51.  99%   7636

  52. 100%   8683 (longest request)

至于用作性能分析建议还是使用LR,有兴趣也可以对性能结果进行分析。

请加入测试技术分享圈,开始您的学习之旅吧!



长按二维码 一键加入  640?wx_fmt=jpeg

87testing.com

长按识别二维码加入:测试技术分享圈

640?wx_fmt=png



  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: http-get/post 多线程数并发测试工具是一种可以模拟多个用户同时访问网站的软件,用于测试网站在高并发情况下的性能和稳定性。 该工具利用多线程技术,同时向目标网站发送 http-get/post 请求,并对返回结果进行统计和分析,从而得出目标网站在多线程并发量下的响应时间、并发数、错误率等指标。 在使用 http-get/post 多线程数并发测试工具时,需要配置好目标网站的地址和请求参数,以及并发测试的线程数和持续时间。工具会生成多个线程,并在指定的时间内不断发送请求,直至测试结束。 通过使用工具,可以有效评估网站在高并发访问时的性能和稳定性,提高网站的负载能力和用户体验。同时,在网站开发和维护中,也可以利用该工具进行压力测试,以及对代码和服务器性能进行优化。 ### 回答2: HTTP-get/post多线程数并发测试工具是一种可以模拟多用户同时向服务器发起HTTP请求,并记录服务器的响应时间和处理能力的工具。它可以帮助开发人员和测试人员评估服务器的性能、稳定性和可扩展性。 该工具可以对HTTP请求进行自定义配置,如请求的URL、请求方法、请求头、请求体等。同时,它支持多线程并发测试,可以同时向服务器发送大量请求,以测试服务器在负载下的响应速度和资源占用情况,从而帮助开发人员找出并解决潜在的性能瓶颈。 在使用工具进行测试时,需要注意以下几点: 1. 测试目标必须是真实的服务器,因为测试结果会受服务器本身的性能和负载情况影响。 2. 选择合适的请求参数和并发数,以模拟真实用户对服务器的请求负载。如果请求参数和并发数过高,可能会导致服务器崩溃或性能下降。 3. 选择合适的测试工具,不同的测试工具有不同的性能和功能特点,需要根据具体的需求进行选择。 综上所述,HTTP-get/post多线程数并发测试工具是一种非常有用的工具,它能够帮助我们评估服务器的性能、稳定性和可扩展性,发现服务器在高负载情况下的性能瓶颈,并及时进行优化和改进。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值