ab 站点压力测试工具

时间:2023-03-09 13:04:23
ab 站点压力测试工具

ab--压力测试工具

前端时间由于需要测试一个网站的高并发的情况,使用到了一个ab测试工具,下面是我自己的体验及参考网上别人的博客所写,希望对大家有所帮助。

ab工具简介

  1. ab 全称:apache bench

    是apache自带的一个压力测试工具

    可以对apache,nginx,及tomcat等服务器进行压力测试

ab工具的安装

apache自带的工具,所以只要安装上apache后,就能够使用 ab 工具进行网站压力测试

  1. mac打开终端 可以直接使用
  2. windows 需要进入apache安装目录下 例如:cd C:\apache\Apache24\bin
  3. ubuntu 和 centos 如果在安装apache的情况下,应该可以直接使用 ab测试工具,如果没有安装apache的话可以使用命令直接安装ab测试工具(不用安装apache服务器)
    1. ubuntu安装ab

      apt-get install apache2-utils
    2. centos安装ab

      yum install httpd-tools

ab工具的使用

  1. 简单使用

    ab -n 100 -c 10 测试网址

    其中 -n 表示请求数,-c 表示并发数

    稍等一会儿就可以看到测试结果:如:
		lin:~ pingguo$ ab -n 10000 -c 100 http://www.baidu.com/
This is ApacheBench, Version 2.3 <$Revision: 1757674 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking www.baidu.com (be patient)
Completed 1000 requests Server Software: BWS/1.1 //服务器软件
Server Hostname: www.baidu.com //请求的地址
Server Port: 80 //请求的端口号 Document Path: / //页面路劲
Document Length: 112056 bytes //页面长度 Concurrency Level: 100 //并发数
Time taken for tests: 119.428 seconds //共使用多长时间
Complete requests: 1286 //请求数
Failed requests: 1284 //失败请求数
(Connect: 0, Receive: 0, Length: 1284, Exceptions: 0)
Total transferred: 149524294 bytes //总共传输字节数,包含http的头信息等
HTML transferred: 148232704 bytes //html字节数,实际的页面传递字节数
Requests per second: 10.77 [#/sec] (mean) //每秒多少请求,这个是非常重要的参数数值,服务器的吞吐量
Time per request: 9286.783 [ms] (mean) //用户平均请求等待时间
Time per request: 92.868 [ms] (mean, across all concurrent requests) //服务器平均处理时间,也就是服务器吞吐量的倒数
Transfer rate: 1222.66 [Kbytes/sec] received //每秒获取的数据长度 Connection Times (ms)
min mean[+/-sd] median max
Connect: 91 1401 3495.4 1204 72808 Processing: 2788 6865 4579.5 5943 46294
Waiting: 87 1363 591.0 1283 5082
Total: 2996 8266 5699.1 7184 80615 Percentage of the requests served within a certain time (ms)
50% 7184 // 50%的请求在7184ms内返回
66% 8651
75% 9142
80% 9460
90% 10783
95% 15674
98% 25099
99% 29224
100% 80615 (longest request)
lin:~ pingguo$ ab -n 100 -c 10 http://www.baidu.com/
This is ApacheBench, Version 2.3 <$Revision: 1757674 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking www.baidu.com (be patient)...apr_pollset_poll: The timeout specified has expired (70007)
Total of 99 requests completed
  1. 如果在测试的过程中需要使用到用户登录
    1. 先用账户和密码登录后,用开发者工具找到标识这个会话的Cookie值(Session ID)记下来

    2. 如果只用到一个Cookie,那么只需键入命令:

      ab -n 100 -C key=value http://test.com/

    3. 如果需要多个Cookie,就直接设Header:

      ab -n 100 -H “Cookie: Key1=Value1; Key2=Value2” http://test.com/

同类的工具

同类的工具还有 webbench、siege、http_load

本文参考:

http://www.jianshu.com/p/43d04d8baaf7

http://blog.****.net/wm_1991/article/details/51932658

如需转载,请注明出处 http://www.cnblogs.com/zhuchenglin/p/8066557.html