Apache自带的ab压力测试工具用法详解

ab命令原理

Apache的ab命令模拟多线程并发请求,测试服务器负载压力,也能够测试nginx、lighthttp、IIS等其它Web服务器的压力。 ab命令对发出负载的计算机要求很低,既不会占用不少CPU,也不会占用太多的内存,但却会给目标服务器形成巨大的负载,所以是某些DDOS攻击之必备良药,老小皆宜。本身使用也须谨慎。不然一次上太多的负载,形成目标服务器直接因内存耗光死机,而不得不硬重启,得不偿失html

下载安装:

http://mirror.bit.edu.cn/apache//httpd/binaries/win32/?C=M;O=A 找到 httpd-2.2.21-win32-x86-no_ssl.msinginx

windows版本官方只提供源码,这里可参考下载: 连接:https://pan.baidu.com/s/1ylrI7G5nSFu-LBlYgY0T3Q 提取码:uzmrapache

运行:

在Windows系统下,打开cmd命令行窗口,定位到apache安装目录的bin目录下 cd C:\Program Files (x86)\Apache Software Foundation\Apache2.2\binwindows

键入命令:

ab -n 800 -c 800 http://192.168.0.10/ (-n发出800个请求,-c模拟800并发,至关800人同时访问,后面是测试url)服务器

ab -t 60 -c 100 http://192.168.0.10/ 在60秒内发请求,一次100个请求。网络

//若是须要在url中带参数,这样作 ab -t 60 -c 100 -T "text/plain" -p p.txt http://192.168.0.10/hello.html p.txt 是和ab.exe在一个目录 p.txt 中能够写参数,如 p=wdp&fq=78多线程

ab经常使用参数的介绍:

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

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

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

-p:POST时的数据文件

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

执行测试用例:ab -n 1000 -c 100 -w http://127.0.0.1/hello >>d:miss.html

ab并发负载压力测试

结果参数解释:

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

Benchmarking 192.168.0.10 (be patient) 
Completed 100 requests 
Completed 200 requests 
Completed 300 requests 
Completed 400 requests 
Completed 500 requests 
Completed 600 requests 
Completed 700 requests 
Completed 800 requests 
Finished 800 requests


Server Software:        Microsoft-HTTPAPI/2.0 
Server Hostname:        192.168.0.10 
Server Port:            80

Document Path:          / 
Document Length:        315 bytes       //HTTP响应数据的正文长度

Concurrency Level:      800 
Time taken for tests:   0.914 seconds     // 全部这些请求处理完成所花费的时间
Complete requests:      800              //完成请求数 
Failed requests:        0                //失败请求数 
Write errors:           0                
Non-2xx responses:      800 
Total transferred:      393600 bytes     //网络总传输量 
HTML transferred:       252000 bytes     //HTML内容传输量 
Requests per second:    875.22 [#/sec] (mean) //吞吐量-每秒请求数 
Time per request:       914.052 [ms] (mean)  //服务器收到请求,响应页面要花费的时间 
Time per request:       1.143 [ms] (mean, across all concurrent requests) //并发的每一个请求平均消耗时间 
Transfer rate:          420.52 [Kbytes/sec] received //平均每秒网络上的流量,能够帮助排除是否存在网络流量过大致使响应时间延长的问题

网络上消耗的时间的分解:

Connection Times (ms) 
              min  mean[+/-sd] median   max 
Connect:        0    1   0.5      1       3 
Processing:   245  534 125.2    570     682 
Waiting:       11  386 189.1    409     669 
Total:        246  535 125.0    571     684

//整个场景中全部请求的响应状况。在场景中每一个请求都有一个响应时间 
//其中 50% 的用户响应时间小于 571 毫秒 
//80 % 的用户响应时间小于 652 毫秒 
//最大的响应时间小于 684 毫秒 
Percentage of the requests served within a certain time (ms)
  50%    571 
  66%    627 
  75%    646 
  80%    652 
  90%    666 
  95%    677 
  98%    681 
  99%    682 
100%    684 (longest request)
相关文章
相关标签/搜索