Linux下四款Web服务器压力测试工具(http_load、webbench、ab、siege)介绍
一、http_load
程序非常小,解压后也不到100K
http_load以并行复用的方式运行,用以测试web服务器的吞吐量与负载。但是它不同于大多数压力测试工具,它可以以一个单一的进程运行,一般不会把客户机搞死。还可以测试HTTPS类的网站请求。
官网地址:http://www.acme.com/software/http_load/
安装
下载最新的版本
#wget -c http://www.acme.com/software/http_load/http_load-09Mar2016.tar.gz #tar zxvf http_load-09Mar2016.tar.gz #cd http_load-09Mar2016/ #make && make install
命令格式:http_load -p 并发访问进程数 -s 访问时间 需要访问的URL文件
参数其实可以自由组合,参数之间的选择并没有什么限制。比如你写成http_load -parallel 5 -seconds
300 urls.txt也是可以的。我们把参数给大家简单说明一下。
-parallel 简写-p :含义是并发的用户进程数。
-fetches 简写-f :含义是总计的访问次数
-rate 简写-r :含义是每秒的访问频率
-seconds简写-s :含义是总计的访问时间
准备URL文件:urllist.txt,文件格式是每行一个URL,URL最好超过50-100个测试效果比较好.文件格式如下:
http://www.dpdp.fun/
例如:
http_load -p 30 -s 60 urllist.txt
参数了解了,我们来看运行一条命令来看看它的返回结果
命令:% ./http_load -rate 5 -seconds 10 urls说明执行了一个持续时间10秒的测试,每秒的频率为5。
49 fetches, 2 max parallel, 289884 bytes, in 10.0148 seconds5916 mean bytes/connection4.89274
fetches/sec, 28945.5 bytes/secmsecs/connect: 28.8932 mean, 44.243 max, 24.488 minmsecs/first
-response: 63.5362 mean, 81.624 max, 57.803 minHTTP response codes: code 200 — 49
结果分析:
1.49 fetches, 2 max parallel, 289884 bytes, in 10.0148 seconds
说明在上面的测试中运行了49个请求,最大的并发进程数是2,总计传输的数据是289884bytes,运行的时间是10.0148秒
2.5916 mean bytes/connection说明每一连接平均传输的数据量289884/49=5916
3.4.89274 fetches/sec, 28945.5 bytes/sec
说明每秒的响应请求为4.89274,每秒传递的数据为28945.5 bytes/sec
4.msecs/connect: 28.8932 mean, 44.243 max, 24.488 min说明每连接的平均响应时间是28.8932 msecs,最大的响应时间44.243 msecs,最小的响应时间24.488 msecs
5.msecs/first-response: 63.5362 mean, 81.624 max, 57.803 min
6、HTTP response codes: code 200 — 49 说明打开响应页面的类型,如果403的类型过多,那可能
要注意是否系统遇到了瓶颈。
特殊说明:
测试结果中主要的指标是 fetches/sec、msecs/connect 这个选项,即服务器每秒能够响应的查询次数,用这个指标来衡量性能。似乎比 apache的ab准确率要高一些,也更有说服力一些。
Qpt-每秒响应用户数和response time,每连接响应用户时间。
测试的结果主要也是看这两个值。当然仅有这两个指标并不能完成对性能的分析,我们还需要对服务器的cpu、men进行分析,才能得出结论
[root@centos-linux7 ~]# http_load -p 30 -s 60 urllist 624 fetches, 30 max parallel, 3.147e+07 bytes, in 60.0004 seconds 50432.7 mean bytes/connection 10.3999 fetches/sec, 524497 bytes/sec msecs/connect: 157.976 mean, 1700.28 max, 4.532 min msecs/first-response: 543.753 mean, 3228.5 max, 10.399 min HTTP response codes: code 200 -- 624
二、webbench
webbench是Linux下的一个网站压力测试工具,最多可以模拟3万个并发连接去测试网站的负载能力。下载地址可以到google搜,我这里给出一个
下载地址:http://home.tiscali.cz/~cz210552/webbench.html
http://home.tiscali.cz/~cz210552/distfiles/webbench-1.5.tar.gz
这个程序更小,解压后不到50K,呵呵
安装
#tar zxvf webbench-1.5.tar.gz #cd webbench-1.5 #make && make install
会在当前目录生成webbench可执行文件,直接可以使用了
用法:
webbench -c 并发数 -t 运行测试时间 URL
如:
webbench -c 5000 -t 120 http://www.163.com
[root@centos-linux7 webbench-1.5]# webbench -c 5000 -t 120 http://www.163.com/ Webbench - Simple Web Benchmark 1.5 Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software. Benchmarking: GET http://www.163.com/ 5000 clients, running 120 sec. Speed=11353 pages/min, 847436 bytes/sec. Requests: 85 susceed, 22621 failed. [root@centos-linux7 webbench-1.5]#
[root@centos-linux7 webbench-1.5]# webbench -c 5000 -t 120 http://www.dpdp.fun/ Webbench - Simple Web Benchmark 1.5 Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software. Benchmarking: GET http://www.dpdp.fun/ 5000 clients, running 120 sec. Speed=13695 pages/min, 483007 bytes/sec. Requests: 3688 susceed, 23702 failed. [root@centos-linux7 webbench-1.5]# webbench -c 5 -t 120 http://www.dpdp.fun/ Webbench - Simple Web Benchmark 1.5 Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software. Benchmarking: GET http://www.dpdp.fun/ 5 clients, running 120 sec. Speed=246 pages/min, 492558 bytes/sec. Requests: 493 susceed, 0 failed. [root@centos-linux7 webbench-1.5]#
三、ab
ab是apache自带的一款功能强大的测试工具
安装了apache一般就自带了,
用法可以查看它的说明
$ ./ab
./ab: wrong number of arguments
Usage: ./ab [options] [http://]hostname[:port]/path
Options are:
-n requests Number of requests to perform
-c concurrency Number of multiple requests to make
-t timelimit Seconds to max. wait for responses
-p postfile File containing data to POST
-T content-type Content-type header for POSTing
-v verbosity How much troubleshooting info to print
-w Print out results in HTML tables
-i Use HEAD instead of GET
-x attributes String to insert as table attributes
-y attributes String to insert as tr attributes
-z attributes String to insert as td or th attributes
-C attribute Add cookie, eg. ‘Apache=1234. (repeatable)
-H attribute Add Arbitrary header line, eg. ‘Accept-Encoding: gzip’
Inserted after all normal header lines. (repeatable)
-A attribute Add Basic WWW Authentication, the attributes
are a colon separated username and password.
-P attribute Add Basic Proxy Authentication, the attributes
are a colon separated username and password.
-X proxy:port Proxyserver and port number to use
-V Print version number and exit
-k Use HTTP KeepAlive feature
-d Do not show percentiles served table.
-S Do not show confidence estimators and warnings.
-g filename Output collected data to gnuplot format file.
-e filename Output CSV file with percentages served
-h Display usage information (this message)
参数众多,一般我们用到的是-n 和-c
例如:
./ab -c 1000 -n 100 http://www.dpdp.fun/index.php这个表示同时处理1000个请求并运行100次index.php文件.
zhangxiaobin@pooky:~ $ ab -c 1 -n 10 http://www.dpdp.fun/index.php 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 www.dpdp.fun (be patient).....done Server Software: nginx Server Hostname: www.dpdp.fun Server Port: 80 Document Path: /index.php Document Length: 0 bytes Concurrency Level: 1 Time taken for tests: 3.121 seconds Complete requests: 10 Failed requests: 0 Non-2xx responses: 10 Total transferred: 2100 bytes HTML transferred: 0 bytes Requests per second: 3.20 [#/sec] (mean) Time per request: 312.067 [ms] (mean) Time per request: 312.067 [ms] (mean, across all concurrent requests) Transfer rate: 0.66 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 4 7 1.3 7 9 Processing: 296 305 16.8 301 352 Waiting: 296 305 16.8 301 352 Total: 302 312 17.0 306 360 Percentage of the requests served within a certain time (ms) 50% 306 66% 308 75% 310 80% 314 90% 360 95% 360 98% 360 99% 360 100% 360 (longest request)
四、Siege
一款开源的压力测试工具,可以根据配置对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过程的相应时间,并在一定数量的并发访问下重复进行。
官方:https://www.joedog.org/siege-home/
Siege下载:http://download.joedog.org/siege/siege-3.1.4.tar.gz
解压:
# tar -zxf siege-3.1.4.tar.gz
进入解压目录:
# cd siege-3.1.4/
安装:
#./configure ; make
#make install
使用
siege -c 200 -r 10 -f example.url
-c是并发量,-r是重复次数。 url文件就是一个文本,每行都是一个url,它会从里面随机访问的。
example.url内容:
http://www.dpdp.fun
http://www.baidu.com
http://www.google.com=
结果说明
Lifting the server siege… done.
Transactions: 3419263 hits //完成419263次处理
Availability: 100.00 % //100.00 % 成功率
Elapsed time: 5999.69 secs //总共用时
Data transferred: 84273.91 MB //共数据传输84273.91 MB
Response time: 0.37 secs //相应用时1.65秒:显示网络连接的速度
Transaction rate: 569.91 trans/sec //均每秒完成 569.91 次处理:表示服务器后
Throughput: 14.05 MB/sec //平均每秒传送数据
Concurrency: 213.42 //实际最高并发数
Successful transactions: 2564081 //成功处理次数
Failed transactions: 11 //失败处理次数
Longest transaction: 29.04 //每次传输所花最长时间
Shortest transaction: 0.00 //每次传输所花最短时间
HTTP/1.1 200 11.50 secs: 19850 bytes ==> GET / HTTP/1.1 200 8.59 secs: 19851 bytes ==> GET / HTTP/1.1 200 12.29 secs: 19850 bytes ==> GET / HTTP/1.1 200 9.07 secs: 19850 bytes ==> GET / HTTP/1.1 200 5.24 secs: 19851 bytes ==> GET / HTTP/1.1 200 9.16 secs: 19850 bytes ==> GET / HTTP/1.1 200 8.79 secs: 19849 bytes ==> GET / HTTP/1.1 200 5.86 secs: 19851 bytes ==> GET / HTTP/1.1 200 6.04 secs: 19851 bytes ==> GET / HTTP/1.1 200 4.96 secs: 19850 bytes ==> GET / HTTP/1.1 200 6.54 secs: 19849 bytes ==> GET / HTTP/1.1 200 4.28 secs: 19850 bytes ==> GET / done. Transactions: 1605 hits Availability: 80.25 % Elapsed time: 115.70 secs Data transferred: 17.57 MB Response time: 10.08 secs Transaction rate: 13.87 trans/sec Throughput: 0.15 MB/sec Concurrency: 139.83 Successful transactions: 1605 Failed transactions: 395 Longest transaction: 31.99 Shortest transaction: 0.01 LOG FILE: /usr/local/var/siege.log You can disable this log file notification by editing /root/.siege/siege.conf and changing 'show-logfile' to false. [root@centos-linux7 ~]#