压测工具

两个常见压测工具的使用,一个叫siege,一个叫httperf,后者名字比较容易理解,http performance,前者的英文单词是围攻的意思,从功能上讲,这个名字特别贴切。

siege

多线程发压(load test)及基准测试(benchmark)工具。基本使用举例:

siege 'http://www.example.com/path/xxx.html' -c 10 -t8s

表示开启10个并发连接,发压10秒。结果如下: 

Transactions:		         151 hits
Availability:		      100.00 %
Elapsed time:		        7.80 secs
Data transferred:	        5.79 MB
Response time:		        0.01 secs
Transaction rate:	       19.36 trans/sec
Throughput:		        0.74 MB/sec
Concurrency:		        0.15
Successful transactions:         151
Failed transactions:	           0
Longest transaction:	        0.03
Shortest transaction:	        0.00

并不是按指定qps进行发压,而是每个连接,一个请求完成休息特定时间(默认是1秒)发起下一个请求,所以此种发压不会把服务器压挂。当然响应时间Response time越小,处理请求率Transaction rate就会越高。

休息特定秒数再发下一个请求是为了模拟用户行为,如果不进行休息,也就是进行所谓的基准测试,以获得服务器能处理的上限,需要加上-b参数,表示benchmarking。如:

siege 'http://www.example.com/path/xxx.html' -c 10 -t8s -b

还可以设置http请求的头部,如下:

siege 'http://www.example.com/index.html' --header="User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36" --header='Cookie: _xsrf=xxxxx; SID="XXXXX"' -c 10 -t8s

如果不想每次写这么长的--header,或者希望能做一些默认配置,那么就编辑一下~/.siegerc配置文件。-g参数可以发印出当前请求的http信息,用于调试。-f可以将所需要发压的url罗列在一个文件中,然后进行随机请求。

httperf

跟siege差不多功能,不过参数使用上要麻烦些,举例:

./bin/httperf --server 192.168.24.132 --port 8888 --uri '/path/index.html' --rate 100 --num-conn 100 --num-calls 100

输出如下:

httperf --client=0/1 --server=192.168.24.132 --port=8888 --uri=/pic/2b0dcc8781f2621351de506da1f3ce9f.jpg --rate=100 --send-buffer=4096 --recv-buffer=16384 --num-conns=100 --num-calls=100
httperf: warning: open file limit > FD_SETSIZE; limiting max. # of open files to FD_SETSIZE
Maximum connect burst length: 1

Total: connections 100 requests 10000 replies 10000 test-duration 12.888 s

Connection rate: 7.8 conn/s (128.9 ms/conn, <=100 concurrent connections)
Connection time [ms]: min 9897.0 avg 11771.6 max 12137.8 median 11995.5 stddev 535.5
Connection time [ms]: connect 0.0
Connection length [replies/conn]: 100.000

Request rate: 775.9 req/s (1.3 ms/req)
Request size [B]: 107.0

Reply rate [replies/s]: min 749.9 avg 779.1 max 808.3 stddev 41.3 (2 samples)
Reply time [ms]: response 117.7 transfer 0.0
Reply size [B]: header 205.0 content 40178.0 footer 0.0 (total 40383.0)
Reply status: 1xx=0 2xx=10000 3xx=0 4xx=0 5xx=0

CPU time [s]: user 0.45 system 11.35 (user 3.5% system 88.1% total 91.5%)
Net I/O: 30681.5 KB/s (251.3*10^6 bps)

Errors: total 0 client-timo 0 socket-timo 0 connrefused 0 connreset 0
Errors: fd-unavail 0 addrunavail 0 ftab-full 0 other 0

 

发表于 2016年04月02日 13:03   评论:0   阅读:2865  



回到顶部

首页 | 关于我 | 关于本站 | 站内留言 | rss
python logo   django logo   tornado logo