利用Apache Bench测试Web引擎性能

Apache Bench是著名Web服务器软件apache附带的一个小工具,它可以同时模拟多个并发请求,测试apache等Web服务器的最大承载压力,同时也可以根据Apache Bench提供的测试结果对服务器性能参数进行调整。

由于本参数相当于单IP CC攻击,请不要随意测试别人的网站。

一、安装Apache

yum install httpd
最简单获取apache的方法,在CentOS系统下执行以上命令(请注意保证不要和nginx等其它Web服务器冲突)。

二、使用ab命令

Apache Bench(ab)最基本的用法是:
ab -n 100 -c 100 http://www.longsays.com/

在SSH中执行以上命令,网址则修改成您的网站地址,必须在后方加上“/”,或指定相应文件。

“-n”表示:每次请求数,默认不能超过1024个,否则需要修改系统进程限制。
“-c”表示:1个请求的并发连接数,默认最大不能超过50000。

并发连接数不能够大于请求数,即C≤ N 否则会提示:Cannot use concurrency level greater than total number of requests。

三、查看结果


This is ApacheBench, Version 2.0.40-dev apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking www.longsays.com (be patient)
Finished 130 requests

Server Software: nginx/1.0.10 #Web服务器引擎
Server Hostname: www.longsays.com #服务器地址
Server Port: 80 #服务器端口

Document Path: / #请求的文件路径
Document Length: 20718 bytes #文件大小

Concurrency Level: 1020 #并发次数
Time taken for tests: 20.6751 seconds #测试所需时间
Complete requests: 130 #成功请求次数
Failed requests: 0 #失败请求次数
Write errors: 0 #写入错误
Total transferred: 3041510 bytes #测试过程传输字节数
HTML transferred: 2957081 bytes #HTML内容传输字节数
Requests per second: 6.50 [#/sec] (mean) #平均返回数据时间
Time per request: 156976.039 [ms] (mean) #平均响应时间
Time per request: 153.898 [ms] (mean, across all concurrent requests)
#平均并发请求时间
Transfer rate: 148.45 [Kbytes/sec] received #平均传输速率

Connection Times (ms) #响应时间小、中、大值
min mean[+/-sd] median max
Connect: 322 346 18.0 338 401
Processing: 1344 8898 4081.5 9795 19341
Waiting: 669 7629 3782.7 8802 18617
Total: 1682 9245 4087.6 10148 19684

Percentage of the requests served within a certain time (ms)
50% 10148
66% 11054
75% 11567
80% 12797
90% 14636
95% 15551
98% 16834
99% 18119
100% 19684 (longest request)
#以上为所有请求的平均速度,如在测试过程中进度到50%时平均响应时间为10148ms,到66%时
平均响应时间为11054ms。

四、其它参数

选项 相应功能
-n 执行请求数量
-c 每个请求的并发连接数
-t 等待响应时间
-V 显示版本信息

还有部分不常用参数请自行求助搜索引擎。

《利用Apache Bench测试Web引擎性能》上有15条评论

    1. 都说了相当于cc攻击了
      而且我演示的默认并发连接数比较高!你的话100足以
      10请求,每请求10并发
      就是100并发/s
      对于博客绝对完全够用了

回复 myswty.com 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注