http_load的使用

本文介绍了如何使用http_load工具进行压力测试,包括下载安装、参数使用和实际应用。通过指定并发连接数和请求频率,测试网站每秒承受的平均访问量和压力承受能力。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

基于linux平台的一种性能测工具。以并行复用的方式运行,用以测试web服务器的吞吐量与负载,测试web页面的性能。
优点
1.基于命令行,简单、易于上手
2.小巧轻便,解压缩后不到100k
3.开源,免费
缺点
1.仅适用于web页面的性能测试,不适用于访问数据库
2.测试结果分析有限
3.平台依赖linux

http_load官网: http://www.acme.com/software/http_load/

1. 下载和安装

进入工作目录:#cd /usr/local/

wget http://acme.com/software/http_load/http_load-12mar2006.tar.gz

tar zxvf http_load-12mar2006.tar.gz

进入http_load 目录:#cd http_load-12mar2006
编译和安装

make && make install

如果遇到错误,可以执行安装:yum -y install gcc gcc-c++


2. 参数使用

-fetches 简写-f :含义是总计的访问次数
-rate 简写-r :含义是每秒的访问频率
-seconds简写-s :含义是总计的访问时间
-parallel 简写-p:并发访问的线程数
urls是一个url 列表,每个url 单独的一行。可以单个页面。

3. 应用

测试网站每秒所能承受的平均访问量

http_load -parallel 5-fetches 1000urls.txt这段命令行是同时使用5个进程,随机访问urls.txt中的网址列表,总共访问1000次。运行之后的结果:
1000 fetches, 5 max parallel, 6e+06 bytes, in 58.1026 seconds
6000 mean bytes/connection
17.2109 fetches/sec, 103266 bytes/sec
msecs/connect: 0.403263 mean, 68.603 max, 0.194 min
msecs/first-response: 284.133 mean, 5410.13 max, 55.735 min
HTTP response codes:
code 200 — 1000
从上面的运行结果来看,目标网站仅仅能够承受每秒17次访问,不够强壮。

测试网站是否能承受住预期的访问压力

http_load -rate 2-seconds 300urls.txt
在300秒内保持一定的频率访问目标url。

示例:
对接口进行压力测试
http://10.32.22.60/vcsp/appData/news/recommend.do?useType=iPhone&channelId=000000-0&pageSize=20&positionId=255031
为了扩大测试样本,在后面自定义一个参数param=0,加上该参数后不会影响返回数据,只是降低缓存的命中率。
使用java写一个循环生成500个url

public class Demo {
public static void main(String[] args) throws IOException {

FileOutputStream fos = new FileOutputStream("D:/param.txt");
OutputStreamWriter osw = new OutputStreamWriter(fos);
BufferedWriter bw = new BufferedWriter(osw);
for(int i=0; i<500; i++){
bw.write("http://10.32.22.60/vcsp/appData/news/recommend.do?useType=iPhone&
channelId=000000-0&pageSize=20&positionId=255031&param="+i);
bw.newLine();
bw.flush();
}
bw.close();
osw.close();
fos.close();

}
}
在/usr/local目录下创建urls.txt文件,将生产的url粘贴过来。

开始测试啦:

./http_load -parallel 1 -seconds 60 urls.txt


如果在输入命令后报错: ./http_load: unknown protocol -, 说明txt文档中有多余的空行,要将其删除。

Note that when you provide a file with a list of URLs make sure that you don't have empty lines in it. If you do, then the utility won't work, complaining:


  ./http_load: unknown protocol -

大功告成了。


参考资料

Benchmarking Response Times With http_load
http_load is yet another utility that does Web server load testing. It can simulate a 33.6 modem connection (-throttle) and allows you to provide a file with a list of URLs, which we be fetched randomly. You can specify how many parallel connections to run using the -parallel N option, or you can specify the number of requests to generate per second with -rate N option. Finally, you can tell the utility when to stop by specifying either the test time length (-seconds N) or the total number of fetches (-fetches N).


A sample run with the file urls including:


  http://www.example.com/foo/
  http://www.example.com/bar/We ask to generate three requests per second and run for only two seconds. Here is the generated output:


  % ./http_load -rate 3 -seconds 2 urls
  http://www.example.com/foo/: check-connect SUCCEEDED, ignoring
  http://www.example.com/bar/: check-connect SUCCEEDED, ignoring
  http://www.example.com/bar/: check-connect SUCCEEDED, ignoring
  http://www.example.com/bar/: check-connect SUCCEEDED, ignoring
  http://www.example.com/foo/: check-connect SUCCEEDED, ignoring
  5 fetches, 3 max parallel, 96870 bytes, in 2.00258 seconds
  19374 mean bytes/connection
  2.49678 fetches/sec, 48372.7 bytes/sec
  msecs/connect: 1.805 mean, 5.24 max, 0.79 min
  msecs/first-response: 291.289 mean, 560.338 max, 34.349 minSo you can see that it has reported 2.5 requests per second. Of course, for the real test you will want to load the server heavily and run the test for a longer time to get more reliable results.


Note that when you provide a file with a list of URLs make sure that you don't have empty lines in it. If you do, then the utility won't work, complaining:
  ./http_load: unknown protocol -

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值