网站压力测试工具

大多数在win下面进行开发 的人员,在做压力测试时,都是采用了apache 自带的ab.exe进行测试的。工具 虽然小,但也算强大。只是Ab的数据 不是特别准确。
除此之一,还有一些工具可以做压力测试,如loadRunner,webbench等。现在我就做一点小小的介绍。。

ab命令 的参数、输出结果的中文 注解格式: ./ab [options] [http://]hostname[:port]/path  
参数:  
-n requests Number of requests to perform  
//在测试会话中所执行的请求个数。默认时,仅执行一个请求  
-c concurrency Number of multiple requests to make  
//一次产生的请求个数。默认是一次一个。  
-t timelimit Seconds to max. wait for responses  
//测试所进行的最大秒数。其内部隐含值是-n 50000。它可以使对服务器 的测试限制在一个固定的总时间以内。默认时,没有 时间限制。  
-p postfile File containing data to POST  
//包含了需要POST的数据的文件 .  
-T content-type Content-type header for POSTing  
//POST数据所使用的Content-type头信息。  
-v verbosity How much troubleshooting info to print  
//设置 显示信息的详细程度 - 4或更大值会显示头信息, 3或更大值可以显示响应代码 (404, 200等), 2或更大值可以显示警告和其他信息。 -V 显示版本号并退出。  
-w Print out results in HTML tables  
//以HTML表的格式输出结果。默认时,它是白色背景的两列宽度的一张表。  
-i Use HEAD instead of GET  
// 执行HEAD请求,而不是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)  
//-C cookie-name=value 对请求附加一个Cookie:行。 其典型形式是name=value的一个参数对。此参数可以重复。  
-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.  
//-P proxy-auth-username:password 对一个中转代理提供BASIC认证信任。用户 名和密码由一个:隔开,并以base64编码形式发 送。无论服务 器是否需要(即, 是否发送了401认证需求代码),此字符 串都会被发送。  
-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)  
//-attributes 设置 属性的字符串. 缺陷程序 中有各种静态声明的固定长度的缓冲区。另外,对命令 行参数、服务器的响应头和其他外部输入的解析 也很简单,这可能会有不良后果。它没有完整地实现 HTTP/1.x; 仅接受某些'预想'的响应格式。 strstr(3)的频繁使用可能会带来性能 问题,即, 你可能是在测试ab而不是服务器的性能。  
  
参数很多,一般我们用 -c 和 -n 参数就可以了. 例如:  
  
./ab -c 1000 -n 1000 http://127.0.0.1/index.php   
  
这个表示同时处理1000个请求并运行1000次 index.php文件.  
#/usr/local/xiaobai/apache2054/bin/ab -c 1000 -n 1000 http://127.0.0.1/index.html.zh-cn.gb2312   
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.121.2.12 $> apache-2.0  
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/   
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/   
  
Benchmarking 127.0.0.1 (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  
Completed 900 requests  
Finished 1000 requests  
  
  
Server Software: Apache/2.0.54  
//平台 apache 版本2.0.54  
Server Hostname: 127.0.0.1  
//服务器主机名  
Server Port: 80  
//服务器端口  
  
Document Path: /index.html.zh-cn.gb2312  
//测试的页面 文档   
Document Length: 1018 bytes  
//文档大小  
  
Concurrency Level: 1000  
//并发数  
Time taken for tests: 8.188731 seconds  
//整个测试持续的时间  
Complete requests: 1000  
// 完成的请求数量  
Failed requests: 0  
//失败的请求数量  
Write errors: 0  
  
Total transferred: 1361581 bytes  
//整个场景中的网络 传输量  
HTML transferred: 1055666 bytes  
//整个场景中的HTML内容传输量  
Requests per second: 122.12 [#/sec] (mean)  
//大家最关心的指标之一,相当于 LR 中的 每秒事务数 ,后面括号中的 mean 表示这是一个平均值  
Time per request: 8188.731 [ms] (mean)  
//大家最关心的指标之二,相当于 LR 中的 平均事务响应时间 ,后面括号中的 mean 表示这是一个平均值  
Time per request: 8.189 [ms] (mean, across all concurrent requests)  
//每个请求实际运行时间的平均值  
Transfer rate: 162.30 [Kbytes/sec] received  
//平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题  
  
Connection Times (ms)  
min mean[+/-sd] median max  
Connect: 4 646 1078.7 89 3291  
Processing: 165 992 493.1 938 4712  
Waiting: 118 934 480.6 882 4554  
Total: 813 1638 1338.9 1093 7785  
//网络上消耗的时间的分解,各项数据的具体算法还不是很清楚  
  
Percentage of the requests served within a certain time (ms)  
50% 1093  
66% 1247  
75% 1373  
80% 1493  
90% 4061  
95% 4398  
98% 5608  
99% 7368  
100% 7785 (longest request)  
//整个场景中所有请求的响应情况。在场景中每个请求都有一个响应时间,其中50%的用户响应时间小于1093 毫秒,60% 的用户响应时间小于1247 毫秒,最大的响应时间小于7785 毫秒  
  
由于对于并发请求,cpu实际上并不是同时处理的,而是按照每个请求获得的时间片逐个轮转处理的,所以基本上第一个Time per request时间约等于第二个Time per request时间乘以并发请求数   

loadrunner简介
LoadRunner 对应用 程序进行压力测试,以隔离并标识潜在的客户端 、网络和服务器瓶颈。  
通过 LoadRunner,可以在可控制的峰值负载 条件下测试系统 。要生成负载,LoadRunner 需要运行分布在网络中的数千个虚拟用户 (Vuser)。通过使用最少的硬件资源,这些 Vuser 提供一致的、可重复并可度量的负载,像实际用户一样使用您的应用程序。LoadRunner 深入的报告和图可以提供评估应用程序性能所需的信息。  
  
LoadRunner 技术   
使用 Mercury LoadRunner,可以创建场景,并在其中定义性能测试会话期间发生的事件。在场景中, LoadRunner 会在物理计算机上用虚拟用户(即 Vuser)代替真实用户。这些 Vuser 通过以可重复、可预测的方式模拟典型用户的操作,在系统上创建负载。假设您正在测试一个基于 Web 的旅行代理应用程序(用户可以通过它在线预订航班),并要确定多个用户同时执行相同的事务时,该应用程序将如何处理。使用 LoadRunner代替旅行代理,您可以创建具有 1000 个 Vuser 的场景,并且这些 Vuser 可以同时尝试在应用程序中预订航班。  
  
测试过程  
LoadRunner 测试过程由以下四个基本步骤组成:  
➤ 步骤 1 — 创建脚本 :捕获在您的应用程序中执行的典型最终用户业务流 程。  
➤ 步骤 2 — 设计 场景:通过定义测试会话期间发生的事件,设置负载测 试环境 。  
➤ 步骤 3 — 运行场景:运行、管理 并监控负载测试。  
➤ 步骤 4 — 分析结果:分析负载测试期间 LoadRunner 生成的性能数据。  
  
LoadRunner 组件  
测试过程的每个步骤均由一个 Mercury LoadRunner 组件执行。这些组件如下:  
➤ Mercury 虚拟用户生成器 (VuGen) — 创建脚本VuGen 通过录制应用程序中典型最终用户执行的操作来生成虚拟用户 (Vuser)。VuGen 将这些操作录制到自动虚拟用户脚本中,以便作为负载测试的基础 。  
➤ Mercury LoadRunner Controller — 设计和运行场景Controller 是用来创建、管理和监控负载测试的中央控制台。使用 Controller 可以运行用来模拟真实用户执行的操作的脚本,并可以通过让多个 Vuser (虚拟用户)同时执行这些操作来在系统中创建负载。  
➤ Mercury Analysis — 分析场景  
Mercury Analysis 提供包含深入的性能分析信息的图和报告。使用这些图和报告,可以标识和确定应用程序中的瓶颈,并确定需要对系统进行哪些更改来提高系统性能。

WEBbench简介
webbench最多可以模拟3万个并发连接去测试网站的负载能力,个人感觉要比Apache自带的ab压力测试工具好,安装使用也特别方便。  
  
  1、适用系统:Linux  
  
  2、编译 安装:  
  
wget http://blog.s135.com/soft/linux /webbench/webbench-1.5.tar.gz   
tar zxvf webbench-1.5.tar.gz  
cd webbench-1.5  
make && make install  
  
  3、使用:  
  
webbench -c 500 -t 30 http://127.0.0.1/test.jpg   
  参数说明:-c表示并发数,-t表示时间(秒)  
  
  4、测试结果示例:  
  
Webbench - Simple Web Benchmark 1.5  
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.  
  
Benchmarking: GET http://127.0.0.1/test.jpg   
500 clients, running 30 sec.  
  
Speed=3230 pages/min, 11614212 bytes/sec.  
Requests: 1615 susceed, 0 failed.  

ab是最方便的。毕竟他直接内置。。。webbench需要安装在linux下,一般人还真难装。loadRunner太大了,几百兆的东西,而且,很多 人还用不来。

发布了31 篇原创文章 · 获赞 11 · 访问量 23万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章