httperf测试

HTTPS的压力测试工具 -- httperf

httperf

1. 官方描述:
Httperf is a tool for measuring web server performance. It provides a flexible facility for generating various HTTP workloads and for measuring server performance. The focus of httperf is not on implementing one particular benchmark but on providing a robust, high-performance tool that facilitates the construction of both micro- and macro-level benchmarks. The three distinguishing characteristics of httperf are its robustness, which includes the ability to generate and sustain server overload, support for the HTTP/1.1 and SSL protocols, and its extensibility to new workload generators and performance measurements.
2. 使用方法:
httperf --client=0/1 --server=[YOUR_DOMAIN] --port=443 --uri=/a.php --rate=100 --send-buffer=4096 --recv-buffer=16384 --ssl --num-conns=50 --num-calls=1000
例样含义:
  • --client=I/N 指定当前客户端I,是N个客户端中的第几个。用于多个客户端发请求,希望确保每个客户端发的请求不是完全一致。一般不用指定
  • --server 请求的server名
  • --port 请求的端口号,默认为80,如果指定了--ssl为443
  • --uri 请求路径
  • --rate 指定一个固定速率来创建连接和会话
  • --num-conns 创建连接数
  • --num-call 每个连接发送多少请求
  • --send-buffer 指定发送http请求的最大buffer,默认为4K,一般不用指定
  • --recv-buffer 指定接受http请求的最大buffer,默认为16K,一般不用指定
3. 结果分析:
  • Maximum connect burst length: 6
  • 最大并发连接数:6
  • Total: connections 50 requests 5050 replies 5000 test-duration 9.193 s
  • 一共50个连接,5050个请求,应答了5000个,测试耗时:9.193秒
  • Connection rate: 5.4 conn/s (183.9 ms/conn, <=50 concurrent connections)
  • 连接速率:5.4个每秒(每个连接耗时183.9 ms, 小于指定的50个并发连接)
  • Connection time [ms]: min 8364.0 avg 8757.5 max 9014.7 median 8899.5 stddev 231.9
  • 连接时间(微秒):最小8364.0,平均8757.5,最大9014.7,中位数 8899.5, 标准偏差231.9
  • Connection time [ms]: connect 89.9
  • 连接时间(微秒):连接 89.9
  • Connection length [replies/conn]: 100.000
  • 连接长度(应答/连接):100.000
  • Request rate: 549.3 req/s (1.8 ms/req)
  • 请求速率:549.5 (pqs),每个请求1.8 ms
  • Request size [B]: 72.0
  • 请求长度(字节):72.0
  • Reply rate [replies/s]: min 514.8 avg 514.8 max 514.8 stddev 0.0 (1 samples)
  • 响应速率(响应个数/秒):最小514.8, 平均514.8,最大514.8,标准偏差 0.0(一个例样)
  • Reply time [ms]: response 25.5 transfer 61.0
  • 响应时间(微妙):响应25.5,传输61.0
  • Reply size [B]: header 147.0 content 53263.0 footer 2.0 (total 53412.0)
  • 响应包长度(字节):响应头147.0 内容:53263.0 响应末端 2.0(总共53412.0)
  • Reply status: 1xx=0 2xx=5000 3xx=0 4xx=0 5xx=0
  • 响应包状态: 2xx 有5000个,其他没有
  • CPU time [s]: user 9.00 system 0.20 (user 97.9% system 2.1% total 100.0%)
  • CPU时间(秒): 用户9.00 系统0.2(用户占了97.9% 系统占2.1% 总共100%)
  • Net I/O: 28407.8 KB/s (232.7*10^6 bps)
  • 网络I/O:28407.8 K每秒
  • Errors: total 50 client-timo 0 socket-timo 0 connrefused 0 connreset 50
  • 错误:总数50 客户端超时0 套接字超时0 连接拒绝0 连接重置50
  • Errors: fd-unavail 0 addrunavail 0 ftab-full 0 other 0
  • 错误:fd不正确0 地址不正确0 ftab占满0 其他0
更轻量级的测试http的压力测试工具,http_load



httperf命令常用参数 
 
最近在做 WEB 压力测试,重新捡起了已经 N 年木有使用过的 httperf。发现这家伙竟然还在更新,而且迁移到了 Google Code (http://code.google.com/p/httperf/)。新版的 
httperf 相比之前有些变化,对请求的发起控制做的更加细化了。学习了一番,难懂的就是 wsess 这个参数了。 
首先我们看一下 –wsess 这个参数的格式: 
–wsess=N1,N2,X 
N1: 代表本次测试发起的总会话数 (session); N2: 代表每个会话中发起请求的次数; 
X: 代表每次“冲击” (burst) 间隔的时间(以“秒”为单位); 接下来,需要理解一下会话 (session) 到底是个什么东西? 
在 htterf 中,session 是由一系列的“冲击”(“冲击”可以理解为对 WEB SERVER 发起的一次测试访问。当然,我对这个 burst 翻译的比较晦涩,系统你能明白。)组成,“冲击”之间相隔的时间由 X 控制。 这就是会话。 
而一次“冲击”(测试访问)中又包含多个请求(可以理解为并发)。包含请求的个数可以使用 –burst-length=N 指定。 
那么 httperf 是如何处理一次“冲击”中并发请求的呢? 
首先,一个单独的请求被发送至 WEB SERVER,一旦这个请求被完整的接收,那么剩下的所有请求 (N – 1),将会同时发送至 WEB SERVER。所以,从这个机制来看,httperf 发起的一次访问总,真实的并发数应是 N – 1  个。 OK,了解了上面这些,我们再来看一个例子:
./httperf \ --hog \ 
--server=www.inanu.net \ --uri=/mysql.php \ --wsess=100,1000,3 \ --burst-length=10 \ --rate=5 \ --timeout=5 
这是一个在实际情况中用到的压力测试命令以及参数。我们逐个解释,其中也包含了上面说到的 –wsess 和 –burst-length。 
–hog: 这个选项会让 httperf 使用尽可能多的 TCP 端口。如果不使用这个选项,则 
httperf 默认值会使用从 1024 到 5000 这些端口发起请求。当然,在重度压力测试中,这么点端口显然是不够用的。 
–server: 这个不用说了,指定 WEB SERVER 的主机名称。 
–uri: 指定需要访问的压力测试脚本(资源),不要忘记前面的”/”。 
–wsess=100,1000,3 –burst-length=10: 我们将这两个参数结合起来解释,结合上面讲到的,本次测试一共有 100 个会话 (session),每个会话包含 1000 次请求,而 
–burst-length 指定了每次测试访问会包含 10 个请求。那么,每个会话真正执行的测试访问次数不难算出,就是 100 次啦!有点绕吗?其实就是 N2/burst-length。如果还是不明白,再看一次开头的那些解释说明吧。最后的 “3″,指定每次测试访问发起的间隔是 3 秒。 –rate=5: 意思就是会话的发起率。在本例中,就是每个会话建立的时间相隔 5 秒。 –timeout=5: 如果一个请求在 5 秒内没有能得到正确的响应和返回,则判定这次请求失败。 
最后,当我们执行上面的测试指令时,会发现 httperf 还自动加上了一个 –client=0/1 。这是什么意思呢? 
其实这并不是和 TCP 连接有任何关系,这只是测试发起端的标识符罢了。在通常情况下,我们会使用很多台请求发起机对一个 WEB SERVER 进行测试。这个 –client=I/N 就是标识这个请求是由哪台测试发起端发出的。I 是本台机器的编号,N 代表这次测试一共有多少台测试发起机。

http://2hei.net/mt/2010/01/linux-web-test-tools-for-https.html

linux下支持https的压力测试工具

作者: 2hei 发表于2010年1月24日 11:02
版权声明: 可以转载, 转载时务必以超链形式标明文章原始出处和作者信息及 版权声明
http://www.2hei.net/mt/2010/01/linux-web-test-tools-for-https.html
测试了linux下的几种压力测试工具,发现有些不支持https,先简单总结如下:

一、apache的ab工具
/home/webadm/bin/ab -c 50 -n 10000 https://2hei.net/mt/index.html
SSL not compiled in; no https support
看样子是说SSL没有编译进来,所以不支持https


二、apache的flood工具
http://httpd.apache.org/test/flood/

wget http://www.apache.org/dist/httpd/flood/flood-0.4.tar.gz

如果要支持https的话,需要添加如下的编译参数:--with-apr --with-apr-util --enable-ssl
具体代码也可以从svn获取。
不过我在编译的时候遇到一些问题,apr-util包在make的时候总是报错!


三、web-bench工具

http://freshmeat.net/projects/web-bench/

./webbench -c 20 -t 10 https://2hei.net/mt/index.html
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Only HTTP protocol is directly supported, set --proxy for others.
明确提示了提示不支持https哦!

四、http_load工具,曾经的最爱,http测试的结果还很令人满意。
http://acme.com/software/http_load/
./http_load -rate 5 -seconds 10 urls
./http_load: unknown protocol - https://2hei.net/mt/index.html
吼吼,看来之前常用的http_load也不支持https


五、siege工具
http://www.joedog.org/index/siege-home

编译使之支持https
./configure --prefix=/home/2hei.net/siege --with-ssl=/usr/include/openssl

基本用法:
./siege
SIEGE 2.69
Usage: siege [options]
       siege [options] URL
       siege -g URL
Options:
  -V, --version           VERSION, prints version number to screen.
  -h, --help              HELP, prints this section.
  -C, --config            CONFIGURATION, show the current configuration.
  -v, --verbose           VERBOSE, prints notification to screen.
  -g, --get               GET, pull down headers from the server and display HTTP
                          transaction. Great for web application debugging.
  -c, --concurrent=NUM    CONCURRENT users, default is 10
  -u, --url="URL"         Deprecated. Set URL as the last argument.
  -i, --internet          INTERNET user simulation, hits the URLs randomly.
  -b, --benchmark         BENCHMARK, signifies no delay for time testing.
  -t, --time=NUMm         TIME based testing where "m" is the modifier S, M, or H
                          no space between NUM and "m", ex: --time=1H, one hour test.
  -r, --reps=NUM          REPS, number of times to run the test, default is 25
  -f, --file=FILE         FILE, change the configuration file to file.
  -R, --rc=FILE           RC, change the siegerc file to file.  Overrides
                          the SIEGERC environmental variable.
  -l, --log               LOG, logs the transaction to PREFIX/var/siege.log
  -m, --mark="text"       MARK, mark the log file with a string separator.
  -d, --delay=NUM         Time DELAY, random delay between 1 and num designed
                          to simulate human activity. Default value is 3
  -H, --header="text"     Add a header to request (can be many)
  -A, --user-agent="text" Sets User-Agent in request


siege -c 20 -r 2 -f url
-c 20 并发20个用户
-r 2 重复循环2次
-f url 任务列表:URL列表

结论相当凑合,纵欲找到可以支持https压力测试的工具了。


六、httperf工具,来自hp的工具,不过已经n年没有更新了。
wget ftp://ftp.hpl.hp.com/pub/httperf/httperf-0.9.0.tar.gz

        $ mkdir build
        $ cd build
        $ SRCDIR/configure
        $ make
        $ make install

工具使用方法:
/usr/local/bin/httperf --help
Usage: httperf [-hdvV] [--add-header S] [--burst-length N] [--client N/N]
        [--close-with-reset] [--debug N] [--failure-status N]
        [--help] [--hog] [--http-version S] [--max-connections N]
        [--max-piped-calls N] [--method S] [--no-host-hdr]
        [--num-calls N] [--num-conns N] [--period [d|u|e]T1[,T2]]
        [--port N] [--print-reply [header|body]] [--print-request [header|body]]
        [--rate X] [--recv-buffer N] [--retry-on-failure] [--send-buffer N]
        [--server S] [--server-name S] [--session-cookies]
        [--ssl] [--ssl-ciphers L] [--ssl-no-reuse]
        [--think-timeout X] [--timeout X] [--uri S] [--verbose] [--version]
        [--wlog y|n,file] [--wsess N,N,X] [--wsesslog N,X,file]
        [--wset N,X]
如:
/usr/local/bin/httperf --server www.2hei.net \
   --port 443 --uri /mt/index.html \
   --rate 15 --num-conn 1000 \
   --num-call 1 --timeout 5

发现会有如下错误:
httperf: warning: open file limit > FD_SETSIZE; limiting max. # of open files to FD_SETSIZE
以下是解决办法:
# Edit /etc/security/limits.conf and add the line * hard nofile 65535 (or instead of * you can put the username of the user for whom you want to change the limit)
# Edit /usr/include/bits/typesizes.h and change #define __FD_SET_SIZE 1024 to #define __FD_SET_SIZE 65535 (in /usr/include/sys/select.h FD_SETSIZE is defined as __FD_SETSIZE)
重新编译即可。

实例测试如下:
/usr/local/bin/httperf --client=0/1 --ssl --server= www.2hei.net --port=443 --uri=/mt/index.html --rate=1 --num-conns=1000 --rate=50 --num-calls=1 --hog
httperf --hog --client=0/1 --server=www.2hei.net --port=443 --uri=/mt/index.html --rate=50 --send-buffer=4096 --recv-buffer=16384 --ssl --num-conns=1000 --num-calls=1
Maximum connect burst length: 1

Total: connections 1000 requests 1000 replies 1000 test-duration 33.758 s

Connection rate: 29.6 conn/s (33.8 ms/conn, <=394 concurrent connections)
Connection time [ms]: min 73.1 avg 6513.5 max 22013.1 median 5371.5 stddev 4176.3
Connection time [ms]: connect 5670.7
Connection length [replies/conn]: 1.000

Request rate: 29.6 req/s (33.8 ms/req)
Request size [B]: 80.0

Reply rate [replies/s]: min 26.6 avg 31.3 max 33.6 stddev 2.4 (6 samples)
Reply time [ms]: response 842.7 transfer 0.0
Reply size [B]: header 331.0 content 163.0 footer 2.0 (total 496.0)
Reply status: 1xx=0 2xx=1000 3xx=0 4xx=0 5xx=0

CPU time [s]: user 9.91 system 23.11 (user 29.4% system 68.5% total 97.8%)
Net I/O: 16.6 KB/s (0.1*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





http://article.yeeyan.org/view/szhairui/59555?from=rss_related

Django 性能测试——一个现实世界的例子

译者: szhairui
发表时间:2009-09-17浏览量:10704评论数:0挑错数:0
作者通过对一个基于256MBVPS的社交网站进行优化的过程进行全程描述,为读者(特别是VPS的站长们)优化网站性能提供了大量可参考信息。

Django 性能测试——一个现实世界的例子

2008年4月28日

大约一个星期前,安德鲁 启动 一个新的 Django 打造的网站,站名叫 Hey!Wall 。这是一个按照社交网络中的“墙”的概念建立的社交网站,它为各类朋友提供了一个留言及分享照片、视频和链接的空间。

我们想对其进行性能评估,并进行一些服务器配置和代码修改来决定采取何种步骤进行改进。我们使用 httperf 进行了测试,并通过优化将其性能提高了整整一倍。

服务器和客户端

服务器一是一台 Slicehost 提供的 Xen VPS ,配有 256MB 内存,运行的是 Debian Etch 系统。部署在美国中西部。

为了测试,采用了一台位于英国的 Xtraordinary Hosting 提供的 Xen VPS,作为客户端。通常我们使用的 ADSL 访问互联网络,但这让我们很难向服务器发起足够多的访问请求。使用连接良好的 VPS 作为客户端使我们可以真正地对服务器加以考验。

服务器规格说明

很难确切地描述服务器的规格。该 VPS 配有 256MB 内存,与数个类似的 VPS 同居一台主机(大概是一台 装有 16GB 内存的 Quad Core 服务器)之上。假定装满了 256MB 切片的话,物理服务器上最多装有 64 台 VPS 。如果四个处理器都是 2.4GHz,那么共 9.6 GHz ,除以 64 得到最少 150MHz 的 CPU 。

Xen VPS 上,无需竞争你就可以获得稳定的内存和 CPU 分配,但通常 主机上任何空闲的 CPU 都将得到使用。如果在同一机器上的其它 VPS 处于空闲状态,你的 VPS 将能够使用更多的 CPU 。这也许意味着在测试期间使用了更多的 CPU ,即某些测试可能比其它的使用了更多的 CPU 资源。

使用 httperf 评估性能

现有各式各样的网络性能测试工具,主要包括 ab (来自 Apache), Flood httperf。我们使用 httperf 并没有任何特别理由。

httperf 命令看起来如下所示:

httperf --hog --server=example.com --uri=/ --timeout=10 --num-conns=200 --rate=5

在该例中,我们向 http://example.com/ 发起了 200 次访问请求,每秒最多 5 次。

测试计划

某些工具支持进程,可以模仿用户对网站提交任务。我们使用了一种简单的“暴力”测试来了解该站点每秒能够处理多少请求。

该基本方法是发起一定数量的请求,能够判断服务器如何反应:状态 200 为成功,状态 500 为失败。提高频率(每秒制造的请求数量)然后再试一遍。如果开始返回大量的 500 ,则已经达到极限。

监测服务器资源

另一个方面是要掌握服务器在内存和 CPU 使用方面的情况。要跟踪这一情况,我们运行 top 并将输出记录为日志文件以供稍后查阅。该 top 命令如下所示:

top -b -d 3 -U www-data > top.txt

在该例中,我们以用户 www-data 每三秒记录一次进程的日志信息。如果你想更加明确的指定目标,可以使用 -p 1, 2, 3 ,而不是 -U username ,其中 1、2 和 3 是 pid(即要观测进程的进程ID)。

网页服务器为配有以 FastCGI processes 方式运行的 Python 2.5 的 Lighttpd 。尽管数据库的日志也是很有用的信息,但我们没有记录该进程(PostgreSQL)的日志。

另一个有用的工具是 vmstat,特别是 swap 列显示了有多少内存进行了交换。交换的意思是你没有足够的内存,它是一种性能杀手。要想反复运行 vmstat 的话,必须指定每次检查间隔的秒数。如:

vmstat 2
使用 httperf 进行已认证访问

httperf 只是简单地向某个 URL 发出简单的 GET 请求,并下载 html 文本(但不包括任何媒体文件)。对公共/匿名(public/anonymous)网页发起的访问请求是件轻松的事情,但如果要访问需要登录的页面怎么办呢?

httperf 可以传递请求头部信息。Django 身份校验( authentication)(由 django.contrib.auth 提供)使用的进程依赖于在客户端 cookie 中所保存的进程 id 。而客户端在请求的头部信息中传递 cookie 。你可以看到这一切是如何进行的。

登录站点,查看 cookies 信息。其中应该有个类似 sessionid=97d674a05b2614e98411553b28f909de 的数值。要通过 httperf 传递该 cookie,可以使用 --add-header 参数选项。如:

httperf ... --add-header='Cookie: sessionid=97d674a05b2614e98411553b28f909den'

小心头部信息之后的 n 。如果少了该字符,你的每个请求可能都会返回超时信息。

测试哪个页面?

考虑到这一点,我们测试了网站的两个网页:

  1. 主页: 对主页的匿名访问
  2. “墙”: 对某个“墙”已认证访问,该网页包括从数据库获取的内容

事实静态与高度动态

对于匿名用户来说,主页基本上是静态的,它只是简单的渲染某个模板而无需数据库的任何数据。

“墙”页面则非常动态,包括了从数据库获取的主要数据。该模板在被渲染时,针对不同时区用户的日期设置“删除”了指向某些物件的链接,等等。某些“墙”包含了大约50个物件,在被优化前,大约要发起 80 条数据库查询。

第一次测试时,我们运行了两个可以从 Django 接受请求 FastCGI 后端。

Home: 175 req/s (即每秒请求数量)Wall: 8 req/s.

经压缩的内容

第一个配置优化是使用 GZipMiddleware 激活输出的 gzip 压缩。性能轻微提高,没有大的变化。但无论如何为了节约带宽,这么做还是值得的。

Home: 200 req/s.
Wall: 8 req/s.

更多进程,更短的队列

然后,我们将 FastCGI 后端的数量从 2 个提升到 5 个。这项改进减少了 500 响应的数量,因为更多的请求可以由额外的后端来处理。

Home: 200 req/s.
Wall: 11 req/s.

更多的进程,更多的问题

从 2 到 5 的改进非常不错,因此我们决定将 FastCGI 后端数量提升到 10 。性能却显著地 下降 了。

经查看服务器上的 vmstat ,可以看到原因是出现了内存交换。太多的进程,每个都为 Python 使用了内存,导致 VPS 内存耗尽,从而不得不从硬盘往返交换内存。

Home: 150 req/s.
Wall: 7 req/s.

基于此,我们将 FastCGI 后端数量降回 5 以进行更多测试。

分析——时间耗到哪里去了

“墙”页面的性能令人失望,因此我们开始进行优化。我们所做第一件事情是分析代码以确定时间都被花费在何处。

使用一些简单的 分析中间件 之后,很清楚地发现时间被消耗在数据库查询之上。“墙”页面包括许多查询,且数量与其所包含的物件数量呈正比。测试墙页面上引发了大约 80 个查询。毫无疑问其性能是糟糕的。

进行优化

通过优化物件附加媒体的处理方式,我们直接给每个物件剔除了一次查询。该措施稍微地减少了请求所需时间,因此也提高了每秒可处理的查询数量。

Wall: 12 req/s.

导致低效的另一个原因是无论页面是否被请求,对每个物件的内容都应用了多个过滤器(Filter)。经我们修改,被过滤内容的 HTML 输出都被存储在物件当中,节约了页面被查阅时的需要进程。这又带来一点小小改进。

Wall: 13 req/s.

通过减少数据库查询,我们以修改用户配置文件(用于显示是谁将该物件粘贴到墙上)的获取方式为每个物件剔除了一次查询。这次修改又提高了不少。

Wall: 15 req/s.

这场测试的最后一次优化目标是减少获取物件所附加媒体的查询数量。我们再一次削减了一些查询,稍微地提高了性能。

Wall: 17 req/s.

下一步:缓存

在尽可能地减少查询之后,接下来要进行一些缓冲工作。获取缓存数据通常比查询数据库更加快捷,因此我们期待性能有一个显著提升。

对整个页面的输出进行缓存是没有意义的,因为每个页面根据发出请求的用户不同而截然不同。只有当用户对同一页面的两次请求之间,情况没有发生任何变化,才可能出现缓存命中。

对墙、物件及用户的列表进行缓存的作用更大。被缓存的数据将被用于从同一用户发出的多个请求,及在对于墙壁的不同程度和不同用户访问之间共享。这未必是巨大的胜利,因为每个“墙”很可能只有极少数的用户,而数据必须在高速缓存中停留足够长的时间以被别人获取。

在这种情况下,我们简化的 httperf 测试将会被极大地误导。每个请求都由同一用户发出,因此缓存命中几乎是100%,而性能将因此极高!这反映不出真实世界的站点使用情况,因此我们最好进行一些更好的测试。

目前我们还没有使用缓存,因为站点可以轻松地应对的当前活动水平,但一旦 Hey! Wall 流行起来,这将是我们的下一个步骤。

多少用户能够导致每秒17次请求?

提供每秒 17 次请求相应看起来仍然非常少,但将该数据翻译成站点的实际用户量是非常有趣的事情。显然,这数据不包括提供像图片、CSS 和 JavaScript 文件之类的媒体文件服务。相对来说,媒体文件个头要大一些,但它们直接由 Lighttpd (而不是 Django)处理,并提供了 Expires 头部信息来允许客户端对它们进行缓存。不过,为了在测试中更好地进行评估,我们还是需要对服务器进行一些处理。

现在说采用何种通用模式还为时过早,因此我说的只能是猜测。请允许我这么说!

我将假定每个用户平均访问三个“墙”,并按顺序查看它们的内容,暂停10至20秒时间以阅读新的评论,或查看一些照片和打开一些链接。该用户每天进行三次这种操作。

只看墙页面,不看媒体的话,用户将每天对墙页面发起 9 次访问请求。每个用户一次只能发起一次访问请求,因此在时间上,任何一秒内 17 个用户可以同时进行该操作。一分钟内,用户只发出3次访问请求,因此17个并发用户只用去了60 秒中的 3 秒(或20秒中的1秒)。

如果一段时间内用户的请求分布是完全平衡的(提示:不可能的!),那也就意味着每分钟可以有 340 用户(17 * 20)访问该网站。延续这个不真实的例子,我们可以说每天有 1440 分钟,而每个用户每天访问网站 3 分钟,因此该网站可以应对大约 163,000 个用户。这对于一个每月 20 美元的 VPS 来说已经非常棒了!

为了更多统计一下这些数字,让我们假定每天6小时内,我们每分钟应对 200 个并发用户,另 6 个小时内(每分钟)应对 100 个并发用户,剩下的 12 小时内(每分钟)应对 10 个并发用户。基于每秒 17 次请求的最大负荷,网站每天仍然可以应对的大约 115,000 个用户。

我确信这些数字并不虚假和荒谬。如果有人在评论中提出更好的评估方案或者真实世界的数据,我将非常感兴趣。

我们学到了什么?

概括:

  1. 测试网站性能可能会产生令人惊异的结果
  2. 过多的数据库查询对性能(duh)来说不是件好事
  3. 对站点的某类内容进行缓存比对其他一些更好
  4. 一台廉价的 VPS 所能应对的用户数量比你所想像的要多得多


服务器压力测试:ab和gnuplot

日志

1.安装相关工具

yum install -y httpd httpd-tools gnuplot

2. 使用ab进行测试:


$ab -c 10 -n 50 -k -g /data/www/bench1.tsv http://www.zrwm.com/
$ab -c 10 -n 50 -k -g /data/www/bench2.tsv http://www.zrwm.com/
$ab -c 10 -n 50 -k -g /data/www/bench3.tsv http://www.zrwm.com/

ab命令参数说明:
-c: number of concurrent users/seconds
-n: number of requests/user/seconds
-k: Keepalived supported

生成的TSV文件,头部的几个列说明:
ctime: Connection Time
dtime: Processing Time
ttime: Total Time
wait: Waiting Time

3.基于这些tsv文件,使用gnuplot生成png格式图表

$ cd /data/www
$ gnuplot
gnuplot> set terminal png
Terminal type set to 'png'
gnuplot> set output "benchmark.png"
gnuplot> set title "Benchmark for www.zrwm.com"
gnuplot> set size 1,1
gnuplot> set grid y
gnuplot> set xlabel 'Request'
gnuplot> set ylabel 'Response Time (ms)'
gnuplot> plot "bench1.tsv" using 10 smooth sbezier with lines title "Benchmark 1:", "bench2.tsv" using 10 smooth sbezier with lines title "Benchmark 2:", "bench3.tsv" using 10 smooth sbezier with lines title "Benchmark 3:"
gnuplot> exit

benchmark

我们可以将第3步的gnuplot代码部分做成模板benchmark.tpl,以简化生成图表的过程:


# output as png image
set terminal png

# save file to "benchmark.png"
set output "benchmark.png"

# graph title
set title "Benchmark for blog.secaserver.com"

# aspect ratio for image size
set size 1,1

# enable grid on y-axis
set grid y

# x-axis label
set xlabel "Request"

# y-axis label
set ylabel "Response Time (ms)"

# plot data from bench1.tsv,bench2.tsv and bench3.tsv using column 10 with smooth sbezier lines
plot "bench1.tsv" using 10 smooth sbezier with lines title "Benchmark 1:", \
"bench2.tsv" using 10 smooth sbezier with lines title "Benchmark 2:", \
"bench3.tsv" using 10 smooth sbezier with lines title "Benchmark 3:"

下次在ab测试后,运行:
$gnuplot benchmark.tpl

Posted on 2013 年 2 月 2 日 by Jose

web服务器压力测试工具- httperf + autobench + gnuplot

1. httperf安装
wget ftp://ftp.hpl.hp.com/pub/httperf/httperf-0.9.0.tar.gz
tar zxvf httperf-0.9.0.tar.gz
cd httperf-0.9.0
./configure –prefix=/usr/local/httperf
make && make install

httpref是通过命令行来调用。它有如下参数
httperf –help
Usage: httperf [-hdvV] [--add-header S] [--burst-length N] [--client N/N]
[--close-with-reset] [--debug N] [--failure-status N]
[--help] [--hog] [--http-version S] [--max-connections N]
[--max-piped-calls N] [--method S] [--no-host-hdr]
[--num-calls N] [--num-conns N] [--period [d|u|e]T1[,T2]]
[--port N] [--print-reply [header|body]] [--print-request [header|body]]
[--rate X] [--recv-buffer N] [--retry-on-failure] [--send-buffer N]
[--server S] [--server-name S] [--session-cookies]
[--ssl] [--ssl-ciphers L] [--ssl-no-reuse]
[--think-timeout X] [--timeout X] [--uri S] [--verbose] [--version]
[--wlog y|n,file] [--wsess N,N,X] [--wsesslog N,X,file]
[--wset N,X]

其中常用的参数的含义
–server S web服务器地址
–num-conns N 测试联接数
–num-calls N 每连接中发起联接数,一般是1
–rate N 每秒请求数
–port N 测试端口
−−method S 测试HTTP方法,默认为GET
–uri S 测试网页,默认为/
–timeout N 等待服务器响应时间

使用实例:
httperf –server www.zrwm.com –port 80 –num-conns 200 –timeout 5 –uri /10k

每次设置参数来测试有点麻烦,使用autobench结合httperf来测试就会方便很多。autobench是perl脚本写的自动测试工具,它调用httperf来测试.

2.autobench安装
wget http://www.xenoclast.org/autobench/downloads/autobench-2.1.2.tar.gz
tar zxvf autobench-2.1.2.tar.gz
cd autobench-2.1.2

单机使用实例:
autobench –single_host –host1 www.zrwm.com –uri1 /10k –port1 80 –quiet –low_rate 20 –high_rate 200 –rate_step 20 –num_call 1 –num_conn 500 –timeout 5 –file results.tsv

双机实例:
autobench –host1=v1.zrwm.com –port1=8001 –host2=v2.zrwm.com –port2=80 –uri1=/ –uri2=/a.php –quiet –low_rate=500 –high_rate=5000 –rate_step=100 –num_call=1 –num_conn=10000 –timeout=10 –file result.tsv

参数含义
–single_host 只测单机
–host1 测试主机地址
–uri1 host1 测试URI
–quiet 安静模式
–low_rate 测试时最低请求数(指 httperf)
–hight_rate 测试时最高请求数
–rate_step 每次测试请求数增加步长
–num-call 同httperf
–num_conn 同httperf
–file 测试结果输出的 tsv文件

3.gnuplot安装(安装之前,请先安装好gd库)
wget http://nchc.dl.sourceforge.net/sourceforge/gnuplot/gnuplot-4.6.0.tar.gz
tar zxvf gnuplot-4.6.0.tar.gz
cd gnuplot-4.6.0
./configure –prefix=/usr/local/gnuplot –with-gd=/usr/local/gd2/
make && make install

注:如果make的时候出现undefined reference to `libiconv’的类似错误,
可以直接执行:export LIBS=”-liconv”
然后再次configure后,重新进行编译安装make && make install

vi /etc/profile
#将/usr/local/gnuplot/bin:/usr/local/httperf/bin 添加到PATH中
export PATH=/usr/local/bin:/usr/local/gnuplot/bin:/usr/local/httperf/bin:$PATH
source /etc/profile

修改 bench2graph

cp /usr/local/bin/bench2graph /usr/local/bin/bench2png
vi /usr/local/bin/bench2png
将72行的echo set terminal postscript color > gnuplot.cmd
修改为echo set terminal png large size 640,480 truecolor > gnuplot.cmd

将77行的 set data style
修改为 set style data

生成PNG图像:
bench2png results.tsv results.png

参考:

http://www.xenoclast.org/autobench/

http://www.gnuplot.info/

Posted in Benchmark, Web Traffic Benchmark.

web压力测试工具-Siege

As a website owner your website performance is crucial to your business. You would expect your website to be able to cope with thousands of visits per minute but unless you’ve prepared for it by purchasing quality hosting services and tuning the servers there is a good change that your website won’t cope with a lot of traffic and in a lot of cases can lead to a loss of revenue. Tuning your web servers to handle more traffic without crashing is a science of its own and there are many ways to improve performance but before you dive in and start tweaking your Apache or MySQL configurations you need some way of measuring the website performance improvements you make. There are many tools available for speed testing your website and they all have their merits. One tool that is easy to use is Siege (Website).

Siege is a command line program that helps measure the speed of your website and provides a summary of the performance which you can use to measure the changes on your web servers.

Installing Siege on Ubuntu (and derivatives)

Siege is part of the standard ubuntu packages, so you should install it in the standard way:

sudo apt-get install siege

Additionally, you can download, compile and install the latest version of Siege. Use the steps below.

Installing Siege on Mac OSX

As far as I am aware there isn’t a package version of Siege for OSX so you can either download,compile and install Siege manually or use Homebrew to install.

Manually compile and install

Do the following to download, compile and install Siege on your OSX.

$ curl http://www.joedog.org/pub/siege/siege-latest.tar.gz -o siege-latest.tar.gz
$ tar xvfz siege-latest.tar.gz
$ cd siege-2.72
$ ./configure
$ make
$ make install

This will install Seige to /usr/local/bin/siege.

Installation via Homebrew

First, install homebrew using the instructions fromhttps://github.com/mxcl/homebrew/wiki/installation. Once installed you can simply install Siege in one command:

$ brew install siege

Using Siege

Now that Siege is installed we can begin speed testing your website. First thing to do is to create the siege config file in your home directory.

~ $ siege.config 
New configuration template added to /home/andrew/.siegerc
Run siege -C to view the current settings in that file

We’ll run our first test shortly but first a word of warning!. Siege is a powerful tool and can quite easily bring your web servers down if used incorrectly! I recommend you test this on your own websites and not those of a third party.

OK, lets run our first test. We’ll test the homepage of our site by simulating 10 users with a delay of up to 10 seconds between requests.

~ $ siege -c10 -d10 -r1 -v http://www.mywebsite.com/
** SIEGE 2.72
** Preparing 10 concurrent users for battle.
The server is now under siege...
HTTP/1.1 200   0.12 secs:    4123 bytes ==> /
HTTP/1.1 200   0.11 secs:    4123 bytes ==> /
HTTP/1.1 200   0.11 secs:    4123 bytes ==> /
HTTP/1.1 200   0.12 secs:    4123 bytes ==> /
HTTP/1.1 200   0.11 secs:    4123 bytes ==> /
HTTP/1.1 200   0.13 secs:    4123 bytes ==> /
HTTP/1.1 200   0.11 secs:    4123 bytes ==> /
HTTP/1.1 200   0.11 secs:    4123 bytes ==> /
HTTP/1.1 200   0.12 secs:    4123 bytes ==> /
HTTP/1.1 200   0.11 secs:    4123 bytes ==> /
done.

Transactions:		          10 hits
Availability:		      100.00 %
Elapsed time:		        8.12 secs
Data transferred:	        0.04 MB
Response time:		        0.11 secs
Transaction rate:	        1.23 trans/sec
Throughput:		        0.00 MB/sec
Concurrency:		        0.14
Successful transactions:          10
Failed transactions:	           0
Longest transaction:	        0.13
Shortest transaction:	        0.11

Let’s break this down a little. First we entered the siege command with a number of parameters:

  • -c10 is the number of concurrent users we want to simulate.
  • -r1 is the number of repetitions, in this case, 1.
  • -d10 is the delay between each user request (each siege simulated users sleeps for a random interval in seconds between 0 and 10).
  • -v is to show the output of each request.
  • Finally the url to test. My tests were run on a bona fide website but I have changed the domain name in my examples.

Once you hit enter Siege will run and output it’s results. The first set of results shows each request. This shows the HTTP method, the returned HTTP result code (200 is good :) ), the time taken in seconds, the number of bytes retreived and finally the URL requested. You can edit your ~/.siegerc to show the full URL if you need to.

After the requests have completed Siege will show you a summary report. This report is documented in the siege man page, which I have reproduced below:

Transactions
The number of server hits. In the example, 25 simulated users [ -c25 ] each hit the server 10 times [ -r10 ], a total of 250 transactions. It is possible for the number of transactions to exceed the number of hits that were scheduled. Siege counts every server hit a transaction, which means redirections and authentication challenges count as two hits, not one. With this regard, siege follows the HTTP specification and it mimics browser behavior.

Availability
This is the percentage of socket connections successfully handled by the server. It is the result of socket failures (including timeouts) divided by the sum of all connection attempts. This number does not include 400 and 500 level server errors which are recorded in “Failed transactions” described below.

Elapsed time
The duration of the entire siege test. This is measured from the time the user invokes siege until the last simulated user completes its transactions. Shown above, the test took 14.67 seconds to complete.

Data transferred
The sum of data transferred to every siege simulated user. It includes the header information as well as content. Because it includes header information, the number reported by siege will be larger then the number reported by the server. In internet mode, which hits random URLs in a configuration file, this number is expected to vary from run to run.

Response time
The average time it took to respond to each simulated user’s requests.

Transaction rate
The average number of transactions the server was able to handle per second, in a nutshell: transactions divided by elapsed time.

Throughput
The average number of bytes transferred every second from the server to all the simulated users.

Concurrency
The average number of simultaneous connections, a number which rises as server performance decreases.

Successful transactions
The number of times the server responded with a return code < 400.

Failed transactions
The number of times the server responded with a return code >= 400 plus the sum of all failed socket transactions which includes socket timeouts.

Longest transaction
The greatest amount of time that any single transaction took, out of all transactions.

Shortest transaction
The smallest amount of time that any single transaction took, out of all transactions.

 Speed testing more than one url

If you need to test more than one URL then you will need to tell Siege to use a file to load the URL’s from. Simply create a text file called urls.txt and add each URL you want to test on a separate line.

$ vim urls.txt

http://www.mywebsite.com/about-us/


http://www.mywebsite.com/contact-us/

To tell Siege to use your urls.txt you need to use the -f parameter.

siege -v -c10 --reps=once -d5 -f urls.txt 
** SIEGE 2.72
** Preparing 10 concurrent users for battle.
The server is now under siege...
HTTP/1.1 200   0.61 secs:    7817 bytes ==> /about-us/
HTTP/1.1 200   0.66 secs:    7821 bytes ==> /about-us/
HTTP/1.1 200   0.67 secs:    7821 bytes ==> /about-us/
HTTP/1.1 200   0.67 secs:    7821 bytes ==> /about-us/
HTTP/1.1 200   0.72 secs:    7818 bytes ==> /about-us/
HTTP/1.1 200   0.74 secs:    7821 bytes ==> /about-us/
HTTP/1.1 200   0.78 secs:    7821 bytes ==> /about-us/
HTTP/1.1 200   0.60 secs:    8050 bytes ==> /contact-us/
HTTP/1.1 200   0.60 secs:    8050 bytes ==> /contact-us/
HTTP/1.1 200   0.63 secs:    7821 bytes ==> /about-us/
HTTP/1.1 200   0.68 secs:    7819 bytes ==> /about-us/
HTTP/1.1 200   0.69 secs:    7821 bytes ==> /about-us/
HTTP/1.1 200   0.61 secs:    8052 bytes ==> /contact-us/
HTTP/1.1 200   0.60 secs:    8046 bytes ==> /contact-us/
HTTP/1.1 200   0.61 secs:    8043 bytes ==> /contact-us/
HTTP/1.1 200   0.62 secs:    8051 bytes ==> /contact-us/
HTTP/1.1 200   0.60 secs:    8044 bytes ==> /contact-us/
HTTP/1.1 200   0.61 secs:    8052 bytes ==> /contact-us/
HTTP/1.1 200   0.65 secs:    8051 bytes ==> /contact-us/
HTTP/1.1 200   0.62 secs:    8051 bytes ==> /contact-us/
done.

Transactions:		          20 hits
Availability:		      100.00 %
Elapsed time:		        9.32 secs
Data transferred:	        0.15 MB
Response time:		        0.65 secs
Transaction rate:	        2.15 trans/sec
Throughput:		        0.02 MB/sec
Concurrency:		        1.39
Successful transactions:          20
Failed transactions:	           0
Longest transaction:	        0.78
Shortest transaction:	        0.60

As you can see, Siege has requested both URL’s from the file at random intervals.

Speed testing a web page with all it’s assets (JavaScript,CSS, Images etc)

Everything we have done so far has been testing single html files which is useful for testing page generation. But what if we need to find out the speed of a whole web page including all the images, javascript, css files, video etc? Simple, you put all the URL’s of all the webpage assets into the urls.txt file. However, doing this by hand can be quite painful. Fortunately we can use a proxy tool to create the URL’s for us.

Introducing sproxy

The author of Siege, Jeffrey Fulmer (see the siege websute) has also written a companion program to Siege called ‘sproxy’. Quite simple, sproxy logs all urls to a text file for use with Siege. To do this you need to tell your web browser to connect to the proxy and then simply load your webpage.

Installing sproxy on Ubuntu (and derivatives)

Unlike Siege, sproxy doesn’t appear to be packaged for Ubuntu, so we need to compile and install it.

$ curl http://www.joedog.org/pub/sproxy/sproxy-latest.tar.gz -o sproxy-latest.tar.gz
$ tar xvfz sproxy-latest.tar.gz
$ cd sproxy-1.02/
$ ./configure
$ make
$ sudo make install

Once sproxy is installed you should configure your browser to use the proxy. In Firefox, go to Preferences > Advanced > Network and click the ‘settings’ button. Then select ‘Manual Proxy Configuration’ and enter ’127.0.0.1′ in the ‘HTTP Proxy:’ field, and ’9001′ in the Port Field. Once you have done this, click ‘OK’ and close your Preferences dialog.
[screenie]

Go to your terminal and launch sproxy. By default it will bind to the localhost and use port 9001. Now go to your browser and load a single page on your website. When it has finished loading, go back to your terminal and quit sproxy using CTRL-C.

andrew@andrew-laptop ~ $ sproxy
SPROXY v1.02 listening on port 9001
...appending HTTP requests to: /home/andrew/urls.txt
...default connection timeout: 120 seconds
^C
andrew@andrew-laptop ~ $

Now view your urls.txt file and you should see the URL’s of all images,css and javascript (and any other assets) that your web page contains. Check the file through and remove any URL’s you don’t want to test such as Google Analytics.

Once you’ve cleaned your urls.txt file you can then siege it as we did previously. This time we’ll simulate one user making one request of the whole web page, assets and all.

siege  -c1 --reps=once -f urls.txt 
** SIEGE 2.72
** Preparing 1 concurrent users for battle.
The server is now under siege..      done.

Transactions:		          38 hits
Availability:		      100.00 %
Elapsed time:		       26.23 secs
Data transferred:	        0.38 MB
Response time:		        0.19 secs
Transaction rate:	        1.45 trans/sec
Throughput:		        0.01 MB/sec
Concurrency:		        0.27
Successful transactions:          38
Failed transactions:	           0
Longest transaction:	        0.62
Shortest transaction:	        0.10

Simulate Browser Caching

Siege, by default, requests each URL from the server regardless of any expiry headers sent by the server. This allows us to simulate a page load with an empty cache but we can also configure Siege to request the URLs and respect any expires headers that are sent. To do this, open your ~/.siegerc file in your text editor and find the Cache revalidation section (around line 101 in my file). Simply change the line to ‘cache = true’, save it and re-run your test, this time with the -v flag.


  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值