httperf Web服务器性能测试

时间:2020-03-21 11:48:13  来源:igfitidea点击:

在本地Intranet中部署Web服务器非常容易且快速。
可以在数分钟内部署高度使用的Apache Web服务器。
但是,为Intranet部署Web服务器和为高流量Internet部署Web服务器有很大的不同。

为高流量生产部署Apache或者任何其他Web服务器,需要做出一些决定,例如我们要使用MPM预叉还是工作器,每个进程使用的内存,保持运行时间,缓存,负载平衡等。

但是首先,为了得出结论并确认Web服务器的性能,管理员需要执行一些测试。
市场上有多种工具可以进行此类测试,这些工具称为性能/基准测试工具。
我们在这篇文章中感兴趣的主题是一种称为“ httperf”的工具。

httperf简介

惠普的David Mosberger创建了httperf,用于对Web服务器进行性能基准测试。

该工具可用于在服务器上创建特定的工作负载以测试其性能。
我们可以测量Web服务器在满负荷运行时的响应率。

httperf在C中实现,以保持其较高的性能。
它通过保持对基本操作系统的依赖程度较低的想法而实现的。

我们将在具有以下配置的虚拟机上测试此工具,它同时支持HTTP版本:1.0和HTTP版本:1.1

内存:512MB

型号名称:Intel(R)CoreTM i5-2520M CPU @ 2.50GHz
中央处理器MHz:2493.706
缓存大小:3072 KB

服务器版本:Apache/2.2.22(Unix)

让我们通过查看httperf的一些示例用法来开始我们的Web服务器性能测试。

[root@myvm1 ~]# httperf --hog --server 192.168.159.128
httperf --hog --client=0/1 --server=192.168.159.128 --port=80 --uri=/--send-buffer=4096 --recv-buffer=16384 --num-conns=1 --num-calls=1
Maximum connect burst length: 0
Total: connections 1 requests 1 replies 1 test-duration 0.006 s
Connection rate: 168.1 conn/s (6.0 ms/conn, <=1 concurrent connections)
Connection time [ms]: min 6.0 avg 6.0 max 6.0 median 5.5 stddev 0.0
Connection time [ms]: connect 0.6
Connection length [replies/conn]: 1.000
Request rate: 168.1 req/s (6.0 ms/req)
Request size [B]: 68.0
Reply rate [replies/s]: min 0.0 avg 0.0 max 0.0 stddev 0.0 (0 samples)
Reply time [ms]: response 5.3 transfer 0.1
Reply size [B]: header 197.0 content 8105.0 footer 2.0 (total 8304.0)
Reply status: 1xx=0 2xx=1 3xx=0 4xx=0 5xx=0
CPU time [s]: user 0.00 system 0.00 (user 0.0% system 16.8% total 16.8%)
Net I/O: 1373.7 KB/s (11.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

让我们看看输出的每个部分在说什么。
这将有助于我们了解进一步测试的结果。

总计:本节介绍已启动的TCP连接的数量。
在我们的例子中,httperf仅启动了一个连接。

连接速率:以每秒连接数的形式告诉输入连接速度。
并且还告诉我们同时或者一次启动的连接是什么。

连接时间:这显示TCP连接的生存期。
这意味着连接启动和连接关闭之间的时间。

连接时间:如果启动了多个连接,则此第二连接时间部分指示平均连接时间。

连接长度:这表明每个连接获得的平均答复数。

请求速率:这显示httperf发出http请求的请求速率。

请求大小:这显示请求大小(以字节为单位)。

回复速率:告诉服务器回复请求的速率。

回复时间:这显示了Web服务器响应请求所花费的时间,以及接收此回复所花费的时间。

回复大小:这类似于请求大小。
这显示了答复大小(以字节为单位)。

回复状态:这显示了HTTPerf从服务器获得的回复的状态代码。

这两个部分的其余部分是关于客户端在执行测试时所花费的CPU和资源以及测试期间遇到的错误的信息。
请注意,我们上面看到的大多数输出部分仅在同时执行多个请求时才有用,这是我们现在要做的。

注意:当从多个客户端对服务器调用httperf时,我们将获得更好的测试结果,以便该服务器以其最大容量开始工作。

让我们继续进行一些更高的测试,如下所示。

[root@myvm1 html]# httperf --server 192.168.159.128 --port 80 --uri /index.php --rate 600 --num-conn 20000 --num-call 1 --timeout 5
httperf --timeout=5 --client=0/1 --server=192.168.159.128 --port=80 --uri=/index.php --rate=600 --send-buffer=4096 --recv-buffer=16384 --num-conns=20000 --num-calls=1
Maximum connect burst length: 283
Total: connections 16562 requests 15447 replies 13300 test-duration 38.218 s
Connection rate: 433.4 conn/s (2.3 ms/conn, <=1022 concurrent connections)
Connection time [ms]: min 1.3 avg 1015.3 max 8140.0 median 388.5 stddev 1394.7
Connection time [ms]: connect 501.1
Connection length [replies/conn]: 1.000
Request rate: 404.2 req/s (2.5 ms/req)
Request size [B]: 77.0
Reply rate [replies/s]: min 179.8 avg 371.9 max 510.5 stddev 110.2 (7 samples)
Reply time [ms]: response 524.9 transfer 22.6
Reply size [B]: header 197.0 content 8105.0 footer 2.0 (total 8304.0)
Reply status: 1xx=0 2xx=13300 3xx=0 4xx=0 5xx=0
CPU time [s]: user 0.77 system 15.92 (user 2.0% system 41.7% total 43.7%)
Net I/O: 2851.8 KB/s (23.4*10^6 bps)
Errors: total 6700 client-timo 3262 socket-timo 0 connrefused 0 connreset 0
Errors: fd-unavail 3438 addrunavail 0 ftab-full 0 other 0

在上面的测试中,我们为测试使用了一些不同的参数。

--uri(统一资源标识符)指定获取请求文件或者要从服务器获取的文件。
在上面的测试中,我们重复获取index.php文件

--server指定从中获取http数据的服务器地址。

--port指定Web服务器的端口。

--rate指定每秒的请求数。
在我们的情况下,每秒600个请求。

--num-connections指定要建立的tcp连接数。
在上述方法中,我们以每秒600个http请求的速率建立了2万个连接

--num-call,并且在每个连接上都会进行http调用。
调用是针对http请求及其回复。

--timeout指定客户端等待回复的时间。

服务器饱和后,可以增加来自不同客户端的请求量,以分析Web服务器的性能。

[root@myvm1 ~]# httperf --server 192.168.159.128 --port 80 --uri /index.php --rate 800 --num-conn 30000 --num-call 1 --timeout 5
httperf --timeout=5 --client=0/1 --server=192.168.159.128 --port=80 --uri=/index.php --rate=800 --send-buffer=4096 --recv-buffer=16384 --num-conns=30000 --num-calls=1
Maximum connect burst length: 1536
Total: connections 16159 requests 15102 replies 11219 test-duration 45.462 s
Connection rate: 355.4 conn/s (2.8 ms/conn, <=1022 concurrent connections)
Connection time [ms]: min 96.3 avg 994.8 max 8186.8 median 324.5 stddev 1418.9
Connection time [ms]: connect 541.0
Connection length [replies/conn]: 1.000
Request rate: 332.2 req/s (3.0 ms/req)
Request size [B]: 77.0
Reply rate [replies/s]: min 8.6 avg 248.2 max 496.5 stddev 161.9 (9 samples)
Reply time [ms]: response 567.6 transfer 20.0
Reply size [B]: header 197.0 content 8105.0 footer 2.0 (total 8304.0)
Reply status: 1xx=0 2xx=11219 3xx=0 4xx=0 5xx=0
CPU time [s]: user 1.02 system 16.14 (user 2.2% system 35.5% total 37.7%)
Net I/O: 2025.7 KB/s (16.6*10^6 bps)
Errors: total 18781 client-timo 4940 socket-timo 0 connrefused 0 connreset 0
Errors: fd-unavail 13841 addrunavail 0 ftab-full 0 other 0

如我们所见,随着我们增加连接速率和tcp连接的数量,答复速率,timout的错误计数也在不断增加。

在测试过程中,我们可以分析一次生成的http进程数。