HTTP服务器压力测试

HearyHTTPd进行压力测试。网上的压力测试工具很多,我测试了Apache benchmarkWebBench两款压力测试工具,并在台式机和实验室计算服务器上分别进行了压力测试,QPS分别约6400+、21000+和30000+。

HTTP服务器压力测试

1 Apache benchmark

1.1 简介

Apache benchmark

ab - Apache HTTP server benchmarking tool

ab is a tool for benchmarking your Apache Hypertext Transfer Protocol (HTTP) server. It is designed to give you an impression of how your current Apache installation performs. This especially shows you how many requests per second your Apache installation is capable of serving.

Apache benchmark是一款Apache提供的HTTP服务器压力测试工具,随Apache安装。

1.2 安装

1
sudo apt install apache2-utils

1.3 测试

我测试了我的HearyHTTPd,用1000个客户机并发请求10万次。

在我的实验室台式机上进行了测试:

  • CPU:Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
  • 内存:单通道 8GB DDR4 2400Mhz
  • 通过WSL中的Ubuntu来测试Windows环境JRE下运行的hhttpd。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
jyshen@JYSHEN-WORKPC:~$ ab -n 100000 -c 1000 http://localhost:8080/
This is ApacheBench, Version 2.3 <$Revision: 1807734 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:
Server Hostname: localhost
Server Port: 8080

Document Path: /
Document Length: 0 bytes

Concurrency Level: 1000
Time taken for tests: 15.595 seconds
Complete requests: 100000
Failed requests: 0
Total transferred: 1300000 bytes
HTML transferred: 0 bytes
Requests per second: 6412.45 [#/sec] (mean)
Time per request: 155.947 [ms] (mean)
Time per request: 0.156 [ms] (mean, across all concurrent requests)
Transfer rate: 81.41 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 33 78 20.6 78 143
Processing: 29 77 20.8 77 147
Waiting: 4 45 16.8 41 146
Total: 72 155 7.7 154 195

Percentage of the requests served within a certain time (ms)
50% 154
66% 155
75% 156
80% 156
90% 163
95% 169
98% 173
99% 184
100% 195 (longest request)
  • 测得结果平均每秒能处理6412个请求。
  • 多次测试能稳定在6000以上。
  • 测试中观察内存和CPU消耗无异常情况。
  • 其他影响因素:实验过程中,Windows Defender的Antimalware Service Executable进程的CPU使用率明显上升,约7~10%。

另外,我在实验室的新服务器上进行了测试:

  • CPU:2颗Intel(R) Xeon(R) Gold 6132 CPU @ 2.60GHz
  • 内存:512G(16根32G) ECC DDR4 2666Mhz
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
(base) sjy@h3c-UniServer-R5200-G3:~$ ab -n 100000 -c 1000 http://localhost:8080/
This is ApacheBench, Version 2.3 <$Revision: 1807734 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:
Server Hostname: localhost
Server Port: 8080

Document Path: /
Document Length: 0 bytes

Concurrency Level: 1000
Time taken for tests: 4.753 seconds
Complete requests: 100000
Failed requests: 0
Total transferred: 1300000 bytes
HTML transferred: 0 bytes
Requests per second: 21041.56 [#/sec] (mean)
Time per request: 47.525 [ms] (mean)
Time per request: 0.048 [ms] (mean, across all concurrent requests)
Transfer rate: 267.13 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 7 24 63.7 20 1052
Processing: 6 23 6.1 24 49
Waiting: 5 17 5.1 16 44
Total: 21 47 64.3 46 1084

Percentage of the requests served within a certain time (ms)
50% 46
66% 47
75% 48
80% 49
90% 51
95% 53
98% 56
99% 62
100% 1084 (longest request)
  • 测得结果平均每秒能处理21041个请求。

我还在另一台计算服务器上进行了测试:

  • CPU:2颗Intel(R) Xeon(R) Silver 4216 CPU @ 2.10GHz
  • 内存:128G(4根32G)ECC DDR4 2666Mhz
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
jyshen@ubuntu:~$ ab -c 1000 -n 100000 http://127.0.0.1:8080/
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:
Server Hostname: 127.0.0.1
Server Port: 8080

Document Path: /
Document Length: 152 bytes

Concurrency Level: 1000
Time taken for tests: 3.296 seconds
Complete requests: 100000
Failed requests: 0
Total transferred: 21500000 bytes
HTML transferred: 15200000 bytes
Requests per second: 30338.50 [#/sec] (mean)
Time per request: 32.961 [ms] (mean)
Time per request: 0.033 [ms] (mean, across all concurrent requests)
Transfer rate: 6369.90 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 16 63.0 13 1015
Processing: 3 17 5.1 16 56
Waiting: 3 13 4.9 11 55
Total: 6 33 63.5 31 1042

Percentage of the requests served within a certain time (ms)
50% 31
66% 32
75% 33
80% 34
90% 35
95% 36
98% 40
99% 44
100% 1042 (longest request)

  • 测的结果平均每秒能处理30338个请求。

2 webBench

2.1 简介

GitHub地址:WebBench

Webbench是Radim Kolar在1997年写的一个在linux下使用的非常简单的网站压测工具。它使用fork()模拟多个客户端同时访问我们设定的URL,测试网站在压力下工作的性能,最多可以模拟3万个并发连接去测试网站的负载能力。官网地址:http://home.tiscali.cz/~cz210552/webbench.html

2.2 安装

1
2
3
4
5
6
7
8
9
10
# prerequisite
sudo apt update
sudo apt install build-essential

# install webbench
wget http://home.tiscali.cz/~cz210552/distfiles/webbench-1.5.tar.gz
tar -zxvf webbench-1.5.tar.gz
cd webbench-1.5/
sudo make
sudo make install

2.3 测试

运行1万个并发client,1秒钟。

在我的实验室台式机上测试:

1
2
3
4
5
6
7
8
9
jyshen@JYSHEN-WORKPC:~$ webbench -c 10000 -t 1 http://localhost:8080/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://localhost:8080/
10000 clients, running 1 sec.

Speed=39851336 pages/min, 8545485 bytes/sec.
Requests: 664189 susceed, 0 failed.
  • 测得66万多个并发请求均成功处理

实验室的服务器无法fork创建出相同数量的1万子进程,提示:

1
2
3
4
5
6
7
8
(base) sjy@h3c-UniServer-R5200-G3:~/HearyHTTPd/webbench-1.5$ webbench -c 10000 -t 1 http://localhost:8080/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://localhost:8080/
10000 clients, running 1 sec.
problems forking worker no. 8841
fork failed.: Resource temporarily unavailable

通过htop查了下,服务器上还有其他同学的不少计算程序在进行。暂时无法对比。