Windows上Nginx与Apache静态文件性能实测报告
(nginx 1.27.5 vs apache 2.4.63,hey压力测试,含原始数据与分析)
背景与动机
绝大多数关于Nginx和Apache的性能评测都是基于Linux。Nginx官方也明确表示其Windows版本一直处于beta阶段,对其性能不应抱太大期望。现实中关于Windows平台下Nginx性能的实际高并发测试案例非常稀缺。
本文使用hey工具在腾讯云轻量应用服务器(2核 2.6GHz,2G内存,Windows)上分别测试了Nginx 1.27.5 与 Apache 2.4.63 静态文件高并发性能,弥补了这一空白。
测试环境说明
- 服务器:腾讯云轻量服务器 2核2.6GHz,2G内存
- 操作系统:Windows
- Nginx版本:1.27.5
- Apache版本:2.4.63
- 被测资源:本地静态图片
/static/tomato.png
(每次请求71882字节)
- 压测工具:hey for Windows
- 压力参数:并发400,总请求30000
- 测试命令:
hey_windows_amd64.exe -c 400 -n 30000 http://127.0.0.1/static/tomato.png
原始测试数据
Apache 2.4.63 测试结果
Summary:
Total: 19.2283 secs
Slowest: 18.6432 secs
Fastest: 0.0004 secs
Average: 0.1415 secs
Requests/sec: 1560.2004
Total data: 2156460000 bytes
Size/request: 71882 bytes
Response time histogram:
0.000 [1] |
1.865 [29746] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
3.729 [1] |
5.593 [5] |
7.458 [0] |
9.322 [19] |
11.186 [132] |
13.050 [3] |
14.915 [39] |
16.779 [4] |
18.643 [50] |
Latency distribution:
10% in 0.0011 secs
25% in 0.0046 secs
50% in 0.0328 secs
75% in 0.0552 secs
90% in 0.0774 secs
95% in 0.1396 secs
99% in 0.4220 secs
Details (average, fastest, slowest):
DNS+dialup: 0.0008 secs, 0.0004 secs, 18.6432 secs
DNS-lookup: 0.0000 secs, 0.0000 secs, 0.0000 secs
req write: 0.0003 secs, 0.0000 secs, 0.3439 secs
resp wait: 0.1348 secs, 0.0004 secs, 18.6431 secs
resp read: 0.0046 secs, 0.0000 secs, 0.3162 secs
Status code distribution:
[200] 30000 responses
Nginx 1.27.5 测试结果
Summary:
Total: 14.0290 secs
Slowest: 0.3516 secs
Fastest: 0.1592 secs
Average: 0.1808 secs
Requests/sec: 2138.4308
Total data: 2156460000 bytes
Size/request: 71882 bytes
Response time histogram:
0.159 [1] |
0.178 [15472] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
0.198 [12350] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
0.217 [1556] |■■■■
0.236 [394] |■
0.255 [122] |
0.275 [61] |
0.294 [6] |
0.313 [1] |
0.332 [19] |
0.352 [18] |
Latency distribution:
10% in 0.1678 secs
25% in 0.1715 secs
50% in 0.1779 secs
75% in 0.1859 secs
90% in 0.1934 secs
95% in 0.2082 secs
99% in 0.2329 secs
Details (average, fastest, slowest):
DNS+dialup: 0.0007 secs, 0.1592 secs, 0.3516 secs
DNS-lookup: 0.0000 secs, 0.0000 secs, 0.0000 secs
req write: 0.0001 secs, 0.0000 secs, 0.0522 secs
resp wait: 0.0180 secs, 0.0003 secs, 0.0890 secs
resp read: 0.1619 secs, 0.0831 secs, 0.2194 secs
Status code distribution:
[200] 30000 responses
指标对比与结果分析
指标 |
Apache 2.4.63 |
Nginx 1.27.5 |
总用时 |
19.23 秒 |
14.03 秒 |
平均响应时间 |
0.142 秒 |
0.181 秒 |
QPS(吞吐量) |
1560 r/s |
2138 r/s |
最慢响应 |
18.64 秒 |
0.35 秒 |
最快响应 |
0.0004 秒 |
0.1592 秒 |
90%请求小于 |
0.077 秒 |
0.193 秒 |
Status 200 |
30,000 |
30,000 |
错误数 |
0 |
0 |
核心发现
- 吞吐量更高:Nginx的QPS高达2138,比Apache高出37%!(可能和大部分请求响应均衡有关)
- 长尾响应更极端:Apache有极少数慢请求拉高了总体最大延迟,而Nginx响应时间分布极度集中,没有出现大延迟请求。
- 响应速度分布:
- Apache下,绝大多数请求都非常快(99%小于0.42秒),但仍有极端慢请求(>10秒,这可能和进程/线程池调度、IO有关)
- Nginx下,几乎所有请求都集中在0.16~0.23秒内,没有长尾,速度非常平均
- 稳定性:两者在本轮测试均0错误,稳定性都很好
对Nginx官方“Windows版不应期待高性能和高扩展性”言论的印证
- Nginx官方文档 :high performance and scalability should not be expected, version of nginx for Windows is considered to be a beta version.。
- 本次测试发现,Nginx在大并发短压场景下表现相比Apache并不惨淡,响应速度均衡,高并发吞吐明显优于Apache。
本文进一步用 ab 和 hey 进行了交叉验证,得到结论一致。
c:\Apache24\bin>ab.exe -c 400 -n 30000 http://127.0.0.1/static/tomato.png
This is ApacheBench, Version 2.3 <$Revision: 1923142 $>
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 3000 requests
Completed 6000 requests
...
Completed 30000 requests
Finished 30000 requests
Server Software: nginx/1.27.5
Server Hostname: 127.0.0.1
Server Port: 80
Document Path: /static/tomato.png
Document Length: 71882 bytes
Concurrency Level: 400
Time taken for tests: 13.537 seconds
Complete requests: 30000
Failed requests: 0
Total transferred: 2163570000 bytes
HTML transferred: 2156460000 bytes
Requests per second: 2216.11 [#/sec] (mean)
Time per request: 180.496 [ms] (mean)
Time per request: 0.451 [ms] (mean, across all concurrent requests)
Transfer rate: 156078.10 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 1.4 0 16
Processing: 160 179 11.0 174 253
Waiting: 0 6 10.0 0 80
Total: 160 179 11.1 174 253
Percentage of the requests served within a certain time (ms)
50% 174
66% 177
75% 183
80% 188
90% 189
95% 194
98% 218
99% 231
100% 253 (longest request)
c:\Apache24\bin>ab.exe -c 400 -n 30000 http://127.0.0.1/static/tomato.png
This is ApacheBench, Version 2.3 <$Revision: 1923142 $>
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 3000 requests
Completed 6000 requests
...
Completed 30000 requests
Finished 30000 requests
Server Software: Apache/2.4.63
Server Hostname: 127.0.0.1
Server Port: 80
Document Path: /static/tomato.png
Document Length: 71882 bytes
Concurrency Level: 400
Time taken for tests: 18.277 seconds
Complete requests: 30000
Failed requests: 0
Total transferred: 2171160000 bytes
HTML transferred: 2156460000 bytes
Requests per second: 1641.42 [#/sec] (mean)
Time per request: 243.691 [ms] (mean)
Time per request: 0.609 [ms] (mean, across all concurrent requests)
Transfer rate: 116008.67 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 1.5 0 35
Processing: 51 242 54.0 222 878
Waiting: 16 230 61.9 211 878
Total: 51 243 54.0 222 878
Percentage of the requests served within a certain time (ms)
50% 222
66% 250
75% 268
80% 282
90% 330
95% 348
98% 372
99% 408
100% 878 (longest request)