Nginx Windows 版本安装与配置说明
获取了 Nginx For Win32 的官方发行版,具体版本号为 nginx 0.7.53。
对该版本进行了初步试用,并执行了相关的压力测试以评估其性能。
安装与使用的流程较为简便,具体操作可参考官方提供的指南:
Win32 Binaries
自 0.7.52 版本起,Nginx 正式提供了官方的 Windows 二进制文件支持。
Installation:
cd c:\
unzip nginx-0.7.52.zip
ren nginx-0.7.52 nginx
cd nginx
start nginx
Control:
nginx -s [ stop | quit | reopen | reload ]
若遇到问题,请查阅 c:\nginx\logs\error.log 文件或 Windows 事件查看器 (EventLog)。
需特别说明的是,此前第三方编译的 Nginx for Windows 版本支持作为 Windows 服务运行,但在该官方版本中此功能不可用。因此建议采用手动启动方式,或通过新建计划任务实现开机自启。
随后立即开展压力测试,测试工具选用 Apache 的 ab,测试对象为 Nginx 安装后默认的纯静态页面:
Welcome to nginx!
测试命令:./ab -c 100 -n 10000 http://192.168.3.50:8888/
操作系统:Windows server 2003 R2
硬件配置:Xeon 2.8G X2 1G RAM
测试结果:
Server Software: nginx/0.7.53
Server Hostname: 192.168.3.50
Server Port: 8888
Document Path: /
Document Length: 151 bytes
Concurrency Level: 100
Time taken for tests: 107.329 seconds
Complete requests: 10000 (100%处理请求,没有丢失)
Failed requests: 0
Write errors: 0
Total transferred: 3620000 bytes
HTML transferred: 1510000 bytes
Requests per second: 93.17 [#/sec] (mean) 每秒处理请求 93.17 个
Time per request: 1073.293 [ms] (mean)
Time per request: 10.733 [ms] (mean, across all concurrent requests)
Transfer rate: 32.94 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 13 44.3 2 550
Processing: 180 1059 350.5 1065 2665
Waiting: 178 1053 352.3 1058 2664
Total: 194 1071 351.9 1074 2668
Percentage of the requests served within a certain time (ms)
50% 1074
66% 1162
75% 1215
80% 1288
90% 1547
95% 1694
98% 1853
99% 1946
100% 2668 (longest request)
################
根据上述测试结果,Nginx for Windows 在 100 个并发线程下,每秒仅能处理约 93 个请求。
若再启动一个 ab 实例增加压力,总并发线程达到 200 个时,ab 返回结果相当,各端点每秒处理请求数仍维持在 93 个左右。
然而,若再启动第三个 ab 实例进行 100 线程的压力测试,正在进行的两个 ab 中其中一个会被服务端拒绝连接。
尝试多次修改 Nginx 的 worker_processes 参数未果,调整 Win2003 的并发线程设置也无改善……难道 Nginx 在 Windows 下的性能上限仅此而已?后续需进一步排查原因。
此外还存在一个问题:压力测试结束后,在 Windows 任务管理器中观察发现 Nginx 进程仍占用 2%~30% 的 CPU 资源。
在命令行执行 Nginx -s stop 无法正常停止服务,必须强制结束进程才能终止。
################
以上仅为初步尝试的几个关键点,希望是个别环境问题,有机会的朋友不妨自行验证。
配置 PD930 CPU,2G 内存,测试结果如下:
C:\>ab -n 10000 -c 100 http://192.168.1.8/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.1.8 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: nginx/0.7.52
Server Hostname: 192.168.1.8
Server Port: 80
Document Path: /
Document Length: 151 bytes
Concurrency Level: 100
Time taken for tests: 5.109 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 3620000 bytes
HTML transferred: 1510000 bytes
Requests per second: 1957.19 [#/sec] (mean)
Time per request: 51.094 [ms] (mean)
Time per request: 0.511 [ms] (mean, across all concurrent requests)
Transfer rate: 691.90 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 2.4 0 16
Processing: 16 50 13.3 47 78
Waiting: 0 34 14.4 31 78
Total: 16 51 13.3 47 78
Percentage of the requests served within a certain time (ms)
50% 47
66% 63
75% 63
80% 63
90% 63
95% 63
98% 63
99% 78
100% 78 (longest request)