我有一个 2GB RAM、四核服务器,并且我正在运行 nginx 作为反向代理,但是我的 apache 设置应该是什么才能实现最佳优化来处理大量请求,以及如何在负载下进行测试?
当前的:
Timeout 300
TraceEnable Off
ServerSignature Off
ServerTokens ProductOnly
FileETag All
StartServers 3
<IfModule prefork.c>
MinSpareServers 2
MaxSpareServers 4
</IfModule>
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 10000
KeepAlive On
KeepAliveTimeout 300
MaxKeepAliveRequests 100
答案1
以下是我的设置。我喜欢使用 Apache Bench 来测试配置。请参阅下面的 ab 结果。
Timeout 45
KeepAlive Off
# prefork MPM
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 250
MaxRequestsPerChild 1000
</IfModule>
# worker MPM
<IfModule mpm_worker_module>
StartServers 2
MaxClients 250
MinSpareThreads 25
MaxSpareThreads 150
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>
使用以下命令查看 Apache Bench 结果:# ab -n 1000 -c 30 http://example.com/
Server Software: nginx/0.8.54
Server Hostname: example.com
Server Port: 80
Document Path: /
Document Length: 25501 bytes
Concurrency Level: 30
Time taken for tests: 0.076 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 25983000 bytes
HTML transferred: 25501000 bytes
Requests per second: 13203.06 [#/sec] (mean)
Time per request: 2.272 [ms] (mean)
Time per request: 0.076 [ms] (mean, across all concurrent requests)
Transfer rate: 335014.83 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.2 0 1
Processing: 0 2 0.3 2 3
Waiting: 0 1 0.5 1 3
Total: 1 2 0.2 2 3