Apache2 基准测试 - 性能非常差

Apache2 基准测试 - 性能非常差

我有两台服务器,用于测试 apache2 的配置。

第一台服务器:

4GB of RAM, AMD Athlon (tm) 64 X2 Dual Core Processor 5600 + 
Apache 2.2.3, mod_php, mpm prefork: 
Settings: 

Timeout 100 
KeepAlive On 
MaxKeepAliveRequests 150 
KeepAliveTimeout 4 

<IfModule Mpm_prefork_module> 
    StartServers 7 
    MinSpareServers 15 
    MaxSpareServers 30 
    MaxClients 250 
    MaxRequestsPerChild 2000 
</ IfModule> 

Compiled in modules: 
  core.c 
  mod_log_config.c 
  mod_logio.c 
  prefork.c 
  http_core.c 
  mod_so.c 

第二台服务器:

8GB of RAM, Intel (R) Core (TM) i7 CPU [email protected] 
Apache 2.2.9, **fcgid, mpm worker, suexec**

PHP scripts are running via fcgi-wrapper 

Settings: 

Timeout 100 
KeepAlive On 
MaxKeepAliveRequests 100 
KeepAliveTimeout 4 

<IfModule Mpm_worker_module> 
    StartServers 10 
    MaxClients 200 
    MinSpareThreads 25 
    MaxSpareThreads 75 
    ThreadsPerChild 25 
    MaxRequestsPerChild 1000 
</ IfModule> 

Compiled in modules: 
  core.c 
  mod_log_config.c 
  mod_logio.c 
  worker.c 
  http_core.c 
  mod_so.c 

下面的测试结果,很奇怪!

新服务器(动态内容 - 通过 fcgid+suexec 的 php):

Server Software:    Apache/2.2.9
Server Hostname:    XXXXXXXX
Server Port:    80
Document Path:  XXXXXXX
Document Length:    179512 bytes
Concurrency Level:  10
Time taken for tests:   0.26276 seconds
Complete requests:  1000
Failed requests:    0
Total transferred:  179935000 bytes
HTML transferred:   179512000 bytes
Requests per second:    38.06
Transfer rate:  6847.88 kb/s received
Connnection Times (ms)
    min avg max
Connect:    2   4   54
Processing: 161 257 449
Total:  163 261 503

旧服务器(动态内容 - mod_php):

Server Software:    Apache/2.2.3
Server Hostname:    XXXXXX
Server Port:    80
Document Path:  XXXXXX
Document Length:    187537 bytes
Concurrency Level:  10
Time taken for tests:   173.073 seconds
Complete requests:  1000
Failed requests:    22
(Connect: 0, Length: 22, Exceptions: 0)
Total transferred:  188003372 bytes
HTML transferred:   187546372 bytes
Requests per second:    5777.91
Transfer rate:  1086267.40 kb/s received
Connnection Times (ms)
    min avg max
Connect:    3   3   28
Processing: 298 1724    26615
Total:  301 1727    26643

旧服务器:静态内容(jpg 文件)

Server Software:        Apache/2.2.3
Server Hostname:        xxxxxxxxx
Server Port:            80

Document Path:          /images/top2.gif
Document Length:        40486 bytes

Concurrency Level:      100
Time taken for tests:   3.558 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      40864400 bytes
HTML transferred:       40557482 bytes
Requests per second:    281.09 [#/sec] (mean)
Time per request:       355.753 [ms] (mean)
Time per request:       3.558 [ms] (mean, across all concurrent requests)
Transfer rate:          11217.51 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        3   11   4.5     12      23
Processing:    40  329  61.4    339    1009
Waiting:        6  282  55.2    293     737
Total:         43  340  63.0    351    1020

新服务器-静态内容(jpg文件)

Server Software:        Apache/2.2.9
Server Hostname:        XXXXX
Server Port:            80

Document Path:          /images/top2.gif
Document Length:        40486 bytes

Concurrency Level:      100
Time taken for tests:   3.571531 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      41282792 bytes
HTML transferred:       41030080 bytes
Requests per second:    279.99 [#/sec] (mean)
Time per request:       357.153 [ms] (mean)
Time per request:       3.572 [ms] (mean, across all concurrent requests)
Transfer rate:          11287.88 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        2   63  24.8     66     119
Processing:   124  278  31.8    282     391
Waiting:        3   70  28.5     66     164
Total:        126  341  35.9    350     443

我注意到 apache error.log 中有很多条目:

[notice] mod_fcgid: call /www/XXXXX/public_html/forum/index.php with wrapper /www/php-fcgi-scripts/XXXXXX/php-fcgi-starter

我遗漏了什么或不明白什么?

每秒请求数有如此大的差异?可能吗?可能是什么原因造成的?

答案1

我最先想到的是 worker 与 prefork。为了隔离,您应该尝试在“新”/“第二”服务器上运行 prefork。

我也对“旧”基准持怀疑态度:

Transfer rate:  1086267.40 kb/s received

这相当于 1.03 GB/s,即 8.2 Gbps。显然,这比 1 Gbps 端口要快。您在这里运行的是相同的测试,还是在本地对旧版本进行基准测试,在远程对新版本进行基准测试?

希望这不是一个太基础的问题,但是您是否在测试相同的负载/应用程序?例如,如果您将加载静态文件(如图像)与正在执行某些处理的 php 页面进行比较,您将得到不同的结果。如果您的 php 页面也接触数据库,并且两个服务器上的数据库不同,这也会影响结果。

我建议——再次强调,为了隔离——对两者之间的静态文件进行基准测试。如果您没有发现任何差异,请在两者上尝试相同的简单 php 页面(它不是另一个应用程序的一部分,只是在循环中执行一些简单操作,例如 hello world)。

一旦您对各个部分进行了苹果与苹果的基准测试,您就应该有足够的信息来找出导致差异的原因(是您的数据库服务器?文件系统?apache 分叉模型?apache 版本?网络?基准测试本身?)。

答案2

1) 您是否重复了足够多次以验证结果?
2) 您是否在观察内存统计数据并检查错误日志?由于这是两个不同的 Apache 模型(线程与分叉),因此调整可能会产生很大影响。因此,我认为您应该在工作版本中观察您的资源(内存和 CPU),并可能调整可调选项。3
) 这些测试中有很多不同之处,Apache 模型、正在检索的文档的大小、php 模块,也许您可​​以使测试更相似一些?

相关内容