性能不佳


Poor performance

我正在为我的硕士论文做性能测试,我的Symfony2简单应用程序的性能非常差。这是一个简单的应用程序,一个查询和一些数学。

命令的测试结果:

AB -C10 -T60 http://sf2.cities.localhost/app.php

Server Software:        Apache/2.2.20
Server Hostname:        sf2.cities.localhost
Server Port:            80
Document Path:          /app.php
Document Length:        2035 bytes
Concurrency Level:      10
Time taken for tests:   60.162 seconds
Complete requests:      217
Failed requests:        68
   (Connect: 0, Receive: 0, Length: 68, Exceptions: 0)
Write errors:           0
Non-2xx responses:      68
Total transferred:      393876 bytes
HTML transferred:       321102 bytes
Requests per second:    3.61 [#/sec] (mean)
Time per request:       2772.458 [ms] (mean)
Time per request:       277.246 [ms] (mean, across all concurrent requests)
Transfer rate:          6.39 [Kbytes/sec] received
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   2.1      0      11
Processing:   230 2641 2493.1   1778   17146
Waiting:      230 2641 2493.1   1778   17146
Total:        230 2642 2492.9   1778   17146

在测试之前,我启动了两个命令:

PHP 应用程序/控制台 --env=prod cache:clear PHP 应用程序/控制台 --env=prod cache:预热

Symfony检查页面告诉我,我只有intl扩展,所以apc可能没问题。

我的PHP版本是:

PHP 5.3.6-13ubuntu3.6 与 Suhosin-Patch

有人可以给我建议,关于我应该在我的环境中检查什么吗?

它可以是任意数量的事情,包括您的计算机无法处理负载。不过,我可以给你一些指示,看看哪里。

您收到一些返回的错误Failed requests: 68 。查看 apache 日志文件,它们可能会指示问题。如果在它们中找不到任何内容,请确保已启用日志记录,并且配置文件设置了正确的日志级别。您的VirtualHost定义应包含类似以下内容

 LogLevel debug
 CustomLog /var/log/apache2/access-localhost.log vhost_combined
 ErrorLog /var/log/apache2/error-localhost.log

仅将LogLevel debug用于调试。您需要将其设置为 warnerror 用于生产。

在 php.ini 和脚本中启用错误日志记录,并检查 php 错误日志是否存在任何问题。

确保你的 apache2.conf 配置正确,尤其是 mpm 模块。这是一个标准,尽管远非完美配置:

<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>
<IfModule mpm_worker_module>
    StartServers          2
    MaxClients          150
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadsPerChild      25
    MaxRequestsPerChild   0
</IfModule>

确保你有足够的RAM,你只需要大约1GB的apache2(至少在linux下(

您还可以尝试针对小型静态文本文件(大约 2kb(检查性能,看看性能如何。之后,对照简单<? php echo 'Hello World!' ?>检查 php 解释器的性能影响。这两个测试都应该给你一个指示,你的apache在当前配置下的能力。如果性能在两个测试中都可接受,则您的应用运行缓慢。

要尝试的另一件事是在测试中禁用并发性,看看是否有帮助。这将表示应用或数据库访问中存在并发问题。

ab -c1 -t60 http://sf2.cities.localhost/app.php

如果它仍然很慢,谷歌apache performance tuning和(假设你使用MySQL作为你的数据库(mysql performance tuning