我正在为我的硕士论文做性能测试,我发现 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 app/console --env=prod cache:clear php app/console --env=prod cache:warmup
Symfony 检查页面告诉我,我只是没有 intl 扩展名,所以 apc 可能没问题。
我的 PHP 版本是:
PHP 5.3.6-13ubuntu3.6 with 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
仅用于调试。您需要将其设置为 warn
或 error
用于生产。
在 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
如果还是慢,google apache performance tuning
和(假设您使用 MySQL 作为数据库)mysql performance tuning
关于php - 表现不佳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10599863/