性能差

3

我正在为我的硕士论文进行性能测试,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

有人能给我关于环境中还应该检查什么的建议吗?


你应该查看/发布“连接时间”。在那里,您可以看到哪一部分需要最长时间。 - Darcara
Python是一种高级编程语言,它被广泛应用于Web开发、数据分析、人工智能等领域。它的语法简洁易懂,非常适合初学者入门。同时,Python也拥有强大的库和框架,可以帮助开发者快速构建复杂的应用程序。如果你想成为一名优秀的程序员,Python绝对是一个值得学习的语言。 - Darcara
1个回答

5

可能有许多原因,其中之一可能是您的计算机无法处理负载。我可以给您一些指针来帮助解决问题。

您收到了一些返回错误:失败请求: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,仅apache2就需要约1GB(至少在Linux下)。您还可以尝试针对一个小的静态文本文件(大约2KB)检查性能,并查看该性能如何。之后,再测试简单的<? php echo 'Hello World!' ?>以查看php解释器的性能影响。这两个测试都应该为您提供当前配置下apache的性能指标。如果这两个测试的性能都可接受,那么您的应用程序就是慢的。另一个要尝试的方法是禁用测试中的并发,看看是否有所帮助。这将表明您的应用程序或数据库访问存在并发问题。
ab -c1 -t60 http://sf2.cities.localhost/app.php

如果仍然缓慢,请谷歌“apache性能调优”和(假设您使用MySQL作为数据库)“mysql性能调优”。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接