2012-05-15 73 views
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應用程序/控制檯--env = prod cache:clear php app/console --env = prod cache:warmup

Symfony檢查頁面告訴我,我只有intl擴展名,所以apc可能沒問題。

我的PHP版本是:

用了Suhosin貼片PHP 5.3.6-13ubuntu3.6

可能有人給我說說還有什麼我應該在ENV檢查的建議嗎?

+0

你應該看看/ POST「連接時報」。在那裏你可以看到哪一部分需要最多的時間。 – Darcara

+0

這是ab功能嗎? – keram

+0

是的,整個輸出應該看起來像[this](http://imgur.com/Fwek5) – Darcara

回答

5

它可以是任何數量的東西,包括您的計算機無法處理負載。我可以給你幾點提示,但是在哪裏看。

您收到一些錯誤返回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

+0

謝謝,很好的答案。 – keram