首頁 > 後端開發 > PHP7 > 主體

關於PHP7.0與PHP5.6下Laravel部落格應用效能比較分析詳解

藏色散人
發布: 2023-02-17 14:30:02
轉載
3116 人瀏覽過

目前我安裝的Homestead 虛擬機器版本是2.1.8:

關於PHP7.0與PHP5.6下Laravel部落格應用效能比較分析詳解

#該版本Homestead 上預先安裝的PHP 版本是5.6.15:

關於PHP7.0與PHP5.6下Laravel部落格應用效能比較分析詳解

我們使用ab 指令(Apache 提供的效能測試工具)在這個版本中測試Laravel 應用程式(以目前正在講的使用Laravel開發的部落格應用為例)效能,我們模擬10000 次請求,100 個同時進行壓力測試:

ab -n 10000 -c 100 http://blog.app/
登入後複製
登入後複製

運行結果如下:

This is ApacheBench, Version 2.3 
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking blog.app (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: nginx/1.8.0
Server Hostname: blog.app
Server Port: 80

Document Path: /
Document Length: 324 bytes

Concurrency Level: 100
Time taken for tests: 69.354 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 19851388 bytes
HTML transferred: 10230000 bytes
Requests per second: 144.19 [#/sec] (mean)
Time per request: 693.545 [ms] (mean)
Time per request: 6.935 [ms] (mean, across all concurrent requests)
Transfer rate: 279.52 [Kbytes/sec] received

Connection Times (ms)
                  min  mean[+/-sd]  median  max
Connect:       0       0     0.2                 0      3
Processing: 17    684   319.1           588   2720
Waiting:      17     684   319.1           588   2720
Total:          20     684   319.1           588   2720

Percentage of the requests served within a certain time (ms)
 50%      588
 66%      695
 75%      842
 80%      933
 90%    1155
 95%    1321
 98%    1545
 99%    1813
 100%  2720 (longest request)
登入後複製

這裡我們要關注的是紅色加粗的文字,即每秒處理請求數,這是衡量系統性能的關鍵指標。根據系統及硬體配置的差異,數據會有些出入。

現在我們按照「Laravel Homestead 支援 PHP 7 」這一節所述將 Homestead 中的 PHP 升級到 7.0 版本。

使用vagrant ssh 登入新新增的homestead-7 虛擬機,查看PHP 版本資訊是否正確:

關於PHP7.0與PHP5.6下Laravel部落格應用效能比較分析詳解

此時在瀏覽器中存取http ://blog.app 會報錯,因為新安裝的Homestead 資料庫資料為空,需要登入虛擬機器運行如下命令運行遷移並填充資料:

php artisan migrate 
php artisan db:seed
登入後複製

再次訪問就OK了,好了我們繼續使用同樣的ab 指令進行壓力測試:

ab -n 10000 -c 100 http://blog.app/
登入後複製
登入後複製

運行結果如下:

This is ApacheBench, Version 2.3 
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking blog.app (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: nginx/1.8.0
Server Hostname: blog.app
Server Port: 80

Document Path: /
Document Length: 324 bytes

Concurrency Level: 100
Time taken for tests: 45.032 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 20101202 bytes
HTML transferred: 10230000 bytes
Requests per second: 222.06 [#/sec] (mean)
Time per request: 450.319 [ms] (mean)
Time per request: 4.503 [ms] (mean, across all concurrent requests)
Transfer rate: 435.91 [Kbytes/sec] received

Connection Times (ms)
                  min  mean[+/-sd]  median   max
Connect:       0       0     0.2                 0       4
Processing: 11    443   252.8           379   1978
Waiting:      11     443   252.8           379   1978
Total:          15     443   252.8           379   1978

Percentage of the requests served within a certain time (ms)
 50%      379
 66%      517
 75%      590
 80%      631
 90%      795
 95%      938
 98%    1060
 99%    1229
 100%  1978 (longest request)
登入後複製

經過對比,同一個Laravel 應用在PHP 7.0 下的表現比PHP 5.6 提高了54%,這是一個很顯著的效能提升,當然環境不同資料會有所出入,而且還有更大的提升空間。

原文網址:https://xueyuanjun.com/post/2398

以上是關於PHP7.0與PHP5.6下Laravel部落格應用效能比較分析詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:xueyuanjun.com
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板