溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

PHP7.0與PHP5.6下Laravel博客的應用性能對比介紹

發布時間:2020-04-24 09:49:17 來源:億速云 閱讀:418 作者:小新 欄目:編程語言

這篇文章主要為大家詳細介紹了PHP7.0與PHP5.6下Laravel博客的應用性能對比,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下。

目前我安裝的 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%,這是一個很顯著的性能提升,當然環境不同數據會有所出入,而且還有更大的提升空間。

以上就是關于PHP7.0與PHP5.6下Laravel博客應用性能對比分析詳解的詳細內容,更多請關注億速云其它相關文章!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女