亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

詳解PHP7開啟OPcache和Swoole性能的提升對比

 更新時間:2021年05月26日 09:09:06   作者:phpyu  
laravel作為最熱門的php框架之一,廣受認可與歡迎。同時由于集成度很高,每次運行都加載了大量文件,加之使用了大量的閉包、魔術(shù)方法,導(dǎo)致laravel框架很重,并發(fā)性能極差。OPcache和Swoole都是php的擴展,這次旨在比較這兩個擴展分別開啟后對Laravel應(yīng)用的加速效果。

前期準備

測試所用的主機為虛擬機,虛擬機配置在雙核4GB的個人電腦中。虛擬機系統(tǒng)為linux,http服務(wù)器采用nginx,用lnmp腳本安裝nginx、mysql、php。Laravel框架為7.X版本。

配置站點,在nginx的server塊中配置虛擬主機

server{ listen 80; root "/vagrant/www/laravel7/public"; server_name test.laravel.com; index index.html index.php; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }

編輯/etc/hosts文件,在新行添加127.0.0.1 test.laravel.com

打開項目,新建控制器TestController,在里面新建一個test方法:

<?php
namespace App\Http\Controllers;
 
 
 
class TestController extends Controller
{
    public function test()
    {
    	return 123;
    }
 
    
}

在routes/api.php中注冊一個路由:

Route::get('test', 'TestController@test');

在app/Http/Kernel文件中,關(guān)掉頻率限制中間件throttle。

不開啟opcache和laravel

修改php-fpm.conf文件,修改pm和pm.max_children 配置,pm設(shè)置為static,pm.max_children設(shè)置為50,以獲得較好的并發(fā)性能。

[www] listen = /tmp/php-cgi.sock listen.backlog = -1 listen.allowed_clients = 127.0.0.1 listen.owner = www listen.group = www listen.mode = 0666 user = www group = www pm = static pm.max_children = 50 pm.start_servers = 10 pm.min_spare_servers = 10 pm.max_spare_servers = 20 request_terminate_timeout = 100 request_slowlog_timeout = 0 slowlog = var/log/slow.log

重啟fpm后用ab壓測:ab -n 1000 -c 100 http://test.laravel.com/api/test

Server Software:        nginx

Server Hostname:        test.laravel.com

Server Port:            80

Document Path:          /api/test

Document Length:        3 bytes

Concurrency Level:      100

Time taken for tests:   148.306 seconds

Complete requests:      1000

Failed requests:        0

Total transferred:      253000 bytes

HTML transferred:       3000 bytes

Requests per second:    6.74 [#/sec] (mean)

Time per request:       14830.553 [ms] (mean)

Time per request:       148.306 [ms] (mean, across all concurrent requests)

Transfer rate:          1.67 [Kbytes/sec] received

此時的并發(fā)大約為為 7 qps

開啟OPcache

在配置文件php.ini文件中開啟opcache

zend_extension="opcache.so" opcache.enable=1 opcache.memory_consumption=128 opcache.max_accelerated_files=10000 opcache.revalidate_freq=60 opcache.fast_shutdown=1 opcache.enable_cli=1 opcache.interned_strings_buffer=8

重啟fpm后,用ab壓測:ab -n 1000 -c 100 http://test.laravel.com/api/test

Server Software:        nginx

Server Hostname:        test.laravel.com

Server Port:            80

Document Path:          /api/test

Document Length:        4 bytes

Concurrency Level:      100

Time taken for tests:   11.006 seconds

Complete requests:      1000

Failed requests:        0

Total transferred:      254000 bytes

HTML transferred:       4000 bytes

Requests per second:    90.86 [#/sec] (mean)

Time per request:       1100.590 [ms] (mean)

Time per request:       11.006 [ms] (mean, across all concurrent requests)

Transfer rate:          22.54 [Kbytes/sec] received

Connection Times (ms)

              min  mean[+/-sd] median   max

Connect:        0    1   4.3      0      16

Processing:   409 1069 152.0   1092    1414

Waiting:      408 1069 152.0   1092    1414

Total:        424 1070 149.6   1092    1414

Percentage of the requests served within a certain time (ms)

  50%   1092

  66%   1126

  75%   1149

  80%   1162

  90%   1203

  95%   1242

  98%   1280

  99%   1309

 100%   1414 (longest request)

此時的達到了 90qps,性能是未開啟時的 10 倍以上!。

使用swoole加速包

開源的laravel-swoole加速包

在項目目錄下運行composer命令安裝;在nginx的配置文件中配置,將請求轉(zhuǎn)發(fā)到swoole監(jiān)聽的端口。

用 ab 壓測 : ab -n 1000 -c 100 http://test.laravel.com/api/test

Server Software:        nginx

Server Hostname:        test.laravel.com

Server Port:            80

Document Path:          /api/test

Document Length:        4 bytes

Concurrency Level:      100

Time taken for tests:   1.158 seconds

Complete requests:      1000

Failed requests:        0

Total transferred:      225000 bytes

HTML transferred:       4000 bytes

Requests per second:    863.46 [#/sec] (mean)

Time per request:       115.813 [ms] (mean)

Time per request:       1.158 [ms] (mean, across all concurrent requests)

Transfer rate:          189.72 [Kbytes/sec] received

速度起飛!達到了800qps!

也就是一百多倍?

總結(jié)

當然這只是一個比較簡單的測試,但是總的來說opcache擴展和swoole擴展對php腳本性能的提升還是很明顯的。

以上就是詳解PHP7開啟OPcache和Swoole性能的提升對比的詳細內(nèi)容,更多關(guān)于PHP7開啟OPcache和Swoole性能的提升對比的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Content-Disposition使用方法和注意事項

    Content-Disposition使用方法和注意事項

    這篇文章主要為大家詳細介紹了Content-Disposition使用方法和注意事項,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-09-09
  • php中html_entity_decode實現(xiàn)HTML實體轉(zhuǎn)義

    php中html_entity_decode實現(xiàn)HTML實體轉(zhuǎn)義

    這篇文章主要介紹了php中html_entity_decode實現(xiàn)HTML實體轉(zhuǎn)義的相關(guān)資料,需要的朋友可以參考下
    2018-06-06
  • PHP多線程類及用法實例

    PHP多線程類及用法實例

    這篇文章主要介紹了PHP多線程類及用法,實例分析了多線程類的具體實現(xiàn)方法及應(yīng)用技巧,并結(jié)合下載遠程圖片的實例予以深入分析,需要的朋友可以參考下
    2014-12-12
  • php下用cookie統(tǒng)計用戶訪問網(wǎng)頁次數(shù)的代碼

    php下用cookie統(tǒng)計用戶訪問網(wǎng)頁次數(shù)的代碼

    利用cookie統(tǒng)計用戶訪問網(wǎng)頁次數(shù)的代碼,需要的朋友可以參考下。作為學(xué)習cookies的資料,不推薦使用。
    2010-05-05
  • 詳解PHP用mb_string處理windows中文字符

    詳解PHP用mb_string處理windows中文字符

    如果想批處理以前下載的一堆文件,把文件里的關(guān)鍵內(nèi)容用正則匹配出來,集中處理。操作文件時遇到一個問題,就是windows操作系統(tǒng)中的編碼問題。本文將帶著大家詳細探討此問題。
    2021-05-05
  • php smarty模板引擎的6個小技巧

    php smarty模板引擎的6個小技巧

    php smarty模板引擎中幾個經(jīng)常被忽略的但比較有用的標簽整理,包括capture標簽,config_load標簽,php標簽,strip標簽,fetch標簽,以及如何在smarty模板中直接使用define定義的常量
    2014-04-04
  • PHP合并數(shù)組+號和array_merge的區(qū)別

    PHP合并數(shù)組+號和array_merge的區(qū)別

    這篇文章主要介紹了PHP合并數(shù)組+號和array_merge的區(qū)別,PHP的數(shù)組融合一般有兩種做法,一種是直接使用加號相加,另一種則是使用array_merge函數(shù)進行相加,兩者之間有點區(qū)別,需要的朋友可以參考下
    2015-06-06
  • 利用php繪制餅狀圖的實現(xiàn)代碼

    利用php繪制餅狀圖的實現(xiàn)代碼

    本篇文章是對使用php繪制餅狀圖的方法進行了詳細的分析介紹,需要的朋友參考下
    2013-06-06
  • php max_execution_time執(zhí)行時間問題

    php max_execution_time執(zhí)行時間問題

    大部分PHP代碼執(zhí)行時間都不會很久。但是有些時候,比如等待圖片上傳,可能執(zhí)行時間過長導(dǎo)致超時。
    2011-07-07
  • PHP set_time_limit(0)長連接的實現(xiàn)分析

    PHP set_time_limit(0)長連接的實現(xiàn)分析

    每次我們訪問PHP腳本的時候,都是當所有的PHP腳本執(zhí)行完成后,我們才得到返回結(jié)果。如果我們需要一個腳本持續(xù)的運行,那么我們就要通過php長連接的方式,來達到運行目的。
    2010-03-03

最新評論