国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

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

瀏覽:2日期:2022-09-07 11:58:05
目錄前期準備不開啟opcache和laravel開啟OPcache使用swoole加速包總結前期準備

測試所用的主機為虛擬機,虛擬機配置在雙核4GB的個人電腦中。虛擬機系統為linux,http服務器采用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方法:

<?phpnamespace AppHttpControllers; class TestController extends Controller{ public function test() { return 123; } }

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

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

在app/Http/Kernel文件中,關掉頻率限制中間件throttle。

不開啟opcache和laravel

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

[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

此時的并發大約為為 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的配置文件中配置,將請求轉發到swoole監聽的端口。

用 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!

也就是一百多倍?

總結

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

以上就是詳解PHP7開啟OPcache和Swoole性能的提升對比的詳細內容,更多關于PHP7開啟OPcache和Swoole性能的提升對比的資料請關注好吧啦網其它相關文章!

標簽: PHP
相關文章:
主站蜘蛛池模板: 国产九九精品 | 色视频在线观看免费 | 欧美xx一片 | 久久青草热 | 欧美亚洲一区二区三区在线 | 天天摸天天爽视频69视频 | 成人毛片手机版免费看 | 久艹在线观看 | 99综合在线| 久久99国产精一区二区三区 | 中文字幕在线看视频一区二区三区 | 91视频站 | 91热久久免费频精品动漫99 | 免费在线观看一级毛片 | 久久国产精品视频一区 | 亚洲成人在线免费观看 | 亚洲国产欧美一区 | 小屁孩cao大人免费网站 | 高清一区二区在线观看 | 91免费国产高清观看 | 国产女人毛片 | 日韩欧美国产高清在线观看 | 亚洲图片 自拍偷拍 | 色综合久久一本首久久 | 国产激情一区二区三区在线观看 | 外国成人网在线观看免费视频 | 高清国产精品久久 | 中文字幕精品视频在线 | 亚洲一区二区三区高清视频 | 99久久精品免费看国产 | 亚洲男人的天堂久久精品 | 成人香蕉xxxxxxx | 97视频免费上传播放 | 亚洲专区视频 | 成人午夜在线观看国产 | 久草免费资源 | 一及黄色毛片 | 免费一级特黄欧美大片久久网 | 久久国产精品永久免费网站 | fc2ppv在线播放 | 亚洲自拍高清 |