av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

詳解PHP7開(kāi)啟OPcache和Swoole性能的提升對(duì)比

瀏覽:3日期:2022-09-07 11:58:05
目錄前期準(zhǔn)備不開(kāi)啟opcache和laravel開(kāi)啟OPcache使用swoole加速包總結(jié)前期準(zhǔn)備

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

配置站點(diǎn),在nginx的server塊中配置虛擬主機(jī)

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

打開(kāi)項(xiàng)目,新建控制器TestController,在里面新建一個(gè)test方法:

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

在routes/api.php中注冊(cè)一個(gè)路由:

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

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

不開(kāi)啟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壓測(cè):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

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

開(kāi)啟OPcache

在配置文件php.ini文件中開(kāi)啟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壓測(cè):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)

此時(shí)的達(dá)到了 90qps,性能是未開(kāi)啟時(shí)的 10 倍以上!。

使用swoole加速包

開(kāi)源的laravel-swoole加速包

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

用 ab 壓測(cè) : 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

速度起飛!達(dá)到了800qps!

也就是一百多倍?

總結(jié)

當(dāng)然這只是一個(gè)比較簡(jiǎn)單的測(cè)試,但是總的來(lái)說(shuō)opcache擴(kuò)展和swoole擴(kuò)展對(duì)php腳本性能的提升還是很明顯的。

以上就是詳解PHP7開(kāi)啟OPcache和Swoole性能的提升對(duì)比的詳細(xì)內(nèi)容,更多關(guān)于PHP7開(kāi)啟OPcache和Swoole性能的提升對(duì)比的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: PHP
相關(guān)文章:
主站蜘蛛池模板: 免费高清av | 亚洲精品一区二区二区 | 黄a在线观看 | 美女黄网站 | av 一区二区三区 | 亚洲国产精品久久久久秋霞不卡 | 亚洲一区视频在线 | 欧美成人a | 人人九九精 | 日日av| 久久久99国产精品免费 | 精品久久久久久国产 | 日韩精品视频在线免费观看 | 国产伦精品一区二区 | 国产精品久久久久久久久久久久 | 中文字幕在线第一页 | 91大神xh98xh系列全部 | 91网站视频在线观看 | 毛片a级| 91一区二区三区在线观看 | 91久久国产综合久久 | 亚洲天堂中文字幕 | 日韩精品免费看 | 欧美vide| 日韩在线视频观看 | 成人欧美一区二区三区黑人孕妇 | 精品视频久久久久久 | 特黄特色大片免费视频观看 | 99久久免费精品视频 | 午夜精品影院 | 婷婷五月色综合香五月 | 日韩中文一区二区三区 | 久久99深爱久久99精品 | 中文字幕国产视频 | 久久久久久女 | 欧美成人在线免费 | 国产精品免费在线 | 少妇一级淫片aaaaaaaaa | 91麻豆蜜桃一区二区三区 | 91国内在线观看 | 日韩日韩日韩日韩日韩日韩日韩 |