测试Octane
+Swoole
晋升水平
硬件:虚拟机VirtualBox, 1核2G, CPU为i5-8400;
零碎: Centos7 + 宝塔;
php环境: 启用opcache
, session
启用memcached
缓存,文件缓存启用redis
;
部署我的项目及引入octane
composer create-project laravel/laravel octance.sw
cd ./octance.sw
## 引入octane
composer require laravel/octane
## 装置octane
php artisan octane:install
装置这一步应用RoadRunner
出了很多问题,最初跑起来也没能失常拜访,遂放弃应用RR;
应用swoole
倒是非常简单,宝塔面板中装好swoole
扩大,octane:install
时选swoole
间接实现。
对laravel
进行一般的生产环境优化;
composer install --no-dev
## 设置配置文件,关掉debug
vi .env
APP_ENV=production
APP_DEBUG=false
## :wq保留
## 执行优化
composer dump-autoload -o
php artisan optimize
到中件间文件app/Http/Kernel.php
中正文掉api
下的throttle
中间件,免得ab
压测时报429的谬误
测试以下内容:在控制器中返回一个0-100的随机数,控制器代码如下
function random()
{
$i = mt_rand(0, 100);
return response()->json([
'code' => 0,
'msg' => 'random: ' . str_pad($i, 3, '0', STR_PAD_LEFT)
]);
}
1, 压测php-fpm
配置Nginx转发到php-fpm;而后进行ab
压测,一次压测后果如下:
.\ab -n2000 -c8 http://octane.sw/api/random
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking octane.sw (be patient)
Completed 200 requests
Completed 400 requests
Completed 600 requests
Completed 800 requests
Completed 1000 requests
Completed 1200 requests
Completed 1400 requests
Completed 1600 requests
Completed 1800 requests
Completed 2000 requests
Finished 2000 requests
Server Software: nginx
Server Hostname: octane.sw
Server Port: 80
Document Path: /api/random
Document Length: 30 bytes
Concurrency Level: 8
Time taken for tests: 17.194 seconds
Complete requests: 2000
Failed requests: 0
Total transferred: 512000 bytes
HTML transferred: 60000 bytes
Requests per second: 116.32 [#/sec] (mean)
Time per request: 68.777 [ms] (mean)
Time per request: 8.597 [ms] (mean, across all concurrent requests)
Transfer rate: 29.08 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.4 0 5
Processing: 7 68 68.2 53 641
Waiting: 7 68 68.2 53 641
Total: 7 69 68.2 53 641
Percentage of the requests served within a certain time (ms)
50% 53
66% 59
75% 61
80% 64
90% 95
95% 243
98% 303
99% 346
100% 641 (longest request)
测试后果可见,一般优化下,php8的php-fpm
能提供110+的QPS;
2, 压测octane
+swoole
启动工作过程:
php /path/octane.sw/artisan octane:start --host="0.0.0.0" --port=8080 --workers=4 --max-requests=10000 --task-workers=10
并退出到Supervisor
过程守护中;
配置nginx,将所有申请都转发到127.0.0.1:8080
进行ab
压测,一次压测后果如下:
.\ab -n2000 -c8 http://octane.sw/api/random
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking octane.sw (be patient)
Completed 200 requests
Completed 400 requests
Completed 600 requests
Completed 800 requests
Completed 1000 requests
Completed 1200 requests
Completed 1400 requests
Completed 1600 requests
Completed 1800 requests
Completed 2000 requests
Finished 2000 requests
Server Software: nginx
Server Hostname: octane.sw
Server Port: 80
Document Path: /api/random
Document Length: 30 bytes
Concurrency Level: 8
Time taken for tests: 5.234 seconds
Complete requests: 2000
Failed requests: 0
Total transferred: 592000 bytes
HTML transferred: 60000 bytes
Requests per second: 382.10 [#/sec] (mean)
Time per request: 20.937 [ms] (mean)
Time per request: 2.617 [ms] (mean, across all concurrent requests)
Transfer rate: 110.45 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.7 0 11
Processing: 4 21 12.4 18 118
Waiting: 3 21 12.4 18 118
Total: 4 21 12.5 18 118
Percentage of the requests served within a certain time (ms)
50% 18
66% 21
75% 23
80% 25
90% 32
95% 43
98% 65
99% 76
100% 118 (longest request)
对octane
+swoole
的压测的QPS为380+
论断:QPS从110+晋升到380+,晋升幅度达到220%+,晋升很显著,但却低于冀望。官网所声称的QPS高达2000+,显著不能间接套用于生产环境。同时,如果按晋升程序来算,重构代码只是为了200%的晋升是否值得也须要好好考虑一下。
发表回复