在上一篇咱们实现了 Swoole
在 Laravel
中的装置和应用,这一篇将解说 RoadRunner
的装置和应用。
装置 RoadRunner
和装置 Swoole
相似,惟一了区别是 RoadRunner
无需装置 php
的扩大。
环境要求
- PHP 8.0+
- Larave 8.35+
Swoole
和RoadRunner
必须在unix
零碎下装置(macOS, linux, window(WSL2))RoadRunner
:请先确保curl
,zip
sockets
等php
扩大曾经装置- 虚拟机IP:
192.168.2.11
Step1. 装置 octane
包
composer require laravel/octane
Step2. 配置 nginx 代理
map $http_upgrade $connection_upgrade { default upgrade; '' close;}server { listen 8009; # 浏览器端拜访的端口 #listen [::]:80; server_name 127.0.0.1; server_tokens off; root /var/www/html/octane/public; index index.php; charset utf-8; location /index.php { try_files /not_exists @octane; } location / { try_files $uri $uri/ @octane; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } access_log /var/log/nginx/octane-access.log main; error_log /var/log/nginx/octane-error.log error; error_page 404 /index.php; location @octane { set $suffix ""; if ($uri = /index.php) { set $suffix ?$query_string; } proxy_http_version 1.1; proxy_set_header Host $http_host; proxy_set_header Scheme $scheme; proxy_set_header SERVER_PORT $server_port; proxy_set_header REMOTE_ADDR $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_pass http://127.0.0.1:8010$suffix; # 代理申请 }}
proxy_pass
示意 http://127.0.0.1:8010
代理转发来自 http://192.168.2.110:8009
的申请
Step3. 应用 RoadRunner
1. 装置 spiral/roadrunner
# 不同版本可能体现不同,尽量用最新版本composer require spiral/roadrunner:v2.4.0
2. 公布配置文件
php artisan octane:install
输入:
Which application server you would like to use?: [0] roadrunner [1] swoole > 0
抉择 0,示意咱们抉择了 RoadRunner
3. 获取二进制文件
./vendor/bin/rr get-binary
4. 运行
php artisan octane:start --server=roadrunner --port=8010
输入:
INFO Server running… Local: http://127.0.0.1:8010 Press Ctrl+C to stop the server
看到这里,阐明装置胜利了。
5. 在浏览器中拜访
在浏览器中输出 http://192.168.2.11:8009
并回车。能够看到命令界面上会呈现 GET 申请。
能够看到,只有前两次申请的工夫比拟长,前面的申请只有几毫秒
Step4. ab 压测
跟 Swoole
的压测一样,压测命令:
ab -n 1000 -c 8 http://127.0.0.1:8010/
-n 1000
: 指定测试会话应用的申请数为1000-c 8
: 并发数为8
应用 octane
的压测后果
[root@localhost octane]# ab -n 1000 -c 8 http://127.0.0.1:8010/test-mysqlThis is ApacheBench, Version 2.3 <$Revision: 1430300 $>Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/Licensed to The Apache Software Foundation, http://www.apache.org/Benchmarking 127.0.0.1 (be patient)Completed 100 requestsCompleted 200 requestsCompleted 300 requestsCompleted 400 requestsCompleted 500 requestsCompleted 600 requestsCompleted 700 requestsCompleted 800 requestsCompleted 900 requestsCompleted 1000 requestsFinished 1000 requestsServer Software: Server Hostname: 127.0.0.1Server Port: 8010Document Path: /test-mysqlDocument Length: 0 bytesConcurrency Level: 8Time taken for tests: 22.446 secondsComplete requests: 1000Failed requests: 0Write errors: 0Total transferred: 1048000 bytesHTML transferred: 0 bytesRequests per second: 44.55 [#/sec] (mean)Time per request: 179.566 [ms] (mean)Time per request: 22.446 [ms] (mean, across all concurrent requests)Transfer rate: 45.60 [Kbytes/sec] receivedConnection Times (ms) min mean[+/-sd] median maxConnect: 0 0 0.1 0 1Processing: 9 178 43.9 180 360Waiting: 9 178 43.9 180 360Total: 9 178 43.9 180 360Percentage of the requests served within a certain time (ms) 50% 180 66% 194 75% 213 80% 221 90% 234 95% 242 98% 250 99% 255 100% 360 (longest request)
**再看看不应用 octane
的压测后果:
[root@localhost octane]# ab -n 1000 -c 8 http://127.0.0.1:8008/test-mysqlThis is ApacheBench, Version 2.3 <$Revision: 1430300 $>Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/Licensed to The Apache Software Foundation, http://www.apache.org/Benchmarking 127.0.0.1 (be patient)Completed 100 requestsCompleted 200 requestsCompleted 300 requestsCompleted 400 requestsCompleted 500 requestsCompleted 600 requestsCompleted 700 requestsCompleted 800 requestsCompleted 900 requestsCompleted 1000 requestsFinished 1000 requestsServer Software: nginx/1.20.1Server Hostname: 127.0.0.1Server Port: 8008Document Path: /test-mysqlDocument Length: 0 bytesConcurrency Level: 8Time taken for tests: 52.588 secondsComplete requests: 1000Failed requests: 0Write errors: 0Total transferred: 1134000 bytesHTML transferred: 0 bytesRequests per second: 19.02 [#/sec] (mean)Time per request: 420.705 [ms] (mean)Time per request: 52.588 [ms] (mean, across all concurrent requests)Transfer rate: 21.06 [Kbytes/sec] receivedConnection Times (ms) min mean[+/-sd] median maxConnect: 0 0 0.1 0 1Processing: 78 419 172.2 396 986Waiting: 78 419 172.2 396 986Total: 78 419 172.2 396 986Percentage of the requests served within a certain time (ms) 50% 396 66% 510 75% 568 80% 591 90% 655 95% 706 98% 740 99% 761 100% 986 (longest request)
从下面的两种后果能够看到,RoadRunner
同样可能极大的晋升速度。