关于laravel:Laravel-Octane-安装-RoadRunner

49次阅读

共计 4271 个字符,预计需要花费 11 分钟才能阅读完成。

在上一篇咱们实现了 SwooleLaravel 中的装置和应用,这一篇将解说 RoadRunner 的装置和应用。

装置 RoadRunner 和装置 Swoole 相似,惟一了区别是 RoadRunner 无需装置 php 的扩大。

环境要求

  1. PHP 8.0+
  2. Larave 8.35+
  3. SwooleRoadRunner 必须在 unix 零碎下装置(macOS, linux, window(WSL2))
  4. RoadRunner:请先确保 curlzip socketsphp 扩大曾经装置
  5. 虚拟机 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-mysql
This 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 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        
Server Hostname:        127.0.0.1
Server Port:            8010

Document Path:          /test-mysql
Document Length:        0 bytes

Concurrency Level:      8
Time taken for tests:   22.446 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      1048000 bytes
HTML transferred:       0 bytes
Requests 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] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:     9  178  43.9    180     360
Waiting:        9  178  43.9    180     360
Total:          9  178  43.9    180     360

Percentage 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-mysql
This 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 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        nginx/1.20.1
Server Hostname:        127.0.0.1
Server Port:            8008

Document Path:          /test-mysql
Document Length:        0 bytes

Concurrency Level:      8
Time taken for tests:   52.588 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      1134000 bytes
HTML transferred:       0 bytes
Requests 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] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:    78  419 172.2    396     986
Waiting:       78  419 172.2    396     986
Total:         78  419 172.2    396     986

Percentage 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 同样可能极大的晋升速度。

正文完
 0