5

I setup a clean Laravel 9 project. I then setup Octane with RoadRunner.

I run it on a VirtualBox VM in a Windows 11 host.

My PC:

  • CPU: Ryzen 5 3600

  • RAM: 32GB - 2x16GB DDR4 3200Mhz CL16

  • Storage: Samsung 970 Evo (Not plus), 500GB

The VM:

  • CPU: 4 Cores

  • RAM: 4GB

  • Storage: 10GB fixed

I tested and compared the performance between PHP-FPM and Octane with nginx, using wrk: https://github.com/wg/wrk

Ran the benchmark on Laravel's default homepage

These are the nginx config files for each of the setups:

  1. The Octane setup:
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

server {
    listen 80;
    listen [::]:80;
    server_name myapp.dev;
    server_tokens off;
    root /var/www/html/myapp/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 off;
    error_log  /var/log/nginx/myapp.dev-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:8000$suffix;
    }
}
  1. The PHP-FPM setup:
server {
    listen 80;
    server_name myapp.dev;
    root /var/www/html/myapp/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

The average req/sec when using PHP-FPM was higher than when using Octane. This is how I ran wrk:

wrk -t4 -c400 -d30s http://127.0.0.1:8080/index.html

I also ran octane with 4 workers:

php artisan octane:start --workers=4

The average with PHP-FPM was ~480 req/sec, and the average with Octane was ~400 req/sec

Example benchmarks:

  1. PHP-FPM:
user@server:~$ wrk -t4 -c400 -d30s http://127.0.0.1/
Running 30s test @ http://127.0.0.1/
  4 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   723.95ms   83.16ms   1.04s    81.75%
    Req/Sec   143.19     99.21   525.00     67.24%
  16381 requests in 30.10s, 293.92MB read
Requests/sec:    544.13
Transfer/sec:      9.76MB
  1. Octane:
user@server:~$ wrk -t4 -c400 -d30s http://127.0.0.1/
Running 30s test @ http://127.0.0.1/
  4 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   887.53ms  299.89ms   1.53s    61.66%
    Req/Sec   138.80    134.46   782.00     86.98%
  13340 requests in 30.04s, 238.36MB read
Requests/sec:    444.09
Transfer/sec:      7.94MB
  1. A test run with Laravel's built-in development server:
user@server:~$ wrk -t4 -c400 -d30s http://127.0.0.1:8080/
Running 30s test @ http://127.0.0.1:8080/
  4 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   767.54ms  626.07ms   1.78s    79.41%
    Req/Sec    44.60     45.79   257.00     87.16%
  2075 requests in 30.04s, 37.04MB read
  Socket errors: connect 0, read 2075, write 0, timeout 1973
Requests/sec:     69.08
Transfer/sec:      1.23M

Why?

1
  • 1
    for Octane, you are using tcp and for php-fpm you are using unix sockets ( which may perform better ). Can you set php-fpm to use tcp and see if it makes a difference ? Commented Nov 14, 2022 at 23:35

1 Answer 1

0

Make sure you have opcache enabled for the cli in your PHP config

opcache.enable_cli=1

I'm guessing php-fpm is using opcache but Roadrunner isn't.

Sign up to request clarification or add additional context in comments.

1 Comment

Roadrunner likely doesn't benefit from the opcode cache; it is inherently its own cache.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.