Skip to content

Instantly share code, notes, and snippets.

@robwilde
Forked from viezel/test-octane.md
Created April 22, 2023 00:47
Show Gist options
  • Select an option

  • Save robwilde/daba71fdb4b06ea84f25f50546e2481c to your computer and use it in GitHub Desktop.

Select an option

Save robwilde/daba71fdb4b06ea84f25f50546e2481c to your computer and use it in GitHub Desktop.

Revisions

  1. @viezel viezel revised this gist Apr 7, 2021. 1 changed file with 88 additions and 3 deletions.
    91 changes: 88 additions & 3 deletions test-octane.md
    Original file line number Diff line number Diff line change
    @@ -2,12 +2,97 @@

    I wanted to quickly take Laravel Octane beta for a spin, as we have been using Swoole for some time and wanted to see how official support performs vs what we have.


    ## Setup
    ## Test 2: Forge server

    Next test is more real world as we now have a web server and database server within a VPC.

    Using Laravel Forge

    - App server: PHP 8.0.3, AWS t3.small - 2 vCPUs, 2 GB RAM
    - Database: AWS RDS MySQL 8.0 db.t3.micro, 2 vCPUs, 1 GB RAM - using private VPC
    - SSL certificate

    We will use opcache, cache route and config in Laravel, and adjust settings for performance.

    We test for 3 min, using 8 threads and 200 connections each.

    **PHP-FPM Settings**

    pm = dynamic
    pm.max_children = 100
    pm.start_servers = 20
    pm.min_spare_servers = 20
    pm.max_spare_servers = 40


    **Nginx - Swoole**

    upstream swoole-http {
    server 127.0.0.1:8000;
    }

    map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
    }
    server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name octane.example.com;
    server_tokens off;
    root /home/forge/octane.example.com/public;
    index index.php;
    charset utf-8;

    # FORGE CONFIG (DO NOT REMOVE!)
    include forge-conf/octane.example.com/server/*;

    location = /index.php {
    try_files /not_exists @swoole;
    }

    location / {
    try_files $uri $uri/ @swoole;
    }

    location @swoole {
    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://swoole-http$suffix;
    }
    }


    - `wrk -t8 -c200 -d3m https://testdomain.com/api/ping`
    - `wrk -t8 -c200 -d3m https://testdomain.com/api/users`
    - `wrk -t8 -c200 -d3m https://testdomain.com/api/users/1`

    | Route | Nginx to PHP-FPM on AWS t3.small, RDS db.t3.micro | Nginx to Octane Swoole on AWS t3.small, RDS db.t3.micro |
    |:--------------:|:-------------------------------------------------:|:-------------------------------------------------------:|
    | /api/ping | 295 req/sec, 98% App CPU | 832 req/sec, 84% App CPU |
    | /api/users | 77 req/sec, 85% App CPU, 88% DB CPU, 90 DB conn | 113 req/sec, 29% App CPU, 54% DB CPU, 4 DB conn |
    | /api/users/:id | 189 req/sec, 91% App CPU, 10% DB CPU, 16 DB conn | 453 req/sec, 61% App CPU, 6% DB CPU, 2 DB conn |



    ## Test 1 - Setup

    - Macbook Pro 2019
    - Laravel 8.35.1
    - Laravel Octane beta
    - Laravel Octane 0.1.0 beta
    - Laravel Sail
    - Wrk

  2. @viezel viezel revised this gist Apr 7, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion test-octane.md
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ I wanted to quickly take Laravel Octane beta for a spin, as we have been using S
    ## Setup

    - Macbook Pro 2019
    - Laravel 8.12
    - Laravel 8.35.1
    - Laravel Octane beta
    - Laravel Sail
    - Wrk
  3. @viezel viezel revised this gist Apr 6, 2021. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions test-octane.md
    Original file line number Diff line number Diff line change
    @@ -59,6 +59,8 @@ All the tests have been conducted on my MacBook Pro 2019 using Docker. Im sure u
    | /api/users | 82 req/sec | 152 req/sec | 201 req/sec |
    | /api/users/:id | 104 req/sec | 290 req/sec | 545 req/sec |

    All the tests have been conducted on my MacBook using Docker. Im sure using native would yield much better performance. However, we care about the difference - not so much about the actaul numbers.


    Again, very quick tests - but for now it looks promising.

  4. @viezel viezel revised this gist Apr 6, 2021. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions test-octane.md
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,10 @@ I wanted to quickly take Laravel Octane beta for a spin, as we have been using S
    - Laravel Sail
    - Wrk


    Basic Laravel app with 5000 users seeded into the database. Only installed Sail and Octane packages. Otherwise 100% vanilla setup.


    ### Test Routes


  5. @viezel viezel created this gist Apr 6, 2021.
    60 changes: 60 additions & 0 deletions test-octane.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    # Intro

    I wanted to quickly take Laravel Octane beta for a spin, as we have been using Swoole for some time and wanted to see how official support performs vs what we have.


    ## Setup

    - Macbook Pro 2019
    - Laravel 8.12
    - Laravel Octane beta
    - Laravel Sail
    - Wrk

    ### Test Routes


    ```php
    Route::get('/users', function () {
    return response()->json(User::query()->paginate());
    });

    Route::get('/users/{userId}', function (int $userId) {
    return response()->json(User::query()->findOrFail($userId));
    });

    Route::get('/ping', function() {
    return response()->json(['message' => 'pong']);
    });
    ```

    | Route | Response | MySQL |
    |:-----:|:--------:|:-----:|
    | /api/ping | Returns a string | No |
    | /api/users | Returns a paginated list of users | Yes |
    | /api/users/:id | Returns a user | Yes |

    - `wrk -t4 -c50 -d30s http://localhost/api/ping`
    - `wrk -t4 -c50 -d30s http://localhost/api/users`
    - `wrk -t4 -c50 -d30s http://localhost/api/users/1`

    ### Test Results

    All the tests have been conducted on my MacBook Pro 2019 using Docker. Im sure using native would yield better performance. However, we care about the difference - not so much about the actaul numbers.

    ### Tests

    1. Nginx to PHP-FPM: classic nginx to fpm setup using docker
    2. Nginx proxy to Swoole. Using Laravel-swoole package and nginx
    3. Laravel Octane beta and Sail


    | Route | Nginx to PHP-FPM | Nginx to Swoole | Octane Swoole HTTP |
    |:--------------:|:-----------------:|:---------------:|:------------------:|
    | /api/ping | 131 req/sec | 369 req/sec | 766 req/sec |
    | /api/users | 82 req/sec | 152 req/sec | 201 req/sec |
    | /api/users/:id | 104 req/sec | 290 req/sec | 545 req/sec |


    Again, very quick tests - but for now it looks promising.