Laravel Rust vs Laravel PHP: I Repeated the Official Benchmark on Hetzner

2026-12-02来源 dev.toEnglish
Laravel Rust vs Laravel PHP: I Repeated the Official Benchmark on Hetzner

Originally published at hafiz.dev

On 1 December, Laravel published a benchmark of Laravel Rust, its new full stack Rust framework. The post's title puts it at 18 times the throughput of Laravel PHP. Sam Rose ran it on Laravel Cloud, put both apps and the k6 script on GitHub, and asked readers to get in touch if they found mistakes in his testing.

So I ran it again, on servers I rented by the hour from Hetzner. Same apps, same k6 script (checked against the official file's SHA-256), and MySQL 8.4 like the original. Then I added the two setups a lot of us actually run: nginx with PHP-FPM, and a €7 VPS with everything on one box. That came to 34 measured runs (plus 3 setup checks) and about €2 of servers, all deleted afterwards.

Laravel Rust served 11 to 13 times what Octane did on every server I tried. Not 18. But the gap survived every change I made.

The results

Server Laravel Rust Octane + FrankenPHP nginx + PHP-FPM Rust vs Octane
1 dedicated vCPU, 4 GiB 1,991.4 (hit the cap) 166.9 92.5 at least 11.9×
€7 VPS, 2 shared vCPU, 4 GB 1,012.6 90.3 61.9 11.2×
Same VPS booted as 1 vCPU, 961 MiB 562.3 44.5 31.0 12.6×

The numbers are requests per second in the best 10-second window with no failed request, which is the official method. Both VPS rows are the median of three rounds. On the dedicated vCPU, MySQL ran on its own server. On the VPS, nginx, the app and MySQL shared the box.

View the interactive component on hafiz.dev

For reference, Laravel's run on Cloud measured 1,774 requests per second for Laravel Rust and 97 for Laravel PHP, which is Octane on FrankenPHP.

How I tested

Four servers in Hetzner's Helsinki region, all on Ubuntu 24.04 and a private network, behind a firewall that only lets SSH in. A spread placement group put each one on a different physical host.

Server Hetzner type Job
bench-k6 ccx13, 2 dedicated vCPU, 8 GB k6 2.3.0, the same size as Laravel's load generator
bench-db ccx13, 2 dedicated vCPU, 8 GB MySQL 8.4.13 for the dedicated test
bench-app ccx23, 4 dedicated vCPU (AMD EPYC Milan), 16 GB the app on one vCPU, nginx on another core
bench-vps cx23, 2 shared vCPU (Intel Xeon Skylake), 4 GB nginx, app and MySQL together

Laravel Cloud gave each app a container with 1 vCPU and 4 GiB. On a VPS, the same budget takes two systemd drop-ins. Each app's service joins a slice with a memory cap and gets pinned to vCPU 0:

# /etc/systemd/system/benchapp.slice.d/50-limits.conf [Slice] MemoryMax=4G MemorySwapMax=0 # /etc/systemd/system/bench-rust.service.d/50-bench.conf [Service] Slice=benchapp.slice CPUAffinity=0 

The Octane and PHP-FPM services got the same drop-in. Versions: Laravel Rust 0.1.0 built with Rust 1.99.1, FrankenPHP 1.13.6 with PHP 8.5.13, PHP-FPM 8.5 from packages.sury.org and MySQL 8.4.13. From the official README I copied OCTANE_WORKERS=4, DB_MAX_CONNECTIONS=20 for Rust and APP_ENV=production.

PHP-FPM ran pm = static, with OPcache on and validate_timestamps=0. I picked its worker count by testing. With 4, 8 and 16 workers, all three were overloaded at 150 requests per second, and 8 had the fewest failures. The 2 vCPU VPS ran 16 workers, and the 1 vCPU boot ran 8.

What I changed, and why

  • gzip moved to nginx. Cloud's edge compresses responses, and neither app compresses by itself, except Octane's Caddyfile, which has encode @compressible zstd br gzip. So nginx did the compression (on its own vCPU on the dedicated box) and stripped Accept-Encoding before passing requests on. I also ran Octane once with compression inside the app. It served 156 requests per second instead of 167, about 7% less.
  • No TLS in front of the app. k6 sent plain HTTP over the private network. Laravel's run went through a public HTTPS hostname, so my latencies are lower in absolute terms.
  • TLS to MySQL on the dedicated test. Laravel Rust's driver (sqlx 0.9, built without its rsa feature) can't log in to MySQL 8.4 over plain TCP. So both apps reached bench-db over TLS with a verified certificate. On the VPS, both used the Unix socket.
  • FrankenPHP pinned to 1.13.6. By default Octane downloads the latest FrankenPHP release. That was 1.14.0, which ships PHP 8.6.
  • A shorter ramp for PHP. The official ramp climbs from 1 to 2,000 requests per second over 20 minutes. Octane's first run got the full ramp and never passed 167, so the later PHP runs used the same slope and stopped at 500. Rust always got the full ramp.

Laravel's result holds, at 11 to 13× instead of 18×

Laravel Rust climbed the whole 20-minute ramp without a single failed request, 1,200,442 successful responses in total. Its best window came at 19 minutes 50 seconds, with 1,991 requests per second and a p95 of 44 ms. The app itself peaked at 56% of its vCPU.

k6 report for Laravel Rust on one dedicated vCPU. The request rate climbs steadily to 2,000 per second, the p95 line stays low apart from one spike, and the failure line stays at zero.

That 1,991 is a floor, not Rust's ceiling. The official ramp stops at 2,000, and by then the k6 server was close to 100% CPU. Over the run, k6 couldn't start 138 of its scheduled requests (none in the best window). So the real limit of Laravel Rust on one EPYC vCPU is somewhere above 2,000, and I didn't measure it.

Octane went the other way.

k6 report for Octane with FrankenPHP on one dedicated vCPU. The request rate climbs to about 180 per second, then the p95 line jumps to the 5-second timeout and failures sit near 100% for the rest of the run.

Its best clean window came at 1 minute 50 seconds, with 167 requests per second and a p95 of 1.5 seconds. Thirty seconds later requests started failing, and they kept failing until the end. Over the 20 minutes, Octane completed 21,729 requests and 309,920 timed out. Not one was a 5xx error. Every failure was k6 giving up after 5 seconds. The flat line near 300 per second in the chart is what 1,500 virtual users (the script's cap) produce when each one waits out a 5-second timeout.

So why 11 to 13× and not 18×? On my dedicated vCPU, Octane did better than on Cloud (167 against 97), while Rust ran into the ramp's ceiling. I can't tell you exactly why Octane was faster here. The CPUs differ, my requests skipped TLS and Cloud's edge, and the region is different. But the ratio barely moved across three very different servers (11.9, 11.2 and 12.6).

PHP-FPM came last everywhere. Octane served 1.4 to 1.8 times as much on the same box.

On a small VPS, the whole machine is the limit

On the €7 VPS, nginx, MySQL and the app compete for the same two shared vCPUs. During Rust's runs the app peaked at about 120% of one vCPU, MySQL at 60% and nginx at 22%. That adds up to the whole box, which hit 99% CPU. So 1,013 is the limit of this VPS with Rust on it, not the limit of Rust.

The 1 vCPU boot shows the same thing with memory. I started the same VPS with maxcpus=1 mem=1G, which leaves 961 MiB, and recorded htop for a minute, starting 3 minutes into each ramp. This is Rust:

htop on the 1 vCPU, 961 MiB VPS during the Laravel Rust ramp. The CPU is at 75%, chirper-laravel-rust uses 39.4% CPU and 24 MB of resident memory, and mysqld holds 486 MB, half of the machine's memory.

The Rust binary used 24 MB of resident memory. MySQL used 486 MB, half the machine. On a box this size, the database is the heavy process, whatever language the app is written in.

Octane at the same point in its ramp had the CPU at 100%, with FrankenPHP using 192 MB:

htop during the Octane ramp on the same 1 vCPU box. The CPU is at 100%, frankenphp uses 81.9% CPU and 192 MB of resident memory, and mysqld holds 476 MB.

Past its limit, PHP falls over instead of slowing down

The steady test sends 50 requests per second for 5 minutes. On the 1 vCPU, 961 MiB VPS, that's above both PHP limits (44.5 and 31). The result isn't a gentle slowdown:

50 req/s on 1 vCPU, 961 MiB Served per second Failed p95 over the run
Laravel Rust 50.0 0.0% 17 ms
Octane + FrankenPHP 16.6 66.7% 4,995 ms
nginx + PHP-FPM 1.2 97.6% 4,759 ms

At its limit, Octane served 44.5 requests per second. Pushed 5.5 past it, it served 16.6. Once requests wait longer than the client does, the server spends its CPU on responses nobody will read, and new requests queue behind them.

The PHP-FPM worker test on the dedicated box shows the same pattern. With 4 workers at 150 requests per second, the best 10-second window served 86 per second. Averaged over the 3-minute hold, it served 7.1.

htop during the PHP-FPM ramp on the 1 vCPU box. Eight php-fpm workers each use about 10% CPU, all in the running state, and the CPU is at 100%.

Laravel Rust never got there in my runs. It had zero failed requests in all seven of its ramps. Past its limit, its latency grew instead. On the 1 GB box its p95 over the whole ramp was about 3.5 seconds, but not one request hit k6's 5-second timeout.

So know where your PHP app's ceiling is, and keep real traffic well below it. In these runs there was no slow band between fine and down.

The OOM killer picked MySQL, three times

On the 1 vCPU, 961 MiB VPS, the kernel ran out of memory three times. That was once in the first PHP-FPM round, and again in the second and third Octane rounds. Each time it killed MySQL, the process with the most memory. It never happened during a Rust run. This is the third one, from the kernel log:

Dec 02 13:26:09 bench-vps kernel: nginx invoked oom-killer: gfp_mask=0x140cca(GFP_HIGHUSER_MOVABLE|__GFP_COMP), order=0, oom_score_adj=0 Dec 02 13:26:09 bench-vps kernel: Out of memory: Killed process 6561 (mysqld) total-vm:1405416kB, anon-rss:480632kB, file-rss:2816kB, shmem-rss:0kB, UID:108 pgtables:1368kB oom_score_adj:0 

In the two Octane rounds, the app logged Connection refused for about 5 seconds, until MySQL was back. In a real app, every page that touches the database fails for those seconds, because of traffic the app couldn't serve anyway.

If you run MySQL and PHP on a 1 GB box, decide which process the kernel should take before it decides for you. systemd's OOMScoreAdjust= is the setting for that, although I didn't test it here.

A cheap shared vCPU is not a dedicated vCPU

The steady 50 requests per second also ran on the dedicated EPYC vCPU and on the €7 VPS with its two shared Skylake vCPUs. Same apps, same load, very different CPU bills:

View the interactive component on hafiz.dev

Rust needed 4.9 times as much CPU on the shared vCPU, Octane 3.9 times and PHP-FPM 2.8 times. Both PHP setups used more than one full vCPU of the VPS for just 50 requests per second. So "1 vCPU" isn't a unit you can compare between a €7 plan and a dedicated one. Benchmark on the plan you'll actually pay for.

Memory at 50 requests per second on the dedicated box was small for all three. Laravel Rust used 6.7 MiB of its own memory, Octane 88.9 MiB and PHP-FPM 27.9 MiB. With the file cache the kernel charges to the app (binary, PHP files, OPcache) it was 114, 220 and 162 MiB. Laravel reported 16M and 134M on Cloud, measured with Cloud's own metrics, so compare the ratios rather than the values.

Requests per euro

Hetzner charges €6.70 a month for the cx23 plus €0.61 for its IPv4 address, VAT included. A dedicated vCPU is a quarter of a ccx23, which is €22.26. Taking each best window as a rate held for a 30-day month:

Requests per € per month Laravel Rust Octane PHP-FPM
€7 VPS, 2 shared vCPU 359 M 32 M 22 M
1 dedicated vCPU 232 M (at least) 19 M 11 M

The €7 VPS wins for every runtime. It served half to two thirds of what the dedicated vCPU did, for a third of the price, and that price includes the database server. I went through the wider Cloud vs Forge vs VPS cost question in an earlier post.

In absolute terms, Octane's 90 requests per second on the €7 VPS is 7.8 million requests a day. Laravel Rust's 1,013 is 87.5 million.

What this means for your app

The benchmark API is small. It serves a paginated feed and single chirps from MySQL, over 10 authors and 200 chirps. With work that light, the framework is most of each request, and that's where a compiled runtime pulls furthest ahead. In an app whose requests spend most of their time in the database, the gap should shrink, because a slow query costs the same whichever runtime sends it. If your pages are slow, the right index or a rewritten query will usually buy you more than a new runtime.

If you're on PHP-FPM, Octane is the cheaper step. It served 1.4 to 1.8 times as much on the same box, with no rewrite. It does keep your app in memory between requests, which brings its own bugs, and I compared FrankenPHP, Swoole and RoadRunner for Octane separately.

Laravel Rust is at version 0.1.0. A release build took 181.8 seconds on 4 dedicated vCPUs and 657.4 seconds on the €7 VPS, against 3.6 seconds for composer install. Laravel's own median build on Cloud was 3 minutes 1 second. The binary is 32.8 MB.

I wouldn't rewrite a working Laravel app for this. I'd try it first on a new service with one hot endpoint, or on something that has to live on a tiny box. My next test ports the read path of a real Laravel app to Laravel Rust, to see how much of the 12× survives real queries.

Limits of this test

  • Rust's ceiling on the dedicated vCPU is unmeasured. The k6 server was close to 100% CPU near the 2,000 cap, so part of the 44 ms p95 may be the load generator queueing. The requests per euro for that row are a lower bound.
  • Plain HTTP on a private network. Laravel's requests crossed TLS and Cloud's edge, so compare my latencies with each other, not with theirs.
  • Latency near the limit swings between rounds. Octane on the €7 VPS had a best-window p95 between 398 ms and 2.9 seconds across three rounds, while its throughput only moved between 88 and 95. That's why I lead with throughput.
  • Two memory figures. "Its own memory" is the app's anonymous memory. The larger figure adds file cache.
  • htop ran during the third round on 1 vCPU, using about 1% CPU (2% with its tmux session). Rust's third round matched the other two (564, 562 and 562).
  • One region, one day, one small API.

Reproduce it

The apps and the k6 script are in Laravel's benchmark repo at commit c506879, and its README covers every setting I copied. My runs kept the official benchmark.js byte for byte. The extra profiles (the 500 cap and a fixed-rate hold) live in a separate script. That script, my server setup and the results of every run are in hzeeshan/laravel-rust-bench. Credit to Sam Rose for publishing everything needed to check his work. Without that, this post would be a guess.

FAQ

Should I rewrite my Laravel app in Laravel Rust?

Probably not yet. It's at version 0.1.0, a release build takes minutes instead of seconds, and the gap I measured comes from a tiny API where the framework is most of the work. If your app is slow because of its queries, a new runtime won't fix that. Try it on a new service with one hot endpoint first.

Why are these numbers different from Laravel's?

The hardware is different, no TLS or edge sat between k6 and the app, and the region is different. Octane did better on my dedicated vCPU (167 against 97), and Rust hit the 2,000 cap, so the ratio came out at 11 to 13× instead of 18×. The direction and the order of magnitude match.

Is Octane worth it on a cheap VPS?

On the €7 VPS it served 90 requests per second against 62 for PHP-FPM, and 44.5 against 31 on the 1 GB boot. That's about 1.4 to 1.5 times as much, with no code changes. But on 1 GB, MySQL also got killed twice during Octane runs. Give it memory headroom.

原文:https://www.a8q9.cn/en/article/laravel-rust-vs-laravel-php-i-repeated-the-official-benchmark-on-hetzner-bb336f.html

相关文章