← all posts

Benchmarking Laravel Rust and Laravel Go against Laravel on PHP

Laravel Rust, Laravel Go and Laravel on PHP, measured on the same servers.

Laravel now comes in three languages. Laravel Rust is a separate framework, written from scratch on Axum and Tokio, that keeps Laravel’s shape: routes, handlers, an Eloquent-style ORM, migrations, queues, Jinja views and Inertia. Laravel Go does the same on Go’s standard net/http, with html/template views. Both are pre-1.0: I tested Laravel Rust 0.1.4 and Laravel Go 0.1.0.

The Rust launch page quotes 18 times the throughput of Laravel on PHP, 8 times less memory and 4 times faster wake-up from scale-to-zero, all measured on Laravel Cloud. The Go page promises “massive throughput” without numbers. Neither test application is published, so I wanted numbers I could reproduce: the same small application written in all three, on ordinary servers, against the PHP setups people actually run in production.

The short version is that both new versions are in a different league from PHP. With default settings, Laravel Rust served 5.8 to 22 times as many requests as the fastest PHP setup, and Laravel Go 4 to 13 times. At the same traffic, Rust used 5 to 12 times less CPU than Octane, and Go 2 to 4 times less. Between the two, Go came close to Rust on simple endpoints, fell to about half its speed on the heaviest ones, and used the least memory of anything I tested.

The application

I wrote one application three times. The Rust and Go versions start from the official laravel/rust and laravel/go skeletons, and the PHP version from a fresh laravel new on Laravel 13 and PHP 8.5. Each has a Post model that belongs to a User, and the same five endpoints:

EndpointWork
Static JSONReturns a constant JSON object. Nothing but framework overhead.
One post by idFinds a post by primary key and returns it as JSON.
20 posts with authorsThe 20 newest posts with their authors eager loaded, as JSON. Two queries.
Increment a counterLoads a post and atomically increments its votes column.
Rendered HTML pageThe same 20 posts rendered through a layout and a view, with sessions and CSRF.

Each framework created its schema with its own migrations, and the resulting tables matched column for column. The same seed script then loaded 1,000 users and 10,000 posts into each database. Requests for a single post pick a random id, so no stack repeats one identical query.

The handlers are the idiomatic version in each framework. In Rust, the list endpoint is:

Post::query()
    .with(Post::user)
    .order_by(Post::published_at.desc())
    .limit(20)
    .get()
    .await

in Go:

model.Query[models.Post]().
    With("user").
    OrderByDesc("published_at").
    Limit(20).
    Get(ctx)

and in PHP it is the Eloquent equivalent:

Post::query()
    ->with('user')
    ->orderByDesc('published_at')
    ->limit(20)
    ->get();

Five ways to run it

The Rust and Go applications each compile to one binary, and I ran them the way their deployment guides describe. PHP has more choices, and they differ enough that comparing against only one would be misleading:

StackHow it runs
Laravel RustThe release binary.
Laravel GoThe go build binary.
OctaneLaravel Octane on FrankenPHP in worker mode. The application boots once per worker and stays in memory.
FrankenPHP classicFrankenPHP without Octane. The application boots on every request.
nginx + PHP-FPMThe traditional setup. The application boots on every request.

Every PHP stack ran with opcache enabled, timestamp validation off, and php artisan optimize. All three skeletons keep sessions in the database by default. I switched all three to cookie sessions, so the rendered page makes no extra queries for its session.

I measured each stack twice. The first pass used defaults, apart from those production basics. The second combined the settings that won a short sweep for each stack: persistent database connections and the tracing JIT for PHP, 16 Octane workers instead of 8, and a database pool of 64 connections instead of 10 for Rust and Go.

The setup

All of it ran on Hetzner Cloud, in one location, on a private network:

  • an application server with 4 dedicated AMD EPYC vCPUs and 16 GB of memory, running one stack at a time
  • a second server of the same size running Postgres 18
  • a third, larger server generating load with oha

Each endpoint got a 10-second warm-up and then three 30-second runs with 64 concurrent connections. The tables use the median run. For a typical endpoint the three runs were within 1% of each other. The counter endpoint was the exception, with up to 18% between runs; for Rust and Go at default settings each run was a little slower than the one before. Each counter run updates the same 10,000 rows for minutes at a time, and I read its figures as the least precise in this post. A sampler read the application container’s CPU time and memory straight from its cgroup twice a second.

Across 175 timed runs there were no failed requests and no non-2xx responses.

Throughput

Requests per second, default settings
Values in req/s, higher is better, each panel has its own scale.
Static JSON
  • Laravel Rust: 58,231
  • Laravel Go: 44,587
  • Octane: 3,371
  • FrankenPHP classic: 1,437
  • PHP-FPM: 1,697
One post by id
  • Laravel Rust: 25,601
  • Laravel Go: 20,828
  • Octane: 1,943
  • FrankenPHP classic: 358
  • PHP-FPM: 424
20 posts with authors
  • Laravel Rust: 9,436
  • Laravel Go: 4,920
  • Octane: 425
  • FrankenPHP classic: 214
  • PHP-FPM: 250
Increment a counter
  • Laravel Rust: 8,599
  • Laravel Go: 7,156
  • Octane: 1,487
  • FrankenPHP classic: 342
  • PHP-FPM: 413
Rendered HTML page
  • Laravel Rust: 5,743
  • Laravel Go: 3,474
  • Octane: 866
  • FrankenPHP classic: 286
  • PHP-FPM: 336
Show the numbers
EndpointLaravel RustLaravel GoOctaneFrankenPHP classicPHP-FPM
Static JSON58,23144,5873,3711,4371,697
One post by id25,60120,8281,943358424
20 posts with authors9,4364,920425214250
Increment a counter8,5997,1561,487342413
Rendered HTML page5,7433,474866286336
Median of three 30-second runs with 64 connections.

With default settings, Laravel Rust served between 5.8 and 22 times as many requests as Octane, the fastest PHP option, and Laravel Go between 4 and 13 times. Against PHP-FPM, the multiples were 17 to 60 for Rust and 10 to 49 for Go.

The gap is widest where the framework does the most work in the application itself. Returning 20 posts with their authors as JSON means building up to 40 models and serializing them. Rust did that 9,436 times a second, Go 4,920 times, and Octane 425. The gap is narrowest on the rendered page and on the counter, for two different reasons. The page runs the same two queries as the list, but Rust and Go spend more on it than on the JSON, with a session, encrypted cookies and a template to render, while Octane renders the page twice as fast as it returns the JSON. I come back to that below. The counter is limited by database connections at default settings, not by the application.

The 20-post list and the rendered page are also where Rust and Go separate. On the static response, the single post and the counter, Go reached 77% to 83% of Rust’s throughput. On those two, which build the most models, it reached 52% and 60%.

With each stack at its best settings, the gap to Octane barely moves. Against PHP-FPM it shrinks, from 17 to 60 times for Rust down to 9 to 34 times, because persistent connections and the JIT lift PHP-FPM:

EndpointLaravel RustLaravel GoOctaneFrankenPHP classicPHP-FPMRust vs OctaneGo vs Octane
Static JSON58,41142,6033,5561,5961,73616.4x12.0x
One post by id27,38323,1822,29290799411.9x10.1x
20 posts with authors10,2715,13845932942522.4x11.2x
Increment a counter15,44614,8882,0178469797.7x7.4x
Rendered HTML page5,8463,6899655236416.1x3.8x
Requests per second with tuned settings, median of three 30-second runs.

With tuned settings, the application server’s four cores were at least 80% busy in every run, so those numbers measure the application, not the database or the load generator. At default settings, the counter endpoint stopped well short of that, because it holds a database connection for two round trips per request. Octane used 2.9 cores and FrankenPHP classic 3.2, because their 8 workers were often all waiting on the database at once. Laravel Rust used 2.1 cores and Laravel Go 2.2, because their default pool of 10 connections ran out first. With 64 connections, Rust went from 8,599 to 15,446 requests a second and Go from 7,156 to 14,888, close enough that the counter is the one endpoint where the two are effectively tied.

The same traffic, less CPU

Most applications never run at their maximum throughput, so I also ran every stack at a fixed request rate, set to roughly 60% to 75% of what PHP-FPM can sustain on each endpoint. At equal load, the question becomes how much of the server each stack needs:

CPU used at a fixed request rate, default settings
Values in cores, lower is better.
Static JSON at 1,000/s
  • Laravel Rust: 0.20
  • Laravel Go: 0.46
  • Octane: 1.45
  • FrankenPHP classic: 2.33
  • PHP-FPM: 2.07
One post by id at 300/s
  • Laravel Rust: 0.11
  • Laravel Go: 0.29
  • Octane: 1.05
  • FrankenPHP classic: 2.56
  • PHP-FPM: 2.31
20 posts with authors at 150/s
  • Laravel Rust: 0.12
  • Laravel Go: 0.45
  • Octane: 1.46
  • FrankenPHP classic: 2.13
  • PHP-FPM: 1.87
Increment a counter at 300/s
  • Laravel Rust: 0.16
  • Laravel Go: 0.41
  • Octane: 1.15
  • FrankenPHP classic: 2.62
  • PHP-FPM: 2.38
Rendered HTML page at 200/s
  • Laravel Rust: 0.26
  • Laravel Go: 0.73
  • Octane: 1.30
  • FrankenPHP classic: 2.08
  • PHP-FPM: 1.90
Show the numbers
EndpointLaravel RustLaravel GoOctaneFrankenPHP classicPHP-FPM
Static JSON at 1,000/s0.200.461.452.332.07
One post by id at 300/s0.110.291.052.562.31
20 posts with authors at 150/s0.120.451.462.131.87
Increment a counter at 300/s0.160.411.152.622.38
Rendered HTML page at 200/s0.260.731.302.081.90
The rate for each endpoint is in its label. The server has 4 cores.

Serving 300 single-post requests a second took Laravel Rust a ninth of one core and Laravel Go under a third. Octane needed a whole core, and PHP-FPM more than two. That is the number that decides how many servers an application needs.

Latency at the same rates followed the same order. For the single post, the 99th percentile was 2.0 ms for both Rust and Go, 7.8 ms for Octane and 31 ms for PHP-FPM. There were two outliers. On Rust’s rendered page, the slowest 0.1% of requests took 207 ms while the 99th percentile was 4.4 ms, which looks like a single pause during that run. On PHP-FPM’s counter, the 99th percentile was 123 ms, against 31 to 35 ms on its other database-backed endpoints.

Memory and cold starts

Memory used by the application container, default settings
Values in MiB, lower is better.
Idle
  • Laravel Rust: 18
  • Laravel Go: 5
  • Octane: 134
  • FrankenPHP classic: 52
  • PHP-FPM: 53
Peak under load
  • Laravel Rust: 59
  • Laravel Go: 26
  • Octane: 125
  • FrankenPHP classic: 77
  • PHP-FPM: 92
Show the numbers
StateLaravel RustLaravel GoOctaneFrankenPHP classicPHP-FPM
Idle1851345253
Peak under load59261257792
Idle is right after start. The peak is the highest sample across all five throughput runs.

Idle, the Go container used 5 MiB, the Rust container 18 MiB and the Octane container 134 MiB. Under full load the gap narrowed, but Go still peaked at 26 MiB and Rust at 59 MiB.

The launch page’s figures, 16 MB for Rust and 134 MB for PHP, were recorded at a steady 50 requests a second. My fixed-rate runs are the closest match: there Octane used 134 to 136 MiB and Rust 26 to 35 MiB.

Octane is the odd one out: it used the most memory right after it started, when each of its workers had just booted Laravel, and settled lower under load. Keeping a booted copy of the application in every worker is the cost of its speed. PHP-FPM and FrankenPHP classic boot per request and hold less in memory between requests.

I also timed how long each container took from docker start to its first successful database-backed response, ten times each:

StackMedianRange
Laravel Rust226 ms184–253 ms
Laravel Go227 ms172–236 ms
PHP-FPM406 ms383–434 ms
FrankenPHP classic408 ms392–431 ms
Octane789 ms752–823 ms

These include starting the container itself, so they are not directly comparable to the Rust launch page’s wake-up times (154 ms against 712 ms, a ratio of 4.6). Here Rust started 3.5 times faster than Octane and 1.8 times faster than PHP-FPM. Octane is the slowest to start because it boots Laravel in each of its workers before it accepts requests.

What surprised me

FrankenPHP is fast because of worker mode. Without Octane, FrankenPHP was slower than nginx and PHP-FPM on all five endpoints: by 14% to 17% with default settings, and by 8% to 23% with tuned settings. The difference between Octane and FrankenPHP classic comes from not booting Laravel on every request.

Persistent connections were the biggest PHP setting by far. PHP-FPM opens a new database connection for every request by default. With tuned settings, PHP-FPM’s single-post endpoint went from 424 to 994 requests a second, and in the sweep beforehand nearly all of that came from turning on PDO::ATTR_PERSISTENT.

Turning models into JSON was expensive in PHP. Octane rendered the HTML page faster (866 per second) than it returned the same 20 posts as JSON (425 per second), even though the page also starts a session and sets encrypted cookies. My reading is that the view touches a few attributes, while the JSON response serializes every column and every date of every model. Laravel Rust and Laravel Go went the other way: their JSON lists were faster than their rendered pages.

What this does and does not show

This is a small CRUD application on one size of server. A real application spends more of each request on business logic, external APIs and slower queries, and the more time a request spends waiting, the less the framework’s own speed matters. This benchmark hardly tests that: outside the counter at default settings, the application server’s CPU was the limit in every run, not the database. An application that waits more will see smaller multiples.

Octane’s built-in server configuration compresses responses, and the other stacks do not. To keep the work equal, the load generator asked every stack for uncompressed responses. In an earlier run with compression on, Octane’s numbers moved by less than 10% in either direction.

Laravel Rust and Laravel Go are also pre-1.0. Their APIs may still change, their package ecosystems are a fraction of PHP’s, and they need a team that is comfortable with the language. Those costs do not show up in a benchmark.

For an existing Laravel application, the cheapest improvements in these numbers are still on the PHP side. At default settings Octane was 1.7 to 4.6 times faster than PHP-FPM on the same code, and persistent database connections closed much of that gap without changing the server. For a new service where throughput, memory or startup time drive the hosting bill, Laravel Rust delivers the throughput its launch page claims: 17 times Octane’s on the simplest endpoint, against a claimed 18. Its memory and startup gains are real but smaller here: 2 to 7 times less memory than Octane depending on load, and a start 3.5 times faster. Laravel Go delivers most of that throughput, at between half and nearly all of Rust’s, with the smallest memory footprint here. In both, the code still reads like Laravel.

Reproducing it

All three applications, the Docker images, the load scripts and the raw results are on GitHub at gdarko/laravel-benchmarks. The harness needs three Linux servers reachable over SSH, from any provider. It installs Docker, builds the five stacks, loads the data and runs everything in about two hours and twenty minutes.

Comments

Loading comments…

← older
PHP2Shell: what to patch and what to contain