Progress, of sorts.
First, I created a simple .php
page that didn’t involve Laravel at all:
$ wrk -c 10 -d 10s -t 1 --latency 'https://....fly.dev/hello.php'
Running 10s test @ https://....fly.dev/hello.php
1 threads and 10 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 6.88ms 14.31ms 176.84ms 97.09%
Req/Sec 2.04k 349.48 2.53k 90.00%
Latency Distribution
50% 4.38ms
75% 5.24ms
90% 6.86ms
99% 91.05ms
20289 requests in 10.01s, 7.62MB read
Requests/sec: 2027.67
Transfer/sec: 780.08KB
Holy cow.
So PHP isn’t the problem.
After that, I created a series of Laravel routes that incrementally added more complexity:
Route::get('/__hello__', function () {
return 'Hello!';
})->name('hello');
Route::get('/__hello0__', function () {
return response(
'Hello 0!'
);
})->name('hello0');
Route::get('/__hello1__', function () {
return response(
'Hello 1!'
)->header('Content-Type', 'text/plain');
})->name('hello1');
Route::get('/__hello2__', function () {
return response(
view('hello2', [
])
)->header('Content-Type', 'text/plain');
})->name('hello2');
Route::get('/__hello3__', function () {
return response(
view('hello3', [
'pages' => Page::wherePublished()->orderByAToZ()->get(),
'posts' => Post::wherePublished()->orderByNewestToOldest()->simplePaginate(25),
])
)->header('Content-Type', 'text/plain');
})->name('hello3');
Route::get('/__hello4__', function () {
return response(
view('hello4', [
'pages' => Page::wherePublished()->orderByAToZ()->get(),
'posts' => Post::wherePublished()->orderByNewestToOldest()->simplePaginate(25),
])
)->header('Content-Type', 'text/plain');
})->name('hello4');
(hello3
executes database queries, but doesn’t use the results. hello4
executes database queries and uses the results.)
The first route was ok-ish:
wrk -c 10 -d 10s -t 1 --latency 'https://....fly.dev/__hello__'
Running 10s test @ https://....fly.dev/__hello__
1 threads and 10 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 72.16ms 12.44ms 122.58ms 70.57%
Req/Sec 138.08 22.38 181.00 72.00%
Latency Distribution
50% 71.12ms
75% 80.12ms
90% 88.06ms
99% 105.32ms
1383 requests in 10.05s, 578.00KB read
Requests/sec: 137.57
Transfer/sec: 57.49KB
But the second was enough to drop me to ~3.5 RPS:
wrk -c 10 -d 10s -t 1 --latency 'https://....fly.dev/__hello0__'
Running 10s test @ https://....fly.dev/__hello0__
1 threads and 10 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 1.74s 7.80ms 1.75s 83.33%
Req/Sec 7.36 10.65 40.00 85.71%
Latency Distribution
50% 1.74s
75% 1.74s
90% 1.75s
99% 1.75s
33 requests in 10.07s, 13.86KB read
Socket errors: connect 0, read 0, write 0, timeout 27
Requests/sec: 3.28
Transfer/sec: 1.38KB
Why? Why does simply creating a response object destroy performance? Why why why?
Not sure.
Not even sure where to start looking.
I did a fly ssh console
and php artisan about
to verify the general app state:
Environment ...........................................................
Application Name .............................................. Laravel
Laravel Version ............................................... 10.45.0
PHP Version ...................... 8.3.3-1+ubuntu22.04.1+deb.sury.org+1
Composer Version ................................................ 2.7.1
Environment ................................................ production
Debug Mode ........................................................ OFF
URL ....................................................... ....fly.dev
Maintenance Mode .................................................. OFF
Cache .................................................................
Config ......................................................... CACHED
Events ..................................................... NOT CACHED
Routes ......................................................... CACHED
Views .......................................................... CACHED
Drivers ...............................................................
Broadcasting ..................................................... null
Cache ............................................................ file
Database ....................................................... sqlite
Logs ........................................................... stderr
Mail ............................................................. smtp
Queue ............................................................ sync
Session ........................................................ cookie
Filament ..............................................................
Packages .............. filament, forms, notifications, support, tables
Version ....................................................... v3.2.35
Views ................................................... NOT PUBLISHED
Livewire ..............................................................
Livewire ....................................................... v3.4.6
Not in debug mode, config is cached, routes are cached, views are cached…
Hmmm.
I don’t know how much more time I’m going to sink into this.