7

I have 3 Laravel applications, one running on Laravel 6 and 2 running on Laravel 8.

They all uses Vue and JWT auth from tymondesigns, and I've plan to upgrade them all to Laravel 10.

But after I successfully rebuilt one of my application to have Laravel 10 with Jetstream on it. I notice it uses like x15 ram compare to the older version of the same application.

You can see here (I use clockwork for monitoring). both of these is on the same server and are in production mode in Ubuntu with 4GB of ram, although L10 is running with Octane,

Old version running Laravel 8 - uses only 2MB of Memory enter image description here

New version running Laravel 10 with Jetstream - uses 30MB of Memory (even with 404s) enter image description here

I thought this was due to my own code structure and application design, so I run a test between bare installation of Laravel 8 vs Laravel 9

composer create-project laravel/laravel:^8.0 l8

and

composer create-project laravel/laravel:^9.0 l9

then added this on both api routes.

Route::get('/test', function() {
    return response()->json(['success' => false, 'message' => 'You damned Teapot!'], 418);
});

the result is not as high as my application, but L9 still uses like x9 memory compared to older version.

Laravel 8 with php 7.4 2MB enter image description here

Laravel 9 with php 8.2 18MB enter image description here

I also set-up laravel 10 and the result is pretty much the same with Laravel 9.

Upon checking the upgrade notes of Laravel 9 and 10, I realize that sanctum is shipped on L9 and L10 by default, so I installed and configured Sanctum on L8, and sure enough, the Memory usage spike even without adding sanctum middleware on that test route, as you can see below it now uses 12MB compare to 2MB before Sanctum is installed. enter image description here

I'm now thinking of removing sanctum on my application and revert to using JWT, but Im not sure if that would be easy since everything was configured by Jetstream.

So my question is, is it possible to optimize this to lower memory usage? and why is SANCTUM causes a lot of memory usage even on routes it wasn't used?

SymmetricsWeb
  • 586
  • 6
  • 20
  • 1
    I do not think you will be able to get a good answer here, maybe someone had this issue too and knows why, but I would go to the sanctum or jetstream github repo and create and issue there presenting this problem – matiaslauriti Mar 07 '23 at 05:23
  • Check the `ServiceProvider` classes. Laravel auto-discovers them now. Try commenting out the vendor code from Sanctum's vendor service provider and see if that alters your memory usage. – IGP Mar 14 '23 at 22:41

0 Answers0