Laravel keep eating memory with every request

Published 1 week ago by asachanfbd

I was working to improve performance of my Laravel application and got below stats -

  • Request 1(db interactions) - 1238(Ram Used)
  • R2(db interactions) - 1250
  • R3(db intr.) - 1275
  • R4(db intr) - 1289
  • R4 - again(db intr) - 1295
  • R5(db intr) - 1313
  • R5 - again(db intr) - 1313
  • Rn - 1873(out of 2004MB total memory)

On performing tests on DB - No memory leak found.( I tried inserts in look and checked memory after every 10000th insert. memory was stable).

Extensions used -

  • "laravelcollective/html": "^5.2",
  • "gbrock/laravel-table": "^0.3.4",
  • "guzzlehttp/guzzle": "^6.1",
  • "lavary/laravel-menu": "^1.6",
  • "intervention/image": "^2.3",
  • "maatwebsite/excel": "^2.1",
  • "aws/aws-sdk-php-laravel": "^3.1",
  • "barryvdh/laravel-dompdf": "^0.7.0",
  • "yajra/laravel-datatables-oracle": "^6.0",
  • "rap2hpoutre/laravel-log-viewer": "^0.7.1",
  • "brozot/laravel-fcm": "^1.2"

Please suggest why Laravel is using all the RAM and not releasing it. It starts crashing at the end.

jlrdw
jlrdw
1 week ago (191,950 XP)

Are you running a query that returns a huge resultset rather that paginating? Also just load what's needed on a page. As an example if an edit page only uses some js for a popup calendar just load that js, not 10 million lines of other js.

asachanfbd
  1. No Queries are not returning huge result sets only required data.
  2. No JS is loaded requests are web services. JSON response only.
Cronix
Cronix
1 week ago (148,870 XP)

Laravel keeps all of the queries that have been ran in memory for debugging. I run some processes that run for hours inserting tens of thousands of records in the db. Each loop takes more memory until it crashes... until.. I discovered how to turn that off.

DB::disableQueryLog();
// run lots of queries

After doing that, laravel consumed no more than 5M memory for the entire thing.

jlrdw
jlrdw
1 week ago (191,950 XP)

@Cronix good to know, where do you put

DB::disableQueryLog();
Cronix
Cronix
1 week ago (148,870 XP)

I just have it before running a ton of queries, like when I'm pulling in data from apis and storing it in a huge loop.

asachanfbd

I had already tested with DB::disableQueryLog(); but this is not the issue.

My issue is memory is not released even after completion of request.

Sign In or create a forum account to participate in this discussion.