Laravel Queue Worker Memory Footprint is Too Big :/
Asked Answered
B

2

12

I am running a queue worker that connects to six MQs. When it is brought up, it consumes 25MB of RAM. That is with zero jobs on the queue, i.e. the worker is in a sleep state. I use Larvel for all of my projects, this particular project is purely built for the queue worker (i.e. a microservice with no web access).

I would like to reduce the memory footprint, but more importantly I would like to know where the memory is being consumed. I am using PHP 7.1 so now that xhprof no longer profiles memory I have to figure out an alternative.

I know that Lumen is meant to consume less memory, and it seems at least that Lumen is a subset of Laravel. Is it possible to "turn off" parts of my Laravel app so that it mimics Lumen? I tried commenting out lines from the config/app.php $providers array, but there does not seem to be a big difference in memory consumption (~1MB by my measure).

tl;dr; how to "tweak" the Laravel memory footprint? how to turn Laravel into Lumen?

Thanks

EDIT: Pics or it didn't happen. AFAIK the RES column is in kilobytes, so ~39MB of memory.

RES == 39MB

Bender answered 11/10, 2017 at 23:5 Comment(6)
Just the single worker process uses 25MB?Sik
thats weird.. what actually you do with laravel..? and the php max memory settings.. how did you conclude that it was laravel that gobble up 25 MB memory?Skyeskyhigh
this might help #33811975Ginetteginevra
Are you using an ORM?Pule
@albert, yes jenssegers/laravel-mongodbBender
Good old htop :DFairweather
A
1

Might this would help to cut down the memory that is used in your queue.

url : Laravel queues - Resource Considerations

Resource Considerations

Daemon queue workers do not "reboot" the framework before processing each job. Therefore, you should free any heavy resources after each job completes. For example, if you are doing image manipulation with the GD library, you should free the memory with imagedestroy when you are done.

Allahabad answered 10/1, 2018 at 8:35 Comment(1)
Thanks, makes sense regarding unmanaged resources, but I don't think I have any (i.e. no file handles other than the laravel log file, no GD work). However, it is making a lot of guzzle calls, under the hood they are curl calls so that may or may not have an impact. The other thing is that the worker daemon starts with 35MB RAM, and after 2 days of heavy operation it's still at 35MB RAM. So I'm not sure what to infer from that.Bender
F
1

Have you checked your php.ini and turned off any extensions you don't require for your worker & rest of codebase.

You could create a custom php.ini for this worker and supply it via the command line arguments

php -c queue_php.ini artisan queue:work.

Don't forget that the memory footprint you're seeing there is for all of that PHP execution so that includes the JIT Compiler and any extensions loaded and whatever they load.

Fairweather answered 16/1, 2018 at 15:53 Comment(3)
That sounds like an interesting idea - is there an easy way to find the php dependencies of a project? Would an IDE help?Bender
Also, an apache php fork of my laravel project will typically use ~4MB of ram. Does that also include the JIT compiler + extensions? ThxBender
@Bender I'm not sure for a few reasons the main one depends on the PHP setup in apache (the connector used).Fairweather

© 2022 - 2024 — McMap. All rights reserved.