-
Notifications
You must be signed in to change notification settings - Fork 28
I found the cause of SQS Queue Worker's memory leak #1380
Comments
Since this is a problem in a specific driver, it would be better if we could solve it at the driver itself. Perhaps at the class Laravel uses to interact with the SDK. |
It is true as it is, but it is impossible to put it in because it can not do postprocessing as it is currently implemented. |
Would it work to call gc_collect_cycles() in the Looping event? |
I was thinking that it could be something done right at the The reasoning is that since it's a SqsQueue problem, it might be best to have a SqsQueue solution instead of affecting all drivers. Of course, if it doesn't cause harm, we might as well do it in the Worker loop. Ideally, we'd do it right after, which means we would add a |
Keeping it in SqsQueue would make sense in the context of focusing on this single problem. Putting it in the Worker makes sense if you consider that it's the Worker's responsibility to shut down when memory usage exceeds what is set by --memory. I was slightly surprised that the Worker didn't call gc_collect_cycles before shutting down to see if it could free memory. |
Call a gc_collect_cycles before sqs pop, if there are similar problems in future, will not you do the same kind of correspondence? Mr, @sisve Laravel users will not be (maybe) welcomed to shutdown queue workers due to memory overruns. |
This still hasn't been updated in a recent release has it? Is it possible just to run this function from a cronjob to resolve the memory issue? Are we able to insert What's the easiest way for something to implement this fix, without having to wait for Laravel, any other packages to update, or trying to host our own customized packages outside our main application files? |
If you are not using horizon, I think you can:
If you're using horizon, I'm not sure. Because horizon itself employs this very same technique, it extends I think that Laravels worker could benefit from calling I.e. performance might be affected when a worker runs many many small/fast jobs and thus calls |
I was struggling to incorporate opinions. My problem is that the queue job will continue to increase memory just by checking for jobs. |
@sh-ogawa Did you try calling call gc_collect_cycles() in a custom listener that is listening for the Looping event? It should be a workaround for your application until a suitable framework solution is implemented. |
@sisve Is it about our queue job? |
You're probably thinking of the JobProcessing/JobProcessed/JobFailed events which is tied to a specific job and wouldn't execute on an empty queue. The Looping event is fired every time the worker checks for an available job (and either executes it, or sleep if there was no available job). I use dedicated listener classes for my logic, but you can just throw this into your favorite service provider to execute
|
@sisve |
There was an update at aws/aws-sdk-php#1667 (comment) which points to an interesting thing:
From https://forums.aws.amazon.com/message.jspa?messageID=695298 (linked in above comment):
|
This behavior sounds similar to #1645 where we found that the SDK (or one of its dependencies) does appear to have cyclic references that have to be cleaned up by PHP's garbage collector, however garbage collection does occur naturally after a certain amount of references have built up.
This problem seems to be due to the implementation of SqsClient 's promise usage, which still has references left.
However, this problem can be solved by using
gc_collect_cycles()
.The easiest place to insert is in the
Illuminate\Queue\Worker::daemon()
.But I do not know if I can put it here, so I raised the issue.
We will share the exchange with aws-sdk-php issue, so would you please proceed with the direction to fix this problem?
aws/aws-sdk-php#1667 (comment)
The text was updated successfully, but these errors were encountered: