-
Notifications
You must be signed in to change notification settings - Fork 11.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[6.x/7.x] broadcast() method causes memory leak #33952
Comments
What driver is |
It would need to be tracked down if this is something that actually happens in Laravel. It could be in the Redis library you are using, etc. |
It's using the native Redis |
Predis or phpredis? |
I think predis, if that's the one that is set by default within homestead |
Can you please find out the actual driver, with 100% certainty. |
Predis. |
@GrahamCampbell @taylorotwell For |
And the issue only occurs with predis, or also with phpredis? phpredis is the recommended driver, with up to 7x better performance. |
So, to give you the full console output for each driver: PHPRedis: Click for logs➜ code php artisan websockets:serve --statistics-interval=1 "Using client: phpredis" Starting the WebSocket server on port 6001... Using: 18.32 MB Saving statistics... Using: 18.34 MB Saving statistics... Using: 18.34 MB Saving statistics... Using: 18.34 MB Saving statistics... Using: 18.34 MB [ HERE I HAVE INITIATED A NEW CONNECTION; UNTIL AT THIS POINT, THE broadcast() DID NOT GET CALLED BECAUSE THERE WERE NO CONNECTED USERS ] Using: 19.88 MB Saving statistics... Using: 19.98 MB Saving statistics... Using: 20.09 MB Saving statistics... Using: 20.19 MB Saving statistics... Using: 20.3 MB Saving statistics... Using: 20.4 MB Saving statistics... [ HERE I HAVE DISCONNECTED FROM THE WEBSOCKETS SERVER ] Using: 20.51 MB Saving statistics... Using: 20.62 MB Saving statistics... Using: 20.72 MB Saving statistics... Using: 20.83 MB Saving statistics... Using: 20.95 MB Saving statistics... Using: 21.06 MB Saving statistics... Using: 21.16 MB Saving statistics... Using: 21.27 MB Saving statistics... Using: 21.37 MB Predis: Click for logs➜ code php artisan websockets:serve --statistics-interval=1 "Using client: predis" Starting the WebSocket server on port 6001... Using: 18.64 MB Saving statistics... Using: 18.66 MB Saving statistics... Using: 18.66 MB Saving statistics... Using: 18.66 MB Saving statistics... Using: 18.66 MB Saving statistics... Using: 18.66 MB Saving statistics... Using: 18.66 MB Saving statistics... Using: 18.66 MB Saving statistics... Using: 18.66 MB [ HERE I HAVE INITIATED A NEW CONNECTION; UNTIL AT THIS POINT, THE broadcast() DID NOT GET CALLED BECAUSE THERE WERE NO CONNECTED USERS ] Using: 20.2 MB Saving statistics... Using: 20.3 MB Saving statistics... Using: 20.41 MB Saving statistics... Using: 20.51 MB Saving statistics... Using: 20.62 MB Saving statistics... Using: 20.72 MB Saving statistics... Using: 20.83 MB Saving statistics... Using: 20.94 MB Saving statistics... Using: 21.04 MB Saving statistics... Using: 21.15 MB Saving statistics... Using: 21.27 MB Saving statistics... [ HERE I HAVE DISCONNECTED FROM THE WEBSOCKETS SERVER ] Using: 21.34 MB Saving statistics... Using: 21.45 MB Saving statistics... Using: 21.55 MB Saving statistics... Using: 21.66 MB Saving statistics... Using: 21.76 MB Saving statistics... Using: 21.87 MB Saving statistics... Using: 21.97 MB Saving statistics... Using: 22.08 MB Saving statistics... Using: 22.18 MB Saving statistics... Using: 22.29 MB Saving statistics... Using: 22.4 MB Saving statistics... Using: 22.5 MB Saving statistics... Using: 22.61 MB Saving statistics... So it doesn't depend on which driver is used. |
Thanks. |
@taylorotwell @GrahamCampbell I can confirm this memory leak happens even on the |
I have pointed out in beyondcode/laravel-websockets#325 (comment) that a controller also caused the issue, eventually moving on in beyondcode/laravel-websockets#325 (comment) to find out the issue is because of the broadcasting dispatch. The package got a |
The issue seems to be caused by the Calling |
I followed the instructions step by step to reproduce this. After digging a while, I found out that in /facade/ignition/src/IgnitionServiceProvider.php, function boot(): public function boot()
{
...
// $this->app->make(QueryRecorder::class)->register();
// $this->app->make(LogRecorder::class)->register();
// $this->app->make(DumpRecorder::class)->register();
} comment out these three lines make the memory leak go away, and the websocket part works well. |
See above. |
If the memory leak is caused by running SQL queries with many bindings, a fix is to set |
@mpskovvang Makes sense! I have informed the package users that had the respective issue. |
Like the title says, I ran into a discussion about some memory leaks for beyondcode/laravel-websockets here: beyondcode/laravel-websockets#325
The basic truth is that after some testing, I found out that running
broadcast(...)
will severely increase the memory for a ReactPHP loop, for instance.To replicate this:
composer require laravel/websockets:"dev-2.x-memory-leak"
php artisan vendor:publish --provider="BeyondCode\LaravelWebSockets\WebSocketsServiceProvider" --tag="migrations"
php artisan migrate
php artisan websockets:serve --statistics-interval=1
php artisan serve
http://127.0.0.1:8000/laravel-websockets
websockets:serve
As explained in beyondcode/laravel-websockets#325 (comment) and beyondcode/laravel-websockets#325 (comment), the problem starts from a
broadcast()
that causes the leakage.I have tested even the code within the event. Running
broadcast()
caused the memory leaks.The text was updated successfully, but these errors were encountered: