laravel / reverb

Laravel Reverb provides a real-time WebSocket communication backend for Laravel applications.
https://reverb.laravel.com
MIT License
1.02k stars 71 forks source link

Memory leak with telescope #148

Closed vatsake closed 4 months ago

vatsake commented 4 months ago

Reverb Version

v1.0.0-beta6

Laravel Version

11.3.1

PHP Version

8.3

Description

I hope I did it right this time... REPO link https://github.com/vatsake/laravel-bug-report

Turns out the culprit(s) still was Telescope (and Reverb).

For the memory 'leak' to occur, a client has to listen for events.


145

146

Steps To Reproduce

Run both the webserver and websocket server. You'll need a database for Telescope.

composer install
php artisan migrate
php artisan serve
php artisan reverb:start

Now connect to the websocket server with the url and subscribe to a channel (I kept .env in repo). I recommend Postman. ws://localhost:8080/app/8vqpxbu8cayuc1uas54f?protocol=7&client=js&version=8.4.0-rc2&flash=false Subscribe with message: {"event":"pusher:subscribe","data":{"auth":"","channel":"test"}}

Now open a memory monitoring tool, I used htop.

When making a request to the root page, 1000 events will be fired. Make a curl request or open in browser: http://localhost:8000/

joedixon commented 4 months ago

Thanks for the reproduction @vatsake

Although I wouldn't necessarily recommend using Telescope with Reverb in production due to the blocking nature of storing entries, I think I have addresssed the issue with #151

Would you be able to test and let me know whether this prevents the increase in memory usage on your server.

driesvints commented 4 months ago

Thanks @vatsake. I still had difficulty to recreate this, steps weren't entirely clear to me. But seems @joedixon managed to and sent in a fix.

vatsake commented 4 months ago

Thanks for the reproduction @vatsake

Although I wouldn't necessarily recommend using Telescope with Reverb in production due to the blocking nature of storing entries, I think I have addresssed the issue with #151

Would you be able to test and let me know whether this prevents the increase in memory usage on your server.

@joedixon @driesvints Was able to test and I can confirm that with this PR the "memory leak" will not occur.

@joedixon What package would you recommend for monitoring? Currently in prod I'm using octane, which makes my app blazing fast, so a 1-2ms blocking ain't really an issue.

joedixon commented 4 months ago

You can use Telescope, but when Reverb collects the events (by default every 15 seconds), that process will prevet other requests from being processed. The more traffic your server is handling, the more entries need to be processed by Telescope, the longer the delay.

You may also like to look at Pulse for Reverb monitoring.