beyondcode / laravel-websockets

Websockets for Laravel. Done right.
https://beyondco.de/docs/laravel-websockets
MIT License
5.07k stars 612 forks source link

High CPU usage after a while #379

Closed bbashy closed 4 years ago

bbashy commented 4 years ago

63 Peak Connections 40 Websocket Messages 3 API Messages

Seen this happen few times. Websockets still work but it's maxing out at 99-100% CPU usage. I use port 2096 for Cloudflare proxy to pick it up. I use Supervisor to keep it running. I use release folders same as Laravel Envoyer.

Anyone seen or know why this might be?

bbashy commented 4 years ago

Moved to a new dedicated server (from 4c/8t to 8c/16t) and it's still doing the same

pl862008 commented 4 years ago

I have the same problem, with laravel 7 and laravel-websockets - 1.4.0 - only two users testing After 2-3 days, it stopped working and maxed one cpu, when dispatch the event - throws BroadcastExeption.

After killing the process, supervisor starts it again and works fine.

dsteindl commented 4 years ago

I run into the same problem on my server. When having statistics enabled, the problem occures after a few minutes. After I disabled statistics, the websocket server seemed to work, but unfortunately, the next day the websocket:server process showed up using 99-100% CPU again.

My server has 8 cores and each of them has 3.2GHz.

Our application is used by max. 500 people at the same time. And only a little section of our application joins websocket channels. Currently there are only 50 people (max) joining websockets channels at the same time.

rennokki commented 4 years ago

2.x managed to somehow fix the issues related to performance. Make sure to check this PR and if you can (only if you can; it can cause breaks) you can upgrade to 2.0.0-beta.11 version of the package (or the latest at this point) to fix the CPU and Memory Leaks. 1.x does not have this fixed as 2.x is currently tested to deprecate 1.x

bbashy commented 4 years ago

@rennokki Thanks for the work you've done to track it down. I'll see if I can update it to 2.x and report back.

dsteindl commented 4 years ago

@rennokki Thanks! I updated to v2.0.0-beta.11 and started the websocket server about 3 hours ago. Everything seems to work until now. The CPU load is between 0 and 3%

rennokki commented 4 years ago

Come back if the issues persist.

rennokki commented 3 years ago

So the issue was with Ignition package, please see https://github.com/laravel/framework/issues/33952#issuecomment-693350705 for quick-fix and https://github.com/facade/ignition/issues/307 for the PR follow-up.

bbashy commented 3 years ago

I published the flare config and set the maximum_number_of_collected_queries to 0. I'll report back.

I use composer install --no-dev on prod so not sure how the other PR mentioned in that thread will do.

victornoleto commented 2 years ago

I have the same problem, with laravel 7 and laravel-websockets - 1.4.0 - only two users testing After 2-3 days, it stopped working and maxed one cpu, when dispatch the event - throws BroadcastExeption.

After killing the process, supervisor starts it again and works fine.

Did you find a solution?

bbashy commented 2 years ago

@victornoleto I think the solution is to update to v2 but it's still marked as beta.

I still get the issue, I just restart the process every now and then. It doesn't stop the functionality of the web socket.

pwnz22 commented 2 years ago

I'm also having issues with that, using v2.0.0-beta.36 and laravel 8.40

juristamrcl commented 2 years ago

In case anyone having this issue, it seems I could figure it out upgrading to latest v1 (at the time of writing this comment 1.13). An issue also occured when running websockets daemon from non-existing folder (after few deployments the old ones have been removed and daemon continued to run from non-existing folder). I figured it out by running php artisan websockets:restart at the end of the deploy script.

ILABUTK commented 1 year ago

I am testing this config:

 "php": "^8.0.0",
 "beyondcode/laravel-websockets": "v2.0.0-beta.36",
 "doctrine/dbal": "^2.9", // required by websockets "v2.0.0-beta.36",