Repository navigation
Description
Describe the bug
Observed with our "large" scale k8s deployment of livekit (few hundred pods, tens of thousands of rooms) that the balance of rooms (and therefore resources such as CPU/Memory) is imbalanced, long lived pods eventually will get close to and exceed k8s limits and get oomkilled. Using the default random node selection
On paper, using the node selection sort_by and sysload, etc parameters seem like the solution, but in practice this seems to cause a herding behavior, for example if using sort_by: rooms a large group of connections will (if the events occur in a short amount of time) be allocated to the node with the lowest room count at that moment of time, overwhelming it, and then causing the pod to be killed, and then the clients herd to the next lowest node, and so on.
The cause of this issue, I believe is a information delay of state between the livekit nodes. Because each livekit node acts as a load balancer, it is only as good as it's current state information. At large numbers, and with many many thousands of connections in a short amount of time, this breaks down.
This article does a good job summarizing the issue https://www.f5.com/company/blog/nginx/nginx-power-of-two-choices-load-balancing-algorithm "It All Falls Apart with Multiple Guides"
Server
- Version: 1.8.4
- Environment: EKS
To Reproduce
Steps to reproduce the behavior:
- Large scale, multi-region deployment, Up to 100 LK nodes per region. Using
sort_byto try to keep the load on the livekit pods balanced - An event causes mass connect / reconnect events (such as a deployment of an upstream service using livekit)
- Connections herd to a single node, possibly triggering k8s oomkills
Expected behavior
The herd of connections is distributed amongst the livekit population favoring the nodes in the sort_by criteria, but not herding to any single (or small set of) nodes
Solution
I have a proposed solution for this issue, by introducing an option to use the "Power of Two Random Choices" load balancing algorithm, which has proven successful for my use case. I will submit a PR shortly with additional detail. I am open to other alternatives as well based the project maintainers' and community feedback
Activity
alan-willard-simplisafe commentedon Jul 10, 2025
Opened a PR with my proposed enhancement here #3785
alan-willard-simplisafe commentedon Oct 9, 2025
Thank you for approving the PR. I think this issue can be closed with the next release. I've been running a custom build with this change since July with great success
alan-willard-simplisafe commentedon Oct 22, 2025
looks like this got released, thank you