Skip to content

Node Selection "herding" at large scale #3784

Closed

Description

@alan-willard-simplisafe

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:

  1. Large scale, multi-region deployment, Up to 100 LK nodes per region. Using sort_by to try to keep the load on the livekit pods balanced
  2. An event causes mass connect / reconnect events (such as a deployment of an upstream service using livekit)
  3. 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

  1. alan-willard-simplisafe commented on Jul 10, 2025

    @alan-willard-simplisafe
    ContributorAuthor

    Opened a PR with my proposed enhancement here #3785

  2. alan-willard-simplisafe commented on Oct 9, 2025

    @alan-willard-simplisafe
    ContributorAuthor

    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

  3. alan-willard-simplisafe commented on Oct 22, 2025

    @alan-willard-simplisafe
    ContributorAuthor

    looks like this got released, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions