Skip to content

Load Balancing

MrCakeSlayer edited this page Sep 24, 2022 · 1 revision

Lavalink4NET Clusters support load balancing:

Standard Load Balancing Strategies

Score Strategy

The score load balancing strategy will calculate a rating for each node and favors the node with the highest. (default)

Round Robin

The round robin load balancing strategy favors the node that has not been used the longest.

Least Players

The load-balancing strategy that uses the node that has the least-playing player.

Load Strategy

The load load-balancing-strategy favors the node with the least node process CPU usage.


Custom Load Balancing

namespace [...]
{
    using System;
    using Lavalink4NET.Cluster;

    /// <summary>
    ///     Provides a set of load balancing strategies.
    /// </summary>
    public static class LoadBalacingStrategies
    {
        private static readonly Random random = new Random();

        /// <summary>
        ///     This load balancing strategy uses a random player.
        /// </summary>
        public static LoadBalacingStrategy MyLoadBalancingStrategy { get; } = (cluster, nodes) =>
            nodes[random.NextInt(nodes.Count)];
    }
}

The above example will choose a random node.