Skip to content

Commit

Permalink
Make the load balancer immediately aware of the number of playing pla…
Browse files Browse the repository at this point in the history
…yers (#28)

* Make the load balancer immediately aware of the number of playing players

* Consider both local and remote player count in balancing

Co-authored-by: duncte123 <contact@duncte123.me>

---------

Co-authored-by: duncte123 <contact@duncte123.me>
  • Loading branch information
freyacodes and duncte123 committed Sep 16, 2024
1 parent ffd5e0f commit 57c8d29
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dev.arbjerg.lavalink.internal.loadbalancing
import dev.arbjerg.lavalink.client.LavalinkNode
import dev.arbjerg.lavalink.client.loadbalancing.MAX_ERROR
import dev.arbjerg.lavalink.protocol.v4.Message
import kotlin.math.max
import kotlin.math.pow

// Clearing them on a timer sucks, here's some ideas from freya:
Expand Down Expand Up @@ -65,7 +66,8 @@ data class Penalties(val node: LavalinkNode) {
// The way we calculate penalties is heavily based on the original Lavalink client.

// This will serve as a rule of thumb. 1 playing player = 1 penalty point
val playerPenalty = stats.playingPlayers
val cachedPlayingPlayers = node.playerCache.count { it.value.track != null && !it.value.paused }
val playerPenalty = max(cachedPlayingPlayers, stats.playingPlayers)

val cpuPenalty = (1.05.pow(100 * stats.cpu.systemLoad) * 10 - 10).toInt()

Expand Down

0 comments on commit 57c8d29

Please sign in to comment.