Skip to content

Commit 57c8d29

Browse files
Make the load balancer immediately aware of the number of playing players (#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 <[email protected]> --------- Co-authored-by: duncte123 <[email protected]>
1 parent ffd5e0f commit 57c8d29

File tree

1 file changed

+3
-1
lines changed
  • src/main/kotlin/dev/arbjerg/lavalink/internal/loadbalancing

1 file changed

+3
-1
lines changed

src/main/kotlin/dev/arbjerg/lavalink/internal/loadbalancing/Penalties.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dev.arbjerg.lavalink.internal.loadbalancing
33
import dev.arbjerg.lavalink.client.LavalinkNode
44
import dev.arbjerg.lavalink.client.loadbalancing.MAX_ERROR
55
import dev.arbjerg.lavalink.protocol.v4.Message
6+
import kotlin.math.max
67
import kotlin.math.pow
78

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

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

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

0 commit comments

Comments
 (0)