Skip to content

Commit e25ebaf

Browse files
freyacodesduncte123
andcommitted
Consider both local and remote player count in balancing
Co-authored-by: duncte123 <contact@duncte123.me>
1 parent 990dc7e commit e25ebaf

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

Lines changed: 3 additions & 1 deletion
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:
@@ -61,7 +62,8 @@ data class Penalties(val node: LavalinkNode) {
6162
// The way we calculate penalties is heavily based on the original Lavalink client.
6263

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

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

0 commit comments

Comments
 (0)