Properly implement penalties for frame stats
This commit is contained in:
parent
1bb3b36df6
commit
4ae4d6def2
20
balancer.go
20
balancer.go
@ -13,18 +13,26 @@ type balancePenalty struct {
|
||||
func BestNodeByPenalties(nodes []*Node) (*Node, error) {
|
||||
penalties := make([]*balancePenalty, len(nodes))
|
||||
|
||||
var playerPenalty, cpuPenalty int
|
||||
var playerPenalty, cpuPenalty, deficitFramePenalty, nullFramePenalty int
|
||||
|
||||
for i, node := range nodes {
|
||||
if node.stats == nil {
|
||||
penalties[i] = &balancePenalty{node, 1}
|
||||
continue
|
||||
}
|
||||
playerPenalty = 0
|
||||
cpuPenalty = 0
|
||||
deficitFramePenalty = 0
|
||||
nullFramePenalty = 0
|
||||
|
||||
if node.stats != nil {
|
||||
playerPenalty = node.stats.ActivePlayers
|
||||
cpuPenalty = int(math.Pow(1.05, 100*node.stats.Cpu.SystemLoad)*10 - 10)
|
||||
|
||||
penalties[i] = &balancePenalty{node, playerPenalty + cpuPenalty}
|
||||
if node.stats.Frames != nil && node.stats.Frames.Deficit != -1 {
|
||||
deficitFramePenalty = int(math.Pow(1.03, 500*float64(node.stats.Frames.Deficit/3000))*600 - 600)
|
||||
nullFramePenalty = int(math.Pow(1.03, 500*float64(node.stats.Frames.Nulled/3000))*300 - 300)
|
||||
nullFramePenalty *= 2
|
||||
}
|
||||
}
|
||||
|
||||
penalties[i] = &balancePenalty{node, playerPenalty + cpuPenalty + deficitFramePenalty + nullFramePenalty}
|
||||
}
|
||||
|
||||
sort.SliceStable(penalties, func(i, j int) bool {
|
||||
|
7
node.go
7
node.go
@ -42,6 +42,7 @@ type RemoteStats struct {
|
||||
Uptime int64 `json:"uptime"`
|
||||
Memory *MemoryStats `json:"memory"`
|
||||
Cpu *CpuStats `json:"cpu"`
|
||||
Frames *FrameStats `json:"frameStats"`
|
||||
}
|
||||
|
||||
type MemoryStats struct {
|
||||
@ -57,6 +58,12 @@ type CpuStats struct {
|
||||
LavalinkLoad float64 `json:"lavalinkLoad"`
|
||||
}
|
||||
|
||||
type FrameStats struct {
|
||||
Sent int `json:"sent"`
|
||||
Nulled int `json:"nulled"`
|
||||
Deficit int `json:"deficit"`
|
||||
}
|
||||
|
||||
func (node *Node) open() error {
|
||||
header := http.Header{}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user