Properly implement penalties for frame stats

This commit is contained in:
Tyler 2019-10-13 04:44:51 -04:00
parent 1bb3b36df6
commit 4ae4d6def2
2 changed files with 23 additions and 8 deletions

View File

@ -13,18 +13,26 @@ type balancePenalty struct {
func BestNodeByPenalties(nodes []*Node) (*Node, error) { func BestNodeByPenalties(nodes []*Node) (*Node, error) {
penalties := make([]*balancePenalty, len(nodes)) penalties := make([]*balancePenalty, len(nodes))
var playerPenalty, cpuPenalty int var playerPenalty, cpuPenalty, deficitFramePenalty, nullFramePenalty int
for i, node := range nodes { for i, node := range nodes {
if node.stats == nil { playerPenalty = 0
penalties[i] = &balancePenalty{node, 1} cpuPenalty = 0
continue deficitFramePenalty = 0
} nullFramePenalty = 0
if node.stats != nil {
playerPenalty = node.stats.ActivePlayers playerPenalty = node.stats.ActivePlayers
cpuPenalty = int(math.Pow(1.05, 100*node.stats.Cpu.SystemLoad)*10 - 10) 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 { sort.SliceStable(penalties, func(i, j int) bool {

View File

@ -42,6 +42,7 @@ type RemoteStats struct {
Uptime int64 `json:"uptime"` Uptime int64 `json:"uptime"`
Memory *MemoryStats `json:"memory"` Memory *MemoryStats `json:"memory"`
Cpu *CpuStats `json:"cpu"` Cpu *CpuStats `json:"cpu"`
Frames *FrameStats `json:"frameStats"`
} }
type MemoryStats struct { type MemoryStats struct {
@ -57,6 +58,12 @@ type CpuStats struct {
LavalinkLoad float64 `json:"lavalinkLoad"` LavalinkLoad float64 `json:"lavalinkLoad"`
} }
type FrameStats struct {
Sent int `json:"sent"`
Nulled int `json:"nulled"`
Deficit int `json:"deficit"`
}
func (node *Node) open() error { func (node *Node) open() error {
header := http.Header{} header := http.Header{}