Skip to content
Snippets Groups Projects
Commit 98800767 authored by ale's avatar ale
Browse files

prevent division by 0 in utilization scorer

parent bf546d70
No related branches found
No related tags found
No related merge requests found
......@@ -293,7 +293,13 @@ type capacityAvailableScorer struct {
}
func (s *capacityAvailableScorer) Score(ctx RequestContext, n Node) float64 {
return 1.0 / s.pred.Utilization(n)
// Cap utilization low limit at 5%. Anything below that is
// considered equally available.
u := s.pred.Utilization(n)
if u < 0.05 {
u = 0.05
}
return 1.0 / u
}
func NewCapacityAvailableScorer(pred Predictor) NodeFilter {
......
......@@ -115,6 +115,24 @@ func TestLoadBalancer_Policies(t *testing.T) {
runLBTest(t, nodes, nil, "bandwidth_score,best", 1000, map[string]int{"node2": 1000})
}
func TestLoadBalancer_ZeroUtilization(t *testing.T) {
nodes := []*autoradio.NodeStatus{
&autoradio.NodeStatus{
Name: "node1",
IcecastUp: true,
BandwidthUsage: 0,
},
&autoradio.NodeStatus{
Name: "node2",
IcecastUp: true,
BandwidthUsage: 0,
},
}
// Weighted should return both nodes equally.
runLBTest(t, nodes, nil, "bandwidth_score,weighted", 1000, map[string]int{"node1": 500, "node2": 500})
}
func TestLoadBalancer_PoliciesIgnoreDisabledNodes(t *testing.T) {
nodes := []*autoradio.NodeStatus{
&autoradio.NodeStatus{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment