diff --git a/plugin/pkg/scheduler/algorithm/priorities/node_affinity.go b/plugin/pkg/scheduler/algorithm/priorities/node_affinity.go index a4bf9972c40..89050dc34b1 100644 --- a/plugin/pkg/scheduler/algorithm/priorities/node_affinity.go +++ b/plugin/pkg/scheduler/algorithm/priorities/node_affinity.go @@ -36,8 +36,8 @@ func CalculateNodeAffinityPriority(pod *api.Pod, nodeNameToInfo map[string]*sche return nil, err } - var maxCount int - counts := make(map[string]int, len(nodes.Items)) + var maxCount float64 + counts := make(map[string]float64, len(nodes.Items)) affinity, err := api.GetAffinityFromPodAnnotations(pod.Annotations) if err != nil { @@ -61,7 +61,7 @@ func CalculateNodeAffinityPriority(pod *api.Pod, nodeNameToInfo map[string]*sche for _, node := range nodes.Items { if nodeSelector.Matches(labels.Set(node.Labels)) { - counts[node.Name] += int(preferredSchedulingTerm.Weight) + counts[node.Name] += float64(preferredSchedulingTerm.Weight) } if counts[node.Name] > maxCount { @@ -74,12 +74,17 @@ func CalculateNodeAffinityPriority(pod *api.Pod, nodeNameToInfo map[string]*sche result := make(schedulerapi.HostPriorityList, 0, len(nodes.Items)) for i := range nodes.Items { node := &nodes.Items[i] - fScore := float64(0) if maxCount > 0 { - fScore = 10 * (float64(counts[node.Name]) / float64(maxCount)) + fScore := 10 * (counts[node.Name] / maxCount) + result = append(result, schedulerapi.HostPriority{Host: node.Name, Score: int(fScore)}) + if glog.V(10) { + // We explicitly don't do glog.V(10).Infof() to avoid computing all the parameters if this is + // not logged. There is visible performance gain from it. + glog.Infof("%v -> %v: NodeAffinityPriority, Score: (%d)", pod.Name, node.Name, int(fScore)) + } + } else { + result = append(result, schedulerapi.HostPriority{Host: node.Name, Score: 0}) } - result = append(result, schedulerapi.HostPriority{Host: node.Name, Score: int(fScore)}) - glog.V(10).Infof("%v -> %v: NodeAffinityPriority, Score: (%d)", pod.Name, node.Name, int(fScore)) } return result, nil } diff --git a/plugin/pkg/scheduler/algorithm/priorities/taint_toleration.go b/plugin/pkg/scheduler/algorithm/priorities/taint_toleration.go index 64a0ab9665c..624a45389c1 100644 --- a/plugin/pkg/scheduler/algorithm/priorities/taint_toleration.go +++ b/plugin/pkg/scheduler/algorithm/priorities/taint_toleration.go @@ -25,7 +25,7 @@ import ( ) // CountIntolerableTaintsPreferNoSchedule gives the count of intolerable taints of a pod with effect PreferNoSchedule -func countIntolerableTaintsPreferNoSchedule(taints []api.Taint, tolerations []api.Toleration) (intolerableTaints int) { +func countIntolerableTaintsPreferNoSchedule(taints []api.Taint, tolerations []api.Toleration) (intolerableTaints float64) { for i := range taints { taint := &taints[i] // check only on taints that have effect PreferNoSchedule @@ -59,9 +59,9 @@ func ComputeTaintTolerationPriority(pod *api.Pod, nodeNameToInfo map[string]*sch } // the max value of counts - var maxCount int + var maxCount float64 // counts hold the count of intolerable taints of a pod for a given node - counts := make(map[string]int, len(nodes.Items)) + counts := make(map[string]float64, len(nodes.Items)) tolerations, err := api.GetTolerationsFromPodAnnotations(pod.Annotations) if err != nil { @@ -87,15 +87,19 @@ func ComputeTaintTolerationPriority(pod *api.Pod, nodeNameToInfo map[string]*sch // The maximum priority value to give to a node // Priority values range from 0 - maxPriority - const maxPriority = 10 + const maxPriority = float64(10) result := make(schedulerapi.HostPriorityList, 0, len(nodes.Items)) for i := range nodes.Items { node := &nodes.Items[i] - fScore := float64(maxPriority) + fScore := maxPriority if maxCount > 0 { - fScore = (1.0 - float64(counts[node.Name])/float64(maxCount)) * 10 + fScore = (1.0 - counts[node.Name]/maxCount) * 10 + } + if glog.V(10) { + // We explicitly don't do glog.V(10).Infof() to avoid computing all the parameters if this is + // not logged. There is visible performance gain from it. + glog.Infof("%v -> %v: Taint Toleration Priority, Score: (%d)", pod.Name, node.Name, int(fScore)) } - glog.V(10).Infof("%v -> %v: Taint Toleration Priority, Score: (%d)", pod.Name, node.Name, int(fScore)) result = append(result, schedulerapi.HostPriority{Host: node.Name, Score: int(fScore)}) }