From a9d3a5f40dc9bb7e9390391d8df7ad231ecbd63c Mon Sep 17 00:00:00 2001 From: Dave Chen Date: Thu, 27 Jun 2019 10:32:46 +0800 Subject: [PATCH] Short-circuit the evaluation of `cpuFraction` and `memoryFraction` Signed-off-by: Dave Chen --- .../priorities/balanced_resource_allocation.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/scheduler/algorithm/priorities/balanced_resource_allocation.go b/pkg/scheduler/algorithm/priorities/balanced_resource_allocation.go index 97635cddddc..b073d0aa5dd 100644 --- a/pkg/scheduler/algorithm/priorities/balanced_resource_allocation.go +++ b/pkg/scheduler/algorithm/priorities/balanced_resource_allocation.go @@ -42,9 +42,14 @@ func balancedResourceScorer(requested, allocable *schedulernodeinfo.Resource, in cpuFraction := fractionOfCapacity(requested.MilliCPU, allocable.MilliCPU) memoryFraction := fractionOfCapacity(requested.Memory, allocable.Memory) // This to find a node which has most balanced CPU, memory and volume usage. + if cpuFraction >= 1 || memoryFraction >= 1 { + // if requested >= capacity, the corresponding host should never be preferred. + return 0 + } + if includeVolumes && utilfeature.DefaultFeatureGate.Enabled(features.BalanceAttachedNodeVolumes) && allocatableVolumes > 0 { volumeFraction := float64(requestedVolumes) / float64(allocatableVolumes) - if cpuFraction >= 1 || memoryFraction >= 1 || volumeFraction >= 1 { + if volumeFraction >= 1 { // if requested >= capacity, the corresponding host should never be preferred. return 0 } @@ -57,10 +62,6 @@ func balancedResourceScorer(requested, allocable *schedulernodeinfo.Resource, in return int64((1 - variance) * float64(schedulerapi.MaxPriority)) } - if cpuFraction >= 1 || memoryFraction >= 1 { - // if requested >= capacity, the corresponding host should never be preferred. - return 0 - } // Upper and lower boundary of difference between cpuFraction and memoryFraction are -1 and 1 // respectively. Multiplying the absolute value of the difference by 10 scales the value to // 0-10 with 0 representing well balanced allocation and 10 poorly balanced. Subtracting it from