mirror of https://github.com/k3s-io/k3s
parent
ad9722c453
commit
cd65afdf05
|
@ -32,7 +32,7 @@ var (
|
||||||
// BalancedResourceAllocationMap should **NOT** be used alone, and **MUST** be used together
|
// BalancedResourceAllocationMap should **NOT** be used alone, and **MUST** be used together
|
||||||
// with LeastRequestedPriority. It calculates the difference between the cpu and memory fraction
|
// with LeastRequestedPriority. It calculates the difference between the cpu and memory fraction
|
||||||
// of capacity, and prioritizes the host based on how close the two metrics are to each other.
|
// of capacity, and prioritizes the host based on how close the two metrics are to each other.
|
||||||
// Detail: score = 10 - abs(cpuFraction-memoryFraction)*10. The algorithm is partly inspired by:
|
// Detail: score = 10 - variance(cpuFraction,memoryFraction,volumeFraction)*10. The algorithm is partly inspired by:
|
||||||
// "Wei Huang et al. An Energy Efficient Virtual Machine Placement Algorithm with Balanced
|
// "Wei Huang et al. An Energy Efficient Virtual Machine Placement Algorithm with Balanced
|
||||||
// Resource Utilization"
|
// Resource Utilization"
|
||||||
BalancedResourceAllocationMap = balancedResourcePriority.PriorityMap
|
BalancedResourceAllocationMap = balancedResourcePriority.PriorityMap
|
||||||
|
@ -44,8 +44,8 @@ func balancedResourceScorer(requested, allocable *schedulercache.Resource, inclu
|
||||||
// This to find a node which has most balanced CPU, memory and volume usage.
|
// This to find a node which has most balanced CPU, memory and volume usage.
|
||||||
if includeVolumes && utilfeature.DefaultFeatureGate.Enabled(features.BalanceAttachedNodeVolumes) && allocatableVolumes > 0 {
|
if includeVolumes && utilfeature.DefaultFeatureGate.Enabled(features.BalanceAttachedNodeVolumes) && allocatableVolumes > 0 {
|
||||||
volumeFraction := float64(requestedVolumes) / float64(allocatableVolumes)
|
volumeFraction := float64(requestedVolumes) / float64(allocatableVolumes)
|
||||||
if cpuFraction >= 1 || memoryFraction >= 1 || volumeFraction >= 1 {
|
if cpuFraction > 1 || memoryFraction > 1 || volumeFraction > 1 {
|
||||||
// if requested >= capacity, the corresponding host should never be preferred.
|
// if requested > capacity, the corresponding host should never be preferred.
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
// Compute variance for all the three fractions.
|
// Compute variance for all the three fractions.
|
||||||
|
@ -57,8 +57,8 @@ func balancedResourceScorer(requested, allocable *schedulercache.Resource, inclu
|
||||||
return int64((1 - variance) * float64(schedulerapi.MaxPriority))
|
return int64((1 - variance) * float64(schedulerapi.MaxPriority))
|
||||||
}
|
}
|
||||||
|
|
||||||
if cpuFraction >= 1 || memoryFraction >= 1 {
|
if cpuFraction > 1 || memoryFraction > 1 {
|
||||||
// if requested >= capacity, the corresponding host should never be preferred.
|
// if requested > capacity, the corresponding host should never be preferred.
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
// Upper and lower boundary of difference between cpuFraction and memoryFraction are -1 and 1
|
// Upper and lower boundary of difference between cpuFraction and memoryFraction are -1 and 1
|
||||||
|
@ -71,7 +71,7 @@ func balancedResourceScorer(requested, allocable *schedulercache.Resource, inclu
|
||||||
|
|
||||||
func fractionOfCapacity(requested, capacity int64) float64 {
|
func fractionOfCapacity(requested, capacity int64) float64 {
|
||||||
if capacity == 0 {
|
if capacity == 0 {
|
||||||
return 1
|
return math.MaxFloat64
|
||||||
}
|
}
|
||||||
return float64(requested) / float64(capacity)
|
return float64(requested) / float64(capacity)
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ func calculateScoreFromSize(sumSize int64) int {
|
||||||
switch {
|
switch {
|
||||||
case sumSize == 0 || sumSize < minImgSize:
|
case sumSize == 0 || sumSize < minImgSize:
|
||||||
// 0 means none of the images required by this pod are present on this
|
// 0 means none of the images required by this pod are present on this
|
||||||
// node or the total size of the images present is too small to be taken into further consideration.
|
// node or the total size of the images present are too small to be taken into further consideration.
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
case sumSize >= maxImgSize:
|
case sumSize >= maxImgSize:
|
||||||
|
|
|
@ -29,7 +29,7 @@ var (
|
||||||
// prioritizes based on the minimum of the average of the fraction of requested to capacity.
|
// prioritizes based on the minimum of the average of the fraction of requested to capacity.
|
||||||
//
|
//
|
||||||
// Details:
|
// Details:
|
||||||
// cpu((capacity-sum(requested))*10/capacity) + memory((capacity-sum(requested))*10/capacity)/2
|
// (cpu((capacity-sum(requested))*10/capacity) + memory((capacity-sum(requested))*10/capacity))/2
|
||||||
LeastRequestedPriorityMap = leastResourcePriority.PriorityMap
|
LeastRequestedPriorityMap = leastResourcePriority.PriorityMap
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -39,10 +39,10 @@ func mostResourceScorer(requested, allocable *schedulercache.Resource, includeVo
|
||||||
// The used capacity is calculated on a scale of 0-10
|
// The used capacity is calculated on a scale of 0-10
|
||||||
// 0 being the lowest priority and 10 being the highest.
|
// 0 being the lowest priority and 10 being the highest.
|
||||||
// The more resources are used the higher the score is. This function
|
// The more resources are used the higher the score is. This function
|
||||||
// is almost a reversed version of least_requested_priority.calculatUnusedScore
|
// is almost a reversed version of least_requested_priority.calculateUnusedScore
|
||||||
// (10 - calculateUnusedScore). The main difference is in rounding. It was added to
|
// (10 - calculateUnusedScore). The main difference is in rounding. It was added to
|
||||||
// keep the final formula clean and not to modify the widely used (by users
|
// keep the final formula clean and not to modify the widely used (by users
|
||||||
// in their default scheduling policies) calculateUSedScore.
|
// in their default scheduling policies) calculateUsedScore.
|
||||||
func mostRequestedScore(requested, capacity int64) int64 {
|
func mostRequestedScore(requested, capacity int64) int64 {
|
||||||
if capacity == 0 {
|
if capacity == 0 {
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -70,7 +70,7 @@ func ResourceLimitsPriorityMap(pod *v1.Pod, meta interface{}, nodeInfo *schedule
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// computeScore return 1 if limit value is less than or equal to allocable
|
// computeScore returns 1 if limit value is less than or equal to allocatable
|
||||||
// value, otherwise it returns 0.
|
// value, otherwise it returns 0.
|
||||||
func computeScore(limit, allocatable int64) int64 {
|
func computeScore(limit, allocatable int64) int64 {
|
||||||
if limit != 0 && allocatable != 0 && limit <= allocatable {
|
if limit != 0 && allocatable != 0 && limit <= allocatable {
|
||||||
|
|
Loading…
Reference in New Issue