mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Set percentage of nodes scored in each cycle dynamically based on the cluster size
This commit is contained in:
parent
28b965a8c0
commit
6515c4e09b
@ -225,8 +225,7 @@ users:
|
||||
Burst: 100,
|
||||
ContentType: "application/vnd.kubernetes.protobuf",
|
||||
},
|
||||
PercentageOfNodesToScore: 50,
|
||||
BindTimeoutSeconds: &defaultBindTimeoutSeconds,
|
||||
BindTimeoutSeconds: &defaultBindTimeoutSeconds,
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -306,8 +305,7 @@ users:
|
||||
Burst: 100,
|
||||
ContentType: "application/vnd.kubernetes.protobuf",
|
||||
},
|
||||
PercentageOfNodesToScore: 50,
|
||||
BindTimeoutSeconds: &defaultBindTimeoutSeconds,
|
||||
BindTimeoutSeconds: &defaultBindTimeoutSeconds,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -79,7 +79,8 @@ type KubeSchedulerConfiguration struct {
|
||||
// at least "minFeasibleNodesToFind" feasible nodes no matter what the value of this flag is.
|
||||
// Example: if the cluster size is 500 nodes and the value of this flag is 30,
|
||||
// then scheduler stops finding further feasible nodes once it finds 150 feasible ones.
|
||||
// When the value is 0, default percentage (50%) of the nodes will be scored.
|
||||
// When the value is 0, default percentage (5%--50% based on the size of the cluster) of the
|
||||
// nodes will be scored.
|
||||
PercentageOfNodesToScore int32
|
||||
|
||||
// DEPRECATED.
|
||||
|
@ -81,11 +81,6 @@ func SetDefaults_KubeSchedulerConfiguration(obj *kubescedulerconfigv1alpha1.Kube
|
||||
obj.LeaderElection.LockObjectName = kubescedulerconfigv1alpha1.SchedulerDefaultLockObjectName
|
||||
}
|
||||
|
||||
if obj.PercentageOfNodesToScore == 0 {
|
||||
// by default, stop finding feasible nodes once the number of feasible nodes is 50% of the cluster.
|
||||
obj.PercentageOfNodesToScore = 50
|
||||
}
|
||||
|
||||
if len(obj.FailureDomains) == 0 {
|
||||
obj.FailureDomains = kubeletapis.DefaultFailureDomains
|
||||
}
|
||||
|
@ -54,6 +54,11 @@ const (
|
||||
// certain minimum of nodes are checked for feasibility. This in turn helps
|
||||
// ensure a minimum level of spreading.
|
||||
minFeasibleNodesToFind = 100
|
||||
// minFeasibleNodesPercentageToFind is the minimum percentage of nodes that
|
||||
// would be scored in each scheduling cycle. This is a semi-arbitrary value
|
||||
// to ensure that a certain minimum of nodes are checked for feasibility.
|
||||
// This in turn helps ensure a minimum level of spreading.
|
||||
minFeasibleNodesPercentageToFind = 5
|
||||
)
|
||||
|
||||
// FailedPredicateMap declares a map[string][]algorithm.PredicateFailureReason type.
|
||||
@ -375,15 +380,24 @@ func (g *genericScheduler) getLowerPriorityNominatedPods(pod *v1.Pod, nodeName s
|
||||
|
||||
// numFeasibleNodesToFind returns the number of feasible nodes that once found, the scheduler stops
|
||||
// its search for more feasible nodes.
|
||||
func (g *genericScheduler) numFeasibleNodesToFind(numAllNodes int32) int32 {
|
||||
if numAllNodes < minFeasibleNodesToFind || g.percentageOfNodesToScore <= 0 ||
|
||||
g.percentageOfNodesToScore >= 100 {
|
||||
func (g *genericScheduler) numFeasibleNodesToFind(numAllNodes int32) (numNodes int32) {
|
||||
if numAllNodes < minFeasibleNodesToFind || g.percentageOfNodesToScore >= 100 {
|
||||
return numAllNodes
|
||||
}
|
||||
numNodes := numAllNodes * g.percentageOfNodesToScore / 100
|
||||
|
||||
adaptivePercentage := g.percentageOfNodesToScore
|
||||
if adaptivePercentage <= 0 {
|
||||
adaptivePercentage = schedulerapi.DefaultPercentageOfNodesToScore - numAllNodes/125
|
||||
if adaptivePercentage < minFeasibleNodesPercentageToFind {
|
||||
adaptivePercentage = minFeasibleNodesPercentageToFind
|
||||
}
|
||||
}
|
||||
|
||||
numNodes = numAllNodes * adaptivePercentage / 100
|
||||
if numNodes < minFeasibleNodesToFind {
|
||||
return minFeasibleNodesToFind
|
||||
}
|
||||
|
||||
return numNodes
|
||||
}
|
||||
|
||||
|
@ -1483,3 +1483,56 @@ func TestPreempt(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNumFeasibleNodesToFind(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
percentageOfNodesToScore int32
|
||||
numAllNodes int32
|
||||
wantNumNodes int32
|
||||
}{
|
||||
{
|
||||
name: "not set percentageOfNodesToScore and nodes number not more than 50",
|
||||
numAllNodes: 10,
|
||||
wantNumNodes: 10,
|
||||
},
|
||||
{
|
||||
name: "set percentageOfNodesToScore and nodes number not more than 50",
|
||||
percentageOfNodesToScore: 40,
|
||||
numAllNodes: 10,
|
||||
wantNumNodes: 10,
|
||||
},
|
||||
{
|
||||
name: "not set percentageOfNodesToScore and nodes number more than 50",
|
||||
numAllNodes: 1000,
|
||||
wantNumNodes: 420,
|
||||
},
|
||||
{
|
||||
name: "set percentageOfNodesToScore and nodes number more than 50",
|
||||
percentageOfNodesToScore: 40,
|
||||
numAllNodes: 1000,
|
||||
wantNumNodes: 400,
|
||||
},
|
||||
{
|
||||
name: "not set percentageOfNodesToScore and nodes number more than 50*125",
|
||||
numAllNodes: 6000,
|
||||
wantNumNodes: 300,
|
||||
},
|
||||
{
|
||||
name: "set percentageOfNodesToScore and nodes number more than 50*125",
|
||||
percentageOfNodesToScore: 40,
|
||||
numAllNodes: 6000,
|
||||
wantNumNodes: 2400,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
g := &genericScheduler{
|
||||
percentageOfNodesToScore: tt.percentageOfNodesToScore,
|
||||
}
|
||||
if gotNumNodes := g.numFeasibleNodesToFind(tt.numAllNodes); gotNumNodes != tt.wantNumNodes {
|
||||
t.Errorf("genericScheduler.numFeasibleNodesToFind() = %v, want %v", gotNumNodes, tt.wantNumNodes)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,8 @@ type KubeSchedulerConfiguration struct {
|
||||
// at least "minFeasibleNodesToFind" feasible nodes no matter what the value of this flag is.
|
||||
// Example: if the cluster size is 500 nodes and the value of this flag is 30,
|
||||
// then scheduler stops finding further feasible nodes once it finds 150 feasible ones.
|
||||
// When the value is 0, default percentage (50%) of the nodes will be scored.
|
||||
// When the value is 0, default percentage (5%--50% based on the size of the cluster) of the
|
||||
// nodes will be scored.
|
||||
PercentageOfNodesToScore int32 `json:"percentageOfNodesToScore"`
|
||||
|
||||
// DEPRECATED.
|
||||
|
Loading…
Reference in New Issue
Block a user