Merge pull request #72140 from wgliang/feature/adaptive-percentage-find-nodes

Set percentage of nodes scored in each cycle dynamically based on the…
This commit is contained in:
Kubernetes Prow Robot 2018-12-20 12:36:45 -08:00 committed by GitHub
commit 29b3ec9108
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 77 additions and 15 deletions

View File

@ -225,8 +225,7 @@ users:
Burst: 100, Burst: 100,
ContentType: "application/vnd.kubernetes.protobuf", ContentType: "application/vnd.kubernetes.protobuf",
}, },
PercentageOfNodesToScore: 50, BindTimeoutSeconds: &defaultBindTimeoutSeconds,
BindTimeoutSeconds: &defaultBindTimeoutSeconds,
}, },
}, },
{ {
@ -306,8 +305,7 @@ users:
Burst: 100, Burst: 100,
ContentType: "application/vnd.kubernetes.protobuf", ContentType: "application/vnd.kubernetes.protobuf",
}, },
PercentageOfNodesToScore: 50, BindTimeoutSeconds: &defaultBindTimeoutSeconds,
BindTimeoutSeconds: &defaultBindTimeoutSeconds,
}, },
}, },
{ {

View File

@ -79,7 +79,8 @@ type KubeSchedulerConfiguration struct {
// at least "minFeasibleNodesToFind" feasible nodes no matter what the value of this flag is. // 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, // 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. // 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 PercentageOfNodesToScore int32
// DEPRECATED. // DEPRECATED.

View File

@ -81,11 +81,6 @@ func SetDefaults_KubeSchedulerConfiguration(obj *kubescedulerconfigv1alpha1.Kube
obj.LeaderElection.LockObjectName = kubescedulerconfigv1alpha1.SchedulerDefaultLockObjectName 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 { if len(obj.FailureDomains) == 0 {
obj.FailureDomains = kubeletapis.DefaultFailureDomains obj.FailureDomains = kubeletapis.DefaultFailureDomains
} }

View File

@ -54,6 +54,11 @@ const (
// certain minimum of nodes are checked for feasibility. This in turn helps // certain minimum of nodes are checked for feasibility. This in turn helps
// ensure a minimum level of spreading. // ensure a minimum level of spreading.
minFeasibleNodesToFind = 100 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. // 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 // numFeasibleNodesToFind returns the number of feasible nodes that once found, the scheduler stops
// its search for more feasible nodes. // its search for more feasible nodes.
func (g *genericScheduler) numFeasibleNodesToFind(numAllNodes int32) int32 { func (g *genericScheduler) numFeasibleNodesToFind(numAllNodes int32) (numNodes int32) {
if numAllNodes < minFeasibleNodesToFind || g.percentageOfNodesToScore <= 0 || if numAllNodes < minFeasibleNodesToFind || g.percentageOfNodesToScore >= 100 {
g.percentageOfNodesToScore >= 100 {
return numAllNodes 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 { if numNodes < minFeasibleNodesToFind {
return minFeasibleNodesToFind return minFeasibleNodesToFind
} }
return numNodes return numNodes
} }

View File

@ -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)
}
})
}
}

View File

@ -75,7 +75,8 @@ type KubeSchedulerConfiguration struct {
// at least "minFeasibleNodesToFind" feasible nodes no matter what the value of this flag is. // 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, // 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. // 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"` PercentageOfNodesToScore int32 `json:"percentageOfNodesToScore"`
// DEPRECATED. // DEPRECATED.