Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
ffc8cc2f
Commit
ffc8cc2f
authored
Jun 22, 2018
by
Bobby (Babak) Salamat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve scheduler's performance by eliminating sorting when finding the host with the highest score
parent
5e9a5659
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
10 deletions
+20
-10
extender_test.go
pkg/scheduler/core/extender_test.go
+1
-1
generic_scheduler.go
pkg/scheduler/core/generic_scheduler.go
+19
-9
No files found.
pkg/scheduler/core/extender_test.go
View file @
ffc8cc2f
...
@@ -454,7 +454,7 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
...
@@ -454,7 +454,7 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
// because of the errors from errorPredicateExtender and/or
// because of the errors from errorPredicateExtender and/or
// errorPrioritizerExtender.
// errorPrioritizerExtender.
predicates
:
map
[
string
]
algorithm
.
FitPredicate
{
"true"
:
truePredicate
},
predicates
:
map
[
string
]
algorithm
.
FitPredicate
{
"true"
:
truePredicate
},
prioritizers
:
[]
algorithm
.
PriorityConfig
{{
Map
:
EqualPriorityMap
,
Weight
:
1
}},
prioritizers
:
[]
algorithm
.
PriorityConfig
{{
Function
:
machine2Prioritizer
,
Weight
:
1
}},
extenders
:
[]
FakeExtender
{
extenders
:
[]
FakeExtender
{
{
{
predicates
:
[]
fitPredicate
{
errorPredicateExtender
},
predicates
:
[]
fitPredicate
{
errorPredicateExtender
},
...
...
pkg/scheduler/core/generic_scheduler.go
View file @
ffc8cc2f
...
@@ -93,7 +93,6 @@ type genericScheduler struct {
...
@@ -93,7 +93,6 @@ type genericScheduler struct {
predicateMetaProducer
algorithm
.
PredicateMetadataProducer
predicateMetaProducer
algorithm
.
PredicateMetadataProducer
prioritizers
[]
algorithm
.
PriorityConfig
prioritizers
[]
algorithm
.
PriorityConfig
extenders
[]
algorithm
.
SchedulerExtender
extenders
[]
algorithm
.
SchedulerExtender
lastNodeIndexLock
sync
.
Mutex
lastNodeIndex
uint64
lastNodeIndex
uint64
alwaysCheckAllPredicates
bool
alwaysCheckAllPredicates
bool
cachedNodeInfoMap
map
[
string
]
*
schedulercache
.
NodeInfo
cachedNodeInfoMap
map
[
string
]
*
schedulercache
.
NodeInfo
...
@@ -176,6 +175,22 @@ func (g *genericScheduler) Predicates() map[string]algorithm.FitPredicate {
...
@@ -176,6 +175,22 @@ func (g *genericScheduler) Predicates() map[string]algorithm.FitPredicate {
return
g
.
predicates
return
g
.
predicates
}
}
// findMaxScores returns the indexes of nodes in the "priorityList" that has the highest "Score".
func
findMaxScores
(
priorityList
schedulerapi
.
HostPriorityList
)
[]
int
{
maxScoreIndexes
:=
make
([]
int
,
0
,
len
(
priorityList
)
/
2
)
maxScore
:=
priorityList
[
0
]
.
Score
for
i
,
hp
:=
range
priorityList
{
if
hp
.
Score
>
maxScore
{
maxScore
=
hp
.
Score
maxScoreIndexes
=
maxScoreIndexes
[
:
0
]
maxScoreIndexes
=
append
(
maxScoreIndexes
,
i
)
}
else
if
hp
.
Score
==
maxScore
{
maxScoreIndexes
=
append
(
maxScoreIndexes
,
i
)
}
}
return
maxScoreIndexes
}
// selectHost takes a prioritized list of nodes and then picks one
// selectHost takes a prioritized list of nodes and then picks one
// in a round-robin manner from the nodes that had the highest score.
// in a round-robin manner from the nodes that had the highest score.
func
(
g
*
genericScheduler
)
selectHost
(
priorityList
schedulerapi
.
HostPriorityList
)
(
string
,
error
)
{
func
(
g
*
genericScheduler
)
selectHost
(
priorityList
schedulerapi
.
HostPriorityList
)
(
string
,
error
)
{
...
@@ -183,16 +198,11 @@ func (g *genericScheduler) selectHost(priorityList schedulerapi.HostPriorityList
...
@@ -183,16 +198,11 @@ func (g *genericScheduler) selectHost(priorityList schedulerapi.HostPriorityList
return
""
,
fmt
.
Errorf
(
"empty priorityList"
)
return
""
,
fmt
.
Errorf
(
"empty priorityList"
)
}
}
sort
.
Sort
(
sort
.
Reverse
(
priorityList
))
maxScores
:=
findMaxScores
(
priorityList
)
maxScore
:=
priorityList
[
0
]
.
Score
ix
:=
int
(
g
.
lastNodeIndex
%
uint64
(
len
(
maxScores
)))
firstAfterMaxScore
:=
sort
.
Search
(
len
(
priorityList
),
func
(
i
int
)
bool
{
return
priorityList
[
i
]
.
Score
<
maxScore
})
g
.
lastNodeIndexLock
.
Lock
()
ix
:=
int
(
g
.
lastNodeIndex
%
uint64
(
firstAfterMaxScore
))
g
.
lastNodeIndex
++
g
.
lastNodeIndex
++
g
.
lastNodeIndexLock
.
Unlock
()
return
priorityList
[
ix
]
.
Host
,
nil
return
priorityList
[
maxScores
[
ix
]
]
.
Host
,
nil
}
}
// preempt finds nodes with pods that can be preempted to make room for "pod" to
// preempt finds nodes with pods that can be preempted to make room for "pod" to
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment