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
5a083f20
Commit
5a083f20
authored
Feb 13, 2018
by
tossmilestone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reuse the "min*Nodes" slices to save the GC time.
parent
69324f90
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
24 deletions
+35
-24
generic_scheduler.go
pkg/scheduler/core/generic_scheduler.go
+35
-24
No files found.
pkg/scheduler/core/generic_scheduler.go
View file @
5a083f20
...
@@ -677,13 +677,15 @@ func EqualPriorityMap(_ *v1.Pod, _ interface{}, nodeInfo *schedulercache.NodeInf
...
@@ -677,13 +677,15 @@ func EqualPriorityMap(_ *v1.Pod, _ interface{}, nodeInfo *schedulercache.NodeInf
// 3. Ties are broken by sum of priorities of all victims.
// 3. Ties are broken by sum of priorities of all victims.
// 4. If there are still ties, node with the minimum number of victims is picked.
// 4. If there are still ties, node with the minimum number of victims is picked.
// 5. If there are still ties, the first such node is picked (sort of randomly).
// 5. If there are still ties, the first such node is picked (sort of randomly).
//TODO(bsalamat): Try to reuse the "min*Nodes" slices in order to save GC time.
// The 'minNodes1' and 'minNodes2' are being reused here to save the memory
// allocation and garbage collection time.
func
pickOneNodeForPreemption
(
nodesToVictims
map
[
*
v1
.
Node
]
*
Victims
)
*
v1
.
Node
{
func
pickOneNodeForPreemption
(
nodesToVictims
map
[
*
v1
.
Node
]
*
Victims
)
*
v1
.
Node
{
if
len
(
nodesToVictims
)
==
0
{
if
len
(
nodesToVictims
)
==
0
{
return
nil
return
nil
}
}
minNumPDBViolatingPods
:=
math
.
MaxInt32
minNumPDBViolatingPods
:=
math
.
MaxInt32
var
minPDBViolatingNodes
[]
*
v1
.
Node
var
minNodes1
[]
*
v1
.
Node
lenNodes1
:=
0
for
node
,
victims
:=
range
nodesToVictims
{
for
node
,
victims
:=
range
nodesToVictims
{
if
len
(
victims
.
pods
)
==
0
{
if
len
(
victims
.
pods
)
==
0
{
// We found a node that doesn't need any preemption. Return it!
// We found a node that doesn't need any preemption. Return it!
...
@@ -695,42 +697,48 @@ func pickOneNodeForPreemption(nodesToVictims map[*v1.Node]*Victims) *v1.Node {
...
@@ -695,42 +697,48 @@ func pickOneNodeForPreemption(nodesToVictims map[*v1.Node]*Victims) *v1.Node {
numPDBViolatingPods
:=
victims
.
numPDBViolations
numPDBViolatingPods
:=
victims
.
numPDBViolations
if
numPDBViolatingPods
<
minNumPDBViolatingPods
{
if
numPDBViolatingPods
<
minNumPDBViolatingPods
{
minNumPDBViolatingPods
=
numPDBViolatingPods
minNumPDBViolatingPods
=
numPDBViolatingPods
minPDBViolatingNodes
=
nil
minNodes1
=
nil
lenNodes1
=
0
}
}
if
numPDBViolatingPods
==
minNumPDBViolatingPods
{
if
numPDBViolatingPods
==
minNumPDBViolatingPods
{
minPDBViolatingNodes
=
append
(
minPDBViolatingNodes
,
node
)
minNodes1
=
append
(
minNodes1
,
node
)
lenNodes1
++
}
}
}
}
if
len
(
minPDBViolatingNodes
)
==
1
{
if
len
Nodes1
==
1
{
return
min
PDBViolatingNodes
[
0
]
return
min
Nodes1
[
0
]
}
}
// There are more than one node with minimum number PDB violating pods. Find
// There are more than one node with minimum number PDB violating pods. Find
// the one with minimum highest priority victim.
// the one with minimum highest priority victim.
minHighestPriority
:=
int32
(
math
.
MaxInt32
)
minHighestPriority
:=
int32
(
math
.
MaxInt32
)
var
minPriorityNodes
[]
*
v1
.
Node
var
minNodes2
=
make
([]
*
v1
.
Node
,
lenNodes1
)
for
_
,
node
:=
range
minPDBViolatingNodes
{
lenNodes2
:=
0
for
i
:=
0
;
i
<
lenNodes1
;
i
++
{
node
:=
minNodes1
[
i
]
victims
:=
nodesToVictims
[
node
]
victims
:=
nodesToVictims
[
node
]
// highestPodPriority is the highest priority among the victims on this node.
// highestPodPriority is the highest priority among the victims on this node.
highestPodPriority
:=
util
.
GetPodPriority
(
victims
.
pods
[
0
])
highestPodPriority
:=
util
.
GetPodPriority
(
victims
.
pods
[
0
])
if
highestPodPriority
<
minHighestPriority
{
if
highestPodPriority
<
minHighestPriority
{
minHighestPriority
=
highestPodPriority
minHighestPriority
=
highestPodPriority
minPriorityNodes
=
nil
lenNodes2
=
0
}
}
if
highestPodPriority
==
minHighestPriority
{
if
highestPodPriority
==
minHighestPriority
{
minPriorityNodes
=
append
(
minPriorityNodes
,
node
)
minNodes2
[
lenNodes2
]
=
node
lenNodes2
++
}
}
}
}
if
len
(
minPriorityNodes
)
==
1
{
if
len
Nodes2
==
1
{
return
min
PriorityNodes
[
0
]
return
min
Nodes2
[
0
]
}
}
// There are a few nodes with minimum highest priority victim. Find the
// There are a few nodes with minimum highest priority victim. Find the
// smallest sum of priorities.
// smallest sum of priorities.
minSumPriorities
:=
int64
(
math
.
MaxInt64
)
minSumPriorities
:=
int64
(
math
.
MaxInt64
)
var
minSumPriorityNodes
[]
*
v1
.
Node
lenNodes1
=
0
for
_
,
node
:=
range
minPriorityNodes
{
for
i
:=
0
;
i
<
lenNodes2
;
i
++
{
var
sumPriorities
int64
var
sumPriorities
int64
node
:=
minNodes2
[
i
]
for
_
,
pod
:=
range
nodesToVictims
[
node
]
.
pods
{
for
_
,
pod
:=
range
nodesToVictims
[
node
]
.
pods
{
// We add MaxInt32+1 to all priorities to make all of them >= 0. This is
// We add MaxInt32+1 to all priorities to make all of them >= 0. This is
// needed so that a node with a few pods with negative priority is not
// needed so that a node with a few pods with negative priority is not
...
@@ -740,34 +748,37 @@ func pickOneNodeForPreemption(nodesToVictims map[*v1.Node]*Victims) *v1.Node {
...
@@ -740,34 +748,37 @@ func pickOneNodeForPreemption(nodesToVictims map[*v1.Node]*Victims) *v1.Node {
}
}
if
sumPriorities
<
minSumPriorities
{
if
sumPriorities
<
minSumPriorities
{
minSumPriorities
=
sumPriorities
minSumPriorities
=
sumPriorities
minSumPriorityNodes
=
nil
lenNodes1
=
0
}
}
if
sumPriorities
==
minSumPriorities
{
if
sumPriorities
==
minSumPriorities
{
minSumPriorityNodes
=
append
(
minSumPriorityNodes
,
node
)
minNodes1
[
lenNodes1
]
=
node
lenNodes1
++
}
}
}
}
if
len
(
minSumPriorityNodes
)
==
1
{
if
len
Nodes1
==
1
{
return
min
SumPriorityNodes
[
0
]
return
min
Nodes1
[
0
]
}
}
// There are a few nodes with minimum highest priority victim and sum of priorities.
// There are a few nodes with minimum highest priority victim and sum of priorities.
// Find one with the minimum number of pods.
// Find one with the minimum number of pods.
minNumPods
:=
math
.
MaxInt32
minNumPods
:=
math
.
MaxInt32
var
minNumPodNodes
[]
*
v1
.
Node
lenNodes2
=
0
for
_
,
node
:=
range
minSumPriorityNodes
{
for
i
:=
0
;
i
<
lenNodes1
;
i
++
{
node
:=
minNodes1
[
i
]
numPods
:=
len
(
nodesToVictims
[
node
]
.
pods
)
numPods
:=
len
(
nodesToVictims
[
node
]
.
pods
)
if
numPods
<
minNumPods
{
if
numPods
<
minNumPods
{
minNumPods
=
numPods
minNumPods
=
numPods
minNumPodNodes
=
nil
lenNodes2
=
0
}
}
if
numPods
==
minNumPods
{
if
numPods
==
minNumPods
{
minNumPodNodes
=
append
(
minNumPodNodes
,
node
)
minNodes2
[
lenNodes2
]
=
node
lenNodes2
++
}
}
}
}
// At this point, even if there are more than one node with the same score,
// At this point, even if there are more than one node with the same score,
// return the first one.
// return the first one.
if
len
(
minNumPodNodes
)
>
0
{
if
len
Nodes2
>
0
{
return
minN
umPodNodes
[
0
]
return
minN
odes2
[
0
]
}
}
glog
.
Errorf
(
"Error in logic of node scoring for preemption. We should never reach here!"
)
glog
.
Errorf
(
"Error in logic of node scoring for preemption. We should never reach here!"
)
return
nil
return
nil
...
...
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