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
8a9ed4c9
Unverified
Commit
8a9ed4c9
authored
Apr 09, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Apr 09, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #76243 from Huang-Wei/perf-podaffinity
scheduler: performance improvement on PodAffinity
parents
c4f97fa2
28730919
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
23 deletions
+20
-23
interpod_affinity.go
pkg/scheduler/algorithm/priorities/interpod_affinity.go
+20
-23
No files found.
pkg/scheduler/algorithm/priorities/interpod_affinity.go
View file @
8a9ed4c9
...
...
@@ -19,6 +19,7 @@ package priorities
import
(
"context"
"sync"
"sync/atomic"
"k8s.io/api/core/v1"
apierrors
"k8s.io/apimachinery/pkg/api/errors"
...
...
@@ -63,7 +64,7 @@ type podAffinityPriorityMap struct {
nodes
[]
*
v1
.
Node
// counts store the mapping from node name to so-far computed score of
// the node.
counts
map
[
string
]
floa
t64
counts
map
[
string
]
*
in
t64
// The first error that we faced.
firstError
error
}
...
...
@@ -71,7 +72,7 @@ type podAffinityPriorityMap struct {
func
newPodAffinityPriorityMap
(
nodes
[]
*
v1
.
Node
)
*
podAffinityPriorityMap
{
return
&
podAffinityPriorityMap
{
nodes
:
nodes
,
counts
:
make
(
map
[
string
]
floa
t64
,
len
(
nodes
)),
counts
:
make
(
map
[
string
]
*
in
t64
,
len
(
nodes
)),
}
}
...
...
@@ -83,7 +84,7 @@ func (p *podAffinityPriorityMap) setError(err error) {
}
}
func
(
p
*
podAffinityPriorityMap
)
processTerm
(
term
*
v1
.
PodAffinityTerm
,
podDefiningAffinityTerm
,
podToCheck
*
v1
.
Pod
,
fixedNode
*
v1
.
Node
,
weight
floa
t64
)
{
func
(
p
*
podAffinityPriorityMap
)
processTerm
(
term
*
v1
.
PodAffinityTerm
,
podDefiningAffinityTerm
,
podToCheck
*
v1
.
Pod
,
fixedNode
*
v1
.
Node
,
weight
in
t64
)
{
namespaces
:=
priorityutil
.
GetNamespacesFromPodAffinityTerm
(
podDefiningAffinityTerm
,
term
)
selector
,
err
:=
metav1
.
LabelSelectorAsSelector
(
term
.
LabelSelector
)
if
err
!=
nil
{
...
...
@@ -92,22 +93,18 @@ func (p *podAffinityPriorityMap) processTerm(term *v1.PodAffinityTerm, podDefini
}
match
:=
priorityutil
.
PodMatchesTermsNamespaceAndSelector
(
podToCheck
,
namespaces
,
selector
)
if
match
{
func
()
{
p
.
Lock
()
defer
p
.
Unlock
()
for
_
,
node
:=
range
p
.
nodes
{
if
priorityutil
.
NodesHaveSameTopologyKey
(
node
,
fixedNode
,
term
.
TopologyKey
)
{
p
.
counts
[
node
.
Name
]
+=
weight
}
for
_
,
node
:=
range
p
.
nodes
{
if
priorityutil
.
NodesHaveSameTopologyKey
(
node
,
fixedNode
,
term
.
TopologyKey
)
{
atomic
.
AddInt64
(
p
.
counts
[
node
.
Name
],
weight
)
}
}
()
}
}
}
func
(
p
*
podAffinityPriorityMap
)
processTerms
(
terms
[]
v1
.
WeightedPodAffinityTerm
,
podDefiningAffinityTerm
,
podToCheck
*
v1
.
Pod
,
fixedNode
*
v1
.
Node
,
multiplier
int
)
{
for
i
:=
range
terms
{
term
:=
&
terms
[
i
]
p
.
processTerm
(
&
term
.
PodAffinityTerm
,
podDefiningAffinityTerm
,
podToCheck
,
fixedNode
,
floa
t64
(
term
.
Weight
*
int32
(
multiplier
)))
p
.
processTerm
(
&
term
.
PodAffinityTerm
,
podDefiningAffinityTerm
,
podToCheck
,
fixedNode
,
in
t64
(
term
.
Weight
*
int32
(
multiplier
)))
}
}
...
...
@@ -121,17 +118,17 @@ func (ipa *InterPodAffinity) CalculateInterPodAffinityPriority(pod *v1.Pod, node
hasAffinityConstraints
:=
affinity
!=
nil
&&
affinity
.
PodAffinity
!=
nil
hasAntiAffinityConstraints
:=
affinity
!=
nil
&&
affinity
.
PodAntiAffinity
!=
nil
// priorityMap stores the mapping from node name to so-far computed score of
// the node.
pm
:=
newPodAffinityPriorityMap
(
nodes
)
allNodeNames
:=
make
([]
string
,
0
,
len
(
nodeNameToInfo
))
for
name
:=
range
nodeNameToInfo
{
allNodeNames
=
append
(
allNodeNames
,
name
)
pm
.
counts
[
name
]
=
new
(
int64
)
}
// convert the topology key based weights to the node name based weights
var
maxCount
float64
var
minCount
float64
// priorityMap stores the mapping from node name to so-far computed score of
// the node.
pm
:=
newPodAffinityPriorityMap
(
nodes
)
var
maxCount
,
minCount
int64
processPod
:=
func
(
existingPod
*
v1
.
Pod
)
error
{
existingPodNode
,
err
:=
ipa
.
info
.
GetNodeInfo
(
existingPod
.
Spec
.
NodeName
)
...
...
@@ -172,7 +169,7 @@ func (ipa *InterPodAffinity) CalculateInterPodAffinityPriority(pod *v1.Pod, node
// terms = append(terms, existingPodAffinity.PodAffinity.RequiredDuringSchedulingRequiredDuringExecution...)
//}
for
_
,
term
:=
range
terms
{
pm
.
processTerm
(
&
term
,
existingPod
,
pod
,
existingPodNode
,
floa
t64
(
ipa
.
hardPodAffinityWeight
))
pm
.
processTerm
(
&
term
,
existingPod
,
pod
,
existingPodNode
,
in
t64
(
ipa
.
hardPodAffinityWeight
))
}
}
// For every soft pod affinity term of <existingPod>, if <pod> matches the term,
...
...
@@ -217,11 +214,11 @@ func (ipa *InterPodAffinity) CalculateInterPodAffinityPriority(pod *v1.Pod, node
}
for
_
,
node
:=
range
nodes
{
if
pm
.
counts
[
node
.
Name
]
>
maxCount
{
maxCount
=
pm
.
counts
[
node
.
Name
]
if
*
pm
.
counts
[
node
.
Name
]
>
maxCount
{
maxCount
=
*
pm
.
counts
[
node
.
Name
]
}
if
pm
.
counts
[
node
.
Name
]
<
minCount
{
minCount
=
pm
.
counts
[
node
.
Name
]
if
*
pm
.
counts
[
node
.
Name
]
<
minCount
{
minCount
=
*
pm
.
counts
[
node
.
Name
]
}
}
...
...
@@ -230,7 +227,7 @@ func (ipa *InterPodAffinity) CalculateInterPodAffinityPriority(pod *v1.Pod, node
for
_
,
node
:=
range
nodes
{
fScore
:=
float64
(
0
)
if
(
maxCount
-
minCount
)
>
0
{
fScore
=
float64
(
schedulerapi
.
MaxPriority
)
*
(
(
pm
.
counts
[
node
.
Name
]
-
minCount
)
/
(
maxCount
-
minCount
))
fScore
=
float64
(
schedulerapi
.
MaxPriority
)
*
(
float64
(
*
pm
.
counts
[
node
.
Name
]
-
minCount
)
/
float64
(
maxCount
-
minCount
))
}
result
=
append
(
result
,
schedulerapi
.
HostPriority
{
Host
:
node
.
Name
,
Score
:
int
(
fScore
)})
if
klog
.
V
(
10
)
{
...
...
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