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
8465625b
Commit
8465625b
authored
Oct 31, 2017
by
Yongkun Anfernee Gui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize the suboptimal image locality algorithm
parent
35e97841
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
20 deletions
+22
-20
image_locality.go
plugin/pkg/scheduler/algorithm/priorities/image_locality.go
+22
-20
No files found.
plugin/pkg/scheduler/algorithm/priorities/image_locality.go
View file @
8465625b
...
...
@@ -35,10 +35,8 @@ func ImageLocalityPriorityMap(pod *v1.Pod, meta interface{}, nodeInfo *scheduler
return
schedulerapi
.
HostPriority
{},
fmt
.
Errorf
(
"node not found"
)
}
var
sumSize
int64
for
i
:=
range
pod
.
Spec
.
Containers
{
sumSize
+=
checkContainerImageOnNode
(
node
,
&
pod
.
Spec
.
Containers
[
i
])
}
sumSize
:=
totalImageSize
(
node
,
pod
.
Spec
.
Containers
)
return
schedulerapi
.
HostPriority
{
Host
:
node
.
Name
,
Score
:
calculateScoreFromSize
(
sumSize
),
...
...
@@ -49,31 +47,35 @@ func ImageLocalityPriorityMap(pod *v1.Pod, meta interface{}, nodeInfo *scheduler
// 1. Split image size range into 10 buckets.
// 2. Decide the priority of a given sumSize based on which bucket it belongs to.
func
calculateScoreFromSize
(
sumSize
int64
)
int
{
var
score
int
switch
{
case
sumSize
==
0
||
sumSize
<
minImgSize
:
//
score ==
0 means none of the images required by this pod are present on this
// 0 means none of the images required by this pod are present on this
// node or the total size of the images present is too small to be taken into further consideration.
score
=
0
// If existing images' total size is larger than max, just make it highest priority.
return
0
case
sumSize
>=
maxImgSize
:
score
=
schedulerapi
.
MaxPriority
default
:
score
=
int
((
int64
(
schedulerapi
.
MaxPriority
)
*
(
sumSize
-
minImgSize
)
/
(
maxImgSize
-
minImgSize
))
+
1
)
// If existing images' total size is larger than max, just make it highest priority.
return
schedulerapi
.
MaxPriority
}
// Return which bucket the given size belongs to
return
score
return
int
((
int64
(
schedulerapi
.
MaxPriority
)
*
(
sumSize
-
minImgSize
)
/
(
maxImgSize
-
minImgSize
))
+
1
)
}
// checkContainerImageOnNode checks if a container image is present on a node and returns its size.
func
checkContainerImageOnNode
(
node
*
v1
.
Node
,
container
*
v1
.
Container
)
int64
{
// totalImageSize returns the total image size of all the containers that are already on the node.
func
totalImageSize
(
node
*
v1
.
Node
,
containers
[]
v1
.
Container
)
int64
{
imageSizes
:=
make
(
map
[
string
]
int64
)
for
_
,
image
:=
range
node
.
Status
.
Images
{
for
_
,
name
:=
range
image
.
Names
{
if
container
.
Image
==
name
{
// Should return immediately.
return
image
.
SizeBytes
}
imageSizes
[
name
]
=
image
.
SizeBytes
}
}
return
0
var
total
int64
for
_
,
container
:=
range
containers
{
if
size
,
ok
:=
imageSizes
[
container
.
Image
];
ok
{
total
+=
size
}
}
return
total
}
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