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
ff765ed4
Commit
ff765ed4
authored
Sep 13, 2016
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Compute priorities in parallel
parent
13357bd6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
49 deletions
+70
-49
generic_scheduler.go
plugin/pkg/scheduler/generic_scheduler.go
+70
-49
No files found.
plugin/pkg/scheduler/generic_scheduler.go
View file @
ff765ed4
...
@@ -238,8 +238,6 @@ func PrioritizeNodes(
...
@@ -238,8 +238,6 @@ func PrioritizeNodes(
nodes
[]
*
api
.
Node
,
nodes
[]
*
api
.
Node
,
extenders
[]
algorithm
.
SchedulerExtender
,
extenders
[]
algorithm
.
SchedulerExtender
,
)
(
schedulerapi
.
HostPriorityList
,
error
)
{
)
(
schedulerapi
.
HostPriorityList
,
error
)
{
result
:=
make
(
schedulerapi
.
HostPriorityList
,
0
,
len
(
nodes
))
// If no priority configs are provided, then the EqualPriority function is applied
// If no priority configs are provided, then the EqualPriority function is applied
// This is required to generate the priority list in the required format
// This is required to generate the priority list in the required format
if
len
(
priorityConfigs
)
==
0
&&
len
(
extenders
)
==
0
{
if
len
(
priorityConfigs
)
==
0
&&
len
(
extenders
)
==
0
{
...
@@ -247,63 +245,82 @@ func PrioritizeNodes(
...
@@ -247,63 +245,82 @@ func PrioritizeNodes(
}
}
var
(
var
(
mu
=
sync
.
Mutex
{}
mu
=
sync
.
Mutex
{}
wg
=
sync
.
WaitGroup
{}
wg
=
sync
.
WaitGroup
{}
combinedScores
=
make
(
map
[
string
]
int
,
len
(
nodeNameToInfo
))
errs
[]
error
errs
[]
error
)
)
appendError
:=
func
(
err
error
)
{
mu
.
Lock
()
defer
mu
.
Unlock
()
errs
=
append
(
errs
,
err
)
}
meta
:=
priorities
.
PriorityMetadata
(
pod
,
nodes
)
meta
:=
priorities
.
PriorityMetadata
(
pod
,
nodes
)
for
_
,
priorityConfig
:=
range
priorityConfigs
{
results
:=
make
([]
schedulerapi
.
HostPriorityList
,
0
,
len
(
priorityConfigs
))
// skip the priority function if the weight is specified as 0
for
range
priorityConfigs
{
if
priorityConfig
.
Weight
==
0
{
results
=
append
(
results
,
nil
)
continue
}
}
for
i
,
priorityConfig
:=
range
priorityConfigs
{
if
priorityConfig
.
Function
!=
nil
{
wg
.
Add
(
1
)
// DEPRECATED
go
func
(
config
algorithm
.
PriorityConfig
)
{
wg
.
Add
(
1
)
defer
wg
.
Done
()
go
func
(
index
int
,
config
algorithm
.
PriorityConfig
)
{
weight
:=
config
.
Weight
defer
wg
.
Done
()
var
err
error
prioritizedList
,
err
:=
func
()
(
schedulerapi
.
HostPriorityList
,
error
)
{
results
[
index
],
err
=
config
.
Function
(
pod
,
nodeNameToInfo
,
nodes
)
if
config
.
Function
!=
nil
{
if
err
!=
nil
{
return
config
.
Function
(
pod
,
nodeNameToInfo
,
nodes
)
appendError
(
err
)
}
prioritizedList
:=
make
(
schedulerapi
.
HostPriorityList
,
0
,
len
(
nodes
))
for
i
:=
range
nodes
{
hostResult
,
err
:=
config
.
Map
(
pod
,
meta
,
nodeNameToInfo
[
nodes
[
i
]
.
Name
])
if
err
!=
nil
{
return
nil
,
err
}
prioritizedList
=
append
(
prioritizedList
,
hostResult
)
}
if
config
.
Reduce
!=
nil
{
if
err
:=
config
.
Reduce
(
prioritizedList
);
err
!=
nil
{
return
nil
,
err
}
}
}
return
prioritizedList
,
nil
}(
i
,
priorityConfig
)
}()
}
else
{
results
[
i
]
=
make
(
schedulerapi
.
HostPriorityList
,
len
(
nodes
))
mu
.
Lock
()
}
defer
mu
.
Unlock
()
}
processNode
:=
func
(
index
int
)
{
nodeInfo
:=
nodeNameToInfo
[
nodes
[
index
]
.
Name
]
var
err
error
for
i
:=
range
priorityConfigs
{
if
priorityConfigs
[
i
]
.
Function
!=
nil
{
continue
}
results
[
i
][
index
],
err
=
priorityConfigs
[
i
]
.
Map
(
pod
,
meta
,
nodeInfo
)
if
err
!=
nil
{
if
err
!=
nil
{
errs
=
append
(
errs
,
err
)
appendError
(
err
)
return
return
}
}
for
i
:=
range
prioritizedList
{
}
host
,
score
:=
prioritizedList
[
i
]
.
Host
,
prioritizedList
[
i
]
.
Score
}
combinedScores
[
host
]
+=
score
*
weight
workqueue
.
Parallelize
(
16
,
len
(
nodes
),
processNode
)
for
i
,
priorityConfig
:=
range
priorityConfigs
{
if
priorityConfig
.
Reduce
==
nil
{
continue
}
wg
.
Add
(
1
)
go
func
(
index
int
,
config
algorithm
.
PriorityConfig
)
{
defer
wg
.
Done
()
if
err
:=
config
.
Reduce
(
results
[
index
]);
err
!=
nil
{
appendError
(
err
)
}
}
}(
priorityConfig
)
}(
i
,
priorityConfig
)
}
}
//
wait for all go routines to finish
//
Wait for all computations to be finished.
wg
.
Wait
()
wg
.
Wait
()
if
len
(
errs
)
!=
0
{
if
len
(
errs
)
!=
0
{
return
schedulerapi
.
HostPriorityList
{},
errors
.
NewAggregate
(
errs
)
return
schedulerapi
.
HostPriorityList
{},
errors
.
NewAggregate
(
errs
)
}
}
// Summarize all scores.
result
:=
make
(
schedulerapi
.
HostPriorityList
,
0
,
len
(
nodes
))
// TODO: Consider parallelizing it.
for
i
:=
range
nodes
{
result
=
append
(
result
,
schedulerapi
.
HostPriority
{
Host
:
nodes
[
i
]
.
Name
,
Score
:
0
})
for
j
:=
range
priorityConfigs
{
result
[
i
]
.
Score
+=
results
[
j
][
i
]
.
Score
*
priorityConfigs
[
j
]
.
Weight
}
}
if
len
(
extenders
)
!=
0
&&
nodes
!=
nil
{
if
len
(
extenders
)
!=
0
&&
nodes
!=
nil
{
combinedScores
:=
make
(
map
[
string
]
int
,
len
(
nodeNameToInfo
))
for
_
,
extender
:=
range
extenders
{
for
_
,
extender
:=
range
extenders
{
wg
.
Add
(
1
)
wg
.
Add
(
1
)
go
func
(
ext
algorithm
.
SchedulerExtender
)
{
go
func
(
ext
algorithm
.
SchedulerExtender
)
{
...
@@ -321,13 +338,17 @@ func PrioritizeNodes(
...
@@ -321,13 +338,17 @@ func PrioritizeNodes(
mu
.
Unlock
()
mu
.
Unlock
()
}(
extender
)
}(
extender
)
}
}
// wait for all go routines to finish
wg
.
Wait
()
for
i
:=
range
result
{
result
[
i
]
.
Score
+=
combinedScores
[
result
[
i
]
.
Host
]
}
}
}
// wait for all go routines to finish
wg
.
Wait
()
for
host
,
score
:=
range
combinedScores
{
if
glog
.
V
(
10
)
{
glog
.
V
(
10
)
.
Infof
(
"Host %s Score %d"
,
host
,
score
)
for
i
:=
range
result
{
result
=
append
(
result
,
schedulerapi
.
HostPriority
{
Host
:
host
,
Score
:
score
})
glog
.
V
(
10
)
.
Infof
(
"Host %s => Score %d"
,
result
[
i
]
.
Host
,
result
[
i
]
.
Score
)
}
}
}
return
result
,
nil
return
result
,
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