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
2c52e626
Commit
2c52e626
authored
Mar 03, 2016
by
gmarek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change scheduler logic from random to round-robin
parent
f54afa0a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
20 deletions
+21
-20
generic_scheduler.go
plugin/pkg/scheduler/generic_scheduler.go
+21
-20
No files found.
plugin/pkg/scheduler/generic_scheduler.go
View file @
2c52e626
...
@@ -20,6 +20,7 @@ import (
...
@@ -20,6 +20,7 @@ import (
"bytes"
"bytes"
"fmt"
"fmt"
"math/rand"
"math/rand"
"sort"
"strings"
"strings"
"sync"
"sync"
...
@@ -55,12 +56,13 @@ func (f *FitError) Error() string {
...
@@ -55,12 +56,13 @@ func (f *FitError) Error() string {
}
}
type
genericScheduler
struct
{
type
genericScheduler
struct
{
predicates
map
[
string
]
algorithm
.
FitPredicate
predicates
map
[
string
]
algorithm
.
FitPredicate
prioritizers
[]
algorithm
.
PriorityConfig
prioritizers
[]
algorithm
.
PriorityConfig
extenders
[]
algorithm
.
SchedulerExtender
extenders
[]
algorithm
.
SchedulerExtender
pods
algorithm
.
PodLister
pods
algorithm
.
PodLister
random
*
rand
.
Rand
random
*
rand
.
Rand
randomLock
sync
.
Mutex
randomLock
sync
.
Mutex
lastNodeIndex
uint64
}
}
// Schedule tries to schedule the given pod to one of node in the node list.
// Schedule tries to schedule the given pod to one of node in the node list.
...
@@ -109,24 +111,16 @@ func (g *genericScheduler) selectHost(priorityList schedulerapi.HostPriorityList
...
@@ -109,24 +111,16 @@ func (g *genericScheduler) selectHost(priorityList schedulerapi.HostPriorityList
return
""
,
fmt
.
Errorf
(
"empty priorityList"
)
return
""
,
fmt
.
Errorf
(
"empty priorityList"
)
}
}
sort
.
Sort
(
sort
.
Reverse
(
priorityList
))
maxScore
:=
priorityList
[
0
]
.
Score
maxScore
:=
priorityList
[
0
]
.
Score
// idx contains indices of elements with score == maxScore.
firstAfterMaxScore
:=
sort
.
Search
(
len
(
priorityList
),
func
(
i
int
)
bool
{
return
priorityList
[
i
]
.
Score
<
maxScore
})
idx
:=
[]
int
{}
for
i
,
entry
:=
range
priorityList
{
if
entry
.
Score
>
maxScore
{
maxScore
=
entry
.
Score
idx
=
[]
int
{
i
}
}
else
if
entry
.
Score
==
maxScore
{
idx
=
append
(
idx
,
i
)
}
}
g
.
randomLock
.
Lock
()
g
.
randomLock
.
Lock
()
ix
:=
g
.
random
.
Int
()
%
len
(
idx
)
ix
:=
int
(
g
.
lastNodeIndex
%
uint64
(
firstAfterMaxScore
))
g
.
lastNodeIndex
++
g
.
randomLock
.
Unlock
()
g
.
randomLock
.
Unlock
()
return
priorityList
[
i
dx
[
ix
]
]
.
Host
,
nil
return
priorityList
[
i
x
]
.
Host
,
nil
}
}
// Filters the nodes to find the ones that fit based on the given predicate functions
// Filters the nodes to find the ones that fit based on the given predicate functions
...
@@ -188,7 +182,14 @@ func findNodesThatFit(pod *api.Pod, nodeNameToInfo map[string]*schedulercache.No
...
@@ -188,7 +182,14 @@ func findNodesThatFit(pod *api.Pod, nodeNameToInfo map[string]*schedulercache.No
// Each priority function can also have its own weight
// Each priority function can also have its own weight
// The node scores returned by the priority function are multiplied by the weights to get weighted scores
// The node scores returned by the priority function are multiplied by the weights to get weighted scores
// All scores are finally combined (added) to get the total weighted scores of all nodes
// All scores are finally combined (added) to get the total weighted scores of all nodes
func
PrioritizeNodes
(
pod
*
api
.
Pod
,
nodeNameToInfo
map
[
string
]
*
schedulercache
.
NodeInfo
,
podLister
algorithm
.
PodLister
,
priorityConfigs
[]
algorithm
.
PriorityConfig
,
nodeLister
algorithm
.
NodeLister
,
extenders
[]
algorithm
.
SchedulerExtender
)
(
schedulerapi
.
HostPriorityList
,
error
)
{
func
PrioritizeNodes
(
pod
*
api
.
Pod
,
nodeNameToInfo
map
[
string
]
*
schedulercache
.
NodeInfo
,
podLister
algorithm
.
PodLister
,
priorityConfigs
[]
algorithm
.
PriorityConfig
,
nodeLister
algorithm
.
NodeLister
,
extenders
[]
algorithm
.
SchedulerExtender
,
)
(
schedulerapi
.
HostPriorityList
,
error
)
{
result
:=
schedulerapi
.
HostPriorityList
{}
result
:=
schedulerapi
.
HostPriorityList
{}
// If no priority configs are provided, then the EqualPriority function is applied
// If no priority configs are provided, then the EqualPriority function is applied
...
...
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