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
6c63dcff
Commit
6c63dcff
authored
Aug 18, 2018
by
Guoliang Wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Not split nodes when searching for nodes but doing it all at once
parent
8c1bfeb0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
20 deletions
+40
-20
generic_scheduler.go
pkg/scheduler/core/generic_scheduler.go
+21
-18
parallelizer.go
staging/src/k8s.io/client-go/util/workqueue/parallelizer.go
+19
-2
No files found.
pkg/scheduler/core/generic_scheduler.go
View file @
6c63dcff
...
@@ -17,6 +17,7 @@ limitations under the License.
...
@@ -17,6 +17,7 @@ limitations under the License.
package
core
package
core
import
(
import
(
"context"
"fmt"
"fmt"
"math"
"math"
"sort"
"sort"
...
@@ -373,16 +374,19 @@ func (g *genericScheduler) findNodesThatFit(pod *v1.Pod, nodes []*v1.Node) ([]*v
...
@@ -373,16 +374,19 @@ func (g *genericScheduler) findNodesThatFit(pod *v1.Pod, nodes []*v1.Node) ([]*v
// Create filtered list with enough space to avoid growing it
// Create filtered list with enough space to avoid growing it
// and allow assigning.
// and allow assigning.
filtered
=
make
([]
*
v1
.
Node
,
2
*
numNodesToFind
)
filtered
=
make
([]
*
v1
.
Node
,
numNodesToFind
)
errs
:=
errors
.
MessageCountMap
{}
errs
:=
errors
.
MessageCountMap
{}
var
predicateResultLock
sync
.
Mutex
var
(
var
filteredLen
int32
predicateResultLock
sync
.
Mutex
filteredLen
int32
equivClass
*
equivalence
.
Class
)
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
// We can use the same metadata producer for all nodes.
// We can use the same metadata producer for all nodes.
meta
:=
g
.
predicateMetaProducer
(
pod
,
g
.
cachedNodeInfoMap
)
meta
:=
g
.
predicateMetaProducer
(
pod
,
g
.
cachedNodeInfoMap
)
var
equivClass
*
equivalence
.
Class
if
g
.
equivalenceCache
!=
nil
{
if
g
.
equivalenceCache
!=
nil
{
// getEquivalenceClassInfo will return immediately if no equivalence pod found
// getEquivalenceClassInfo will return immediately if no equivalence pod found
equivClass
=
equivalence
.
NewClass
(
pod
)
equivClass
=
equivalence
.
NewClass
(
pod
)
...
@@ -412,25 +416,24 @@ func (g *genericScheduler) findNodesThatFit(pod *v1.Pod, nodes []*v1.Node) ([]*v
...
@@ -412,25 +416,24 @@ func (g *genericScheduler) findNodesThatFit(pod *v1.Pod, nodes []*v1.Node) ([]*v
return
return
}
}
if
fits
{
if
fits
{
filtered
[
atomic
.
AddInt32
(
&
filteredLen
,
1
)
-
1
]
=
g
.
cachedNodeInfoMap
[
nodeName
]
.
Node
()
length
:=
atomic
.
AddInt32
(
&
filteredLen
,
1
)
if
length
>
numNodesToFind
{
cancel
()
atomic
.
AddInt32
(
&
filteredLen
,
-
1
)
}
else
{
filtered
[
length
-
1
]
=
g
.
cachedNodeInfoMap
[
nodeName
]
.
Node
()
}
}
else
{
}
else
{
predicateResultLock
.
Lock
()
predicateResultLock
.
Lock
()
failedPredicateMap
[
nodeName
]
=
failedPredicates
failedPredicateMap
[
nodeName
]
=
failedPredicates
predicateResultLock
.
Unlock
()
predicateResultLock
.
Unlock
()
}
}
}
}
numNodesProcessed
:=
int32
(
0
)
for
numNodesProcessed
<
allNodes
{
// Stops searching for more nodes once the configured number of feasible nodes
numNodesToProcess
:=
allNodes
-
numNodesProcessed
// are found.
if
numNodesToProcess
>
numNodesToFind
{
workqueue
.
ParallelizeUntil
(
ctx
,
16
,
int
(
allNodes
),
checkNode
)
numNodesToProcess
=
numNodesToFind
}
workqueue
.
Parallelize
(
16
,
int
(
numNodesToProcess
),
checkNode
)
if
filteredLen
>=
numNodesToFind
{
break
}
numNodesProcessed
+=
numNodesToProcess
}
filtered
=
filtered
[
:
filteredLen
]
filtered
=
filtered
[
:
filteredLen
]
if
len
(
errs
)
>
0
{
if
len
(
errs
)
>
0
{
return
[]
*
v1
.
Node
{},
FailedPredicateMap
{},
errors
.
CreateAggregateFromMessageCountMap
(
errs
)
return
[]
*
v1
.
Node
{},
FailedPredicateMap
{},
errors
.
CreateAggregateFromMessageCountMap
(
errs
)
...
...
staging/src/k8s.io/client-go/util/workqueue/parallelizer.go
View file @
6c63dcff
...
@@ -17,6 +17,7 @@ limitations under the License.
...
@@ -17,6 +17,7 @@ limitations under the License.
package
workqueue
package
workqueue
import
(
import
(
"context"
"sync"
"sync"
utilruntime
"k8s.io/apimachinery/pkg/util/runtime"
utilruntime
"k8s.io/apimachinery/pkg/util/runtime"
...
@@ -24,9 +25,20 @@ import (
...
@@ -24,9 +25,20 @@ import (
type
DoWorkPieceFunc
func
(
piece
int
)
type
DoWorkPieceFunc
func
(
piece
int
)
// Parallelize is a very simple framework that allow for parallelizing
// Parallelize is a very simple framework that allow
s
for parallelizing
// N independent pieces of work.
// N independent pieces of work.
func
Parallelize
(
workers
,
pieces
int
,
doWorkPiece
DoWorkPieceFunc
)
{
func
Parallelize
(
workers
,
pieces
int
,
doWorkPiece
DoWorkPieceFunc
)
{
ParallelizeUntil
(
nil
,
workers
,
pieces
,
doWorkPiece
)
}
// ParallelizeUntil is a framework that allows for parallelizing N
// independent pieces of work until done or the context is canceled.
func
ParallelizeUntil
(
ctx
context
.
Context
,
workers
,
pieces
int
,
doWorkPiece
DoWorkPieceFunc
)
{
var
stop
<-
chan
struct
{}
if
ctx
!=
nil
{
stop
=
ctx
.
Done
()
}
toProcess
:=
make
(
chan
int
,
pieces
)
toProcess
:=
make
(
chan
int
,
pieces
)
for
i
:=
0
;
i
<
pieces
;
i
++
{
for
i
:=
0
;
i
<
pieces
;
i
++
{
toProcess
<-
i
toProcess
<-
i
...
@@ -44,7 +56,12 @@ func Parallelize(workers, pieces int, doWorkPiece DoWorkPieceFunc) {
...
@@ -44,7 +56,12 @@ func Parallelize(workers, pieces int, doWorkPiece DoWorkPieceFunc) {
defer
utilruntime
.
HandleCrash
()
defer
utilruntime
.
HandleCrash
()
defer
wg
.
Done
()
defer
wg
.
Done
()
for
piece
:=
range
toProcess
{
for
piece
:=
range
toProcess
{
doWorkPiece
(
piece
)
select
{
case
<-
stop
:
return
default
:
doWorkPiece
(
piece
)
}
}
}
}()
}()
}
}
...
...
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