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
a2cc1b1a
Commit
a2cc1b1a
authored
Aug 24, 2018
by
Yecheng Fu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Use sync.map to scale ecache better"
This reverts commit
17d01907
.
parent
2c933695
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
14 deletions
+27
-14
eqivalence.go
pkg/scheduler/core/equivalence/eqivalence.go
+26
-13
eqivalence_test.go
pkg/scheduler/core/equivalence/eqivalence_test.go
+1
-1
No files found.
pkg/scheduler/core/equivalence/eqivalence.go
View file @
a2cc1b1a
...
@@ -35,6 +35,9 @@ import (
...
@@ -35,6 +35,9 @@ import (
"github.com/golang/glog"
"github.com/golang/glog"
)
)
// nodeMap stores a *Cache for each node.
type
nodeMap
map
[
string
]
*
NodeCache
// Cache is a thread safe map saves and reuses the output of predicate functions,
// Cache is a thread safe map saves and reuses the output of predicate functions,
// it uses node name as key to access those cached results.
// it uses node name as key to access those cached results.
//
//
...
@@ -42,13 +45,17 @@ import (
...
@@ -42,13 +45,17 @@ import (
// class". (Equivalence class is defined in the `Class` type.) Saved results
// class". (Equivalence class is defined in the `Class` type.) Saved results
// will be reused until an appropriate invalidation function is called.
// will be reused until an appropriate invalidation function is called.
type
Cache
struct
{
type
Cache
struct
{
// i.e. map[string]*NodeCache
// NOTE(harry): Theoretically sync.Map has better performance in machine with 8+ CPUs, while
sync
.
Map
// the reality is lock contention in first level cache is rare.
mu
sync
.
RWMutex
nodeToCache
nodeMap
}
}
// NewCache create an empty equiv class cache.
// NewCache create an empty equiv class cache.
func
NewCache
()
*
Cache
{
func
NewCache
()
*
Cache
{
return
new
(
Cache
)
return
&
Cache
{
nodeToCache
:
make
(
nodeMap
),
}
}
}
// NodeCache saves and reuses the output of predicate functions. Use RunPredicate to
// NodeCache saves and reuses the output of predicate functions. Use RunPredicate to
...
@@ -76,8 +83,12 @@ func newNodeCache() *NodeCache {
...
@@ -76,8 +83,12 @@ func newNodeCache() *NodeCache {
// it creates the NodeCache and returns it.
// it creates the NodeCache and returns it.
// The boolean flag is true if the value was loaded, false if created.
// The boolean flag is true if the value was loaded, false if created.
func
(
c
*
Cache
)
GetNodeCache
(
name
string
)
(
nodeCache
*
NodeCache
,
exists
bool
)
{
func
(
c
*
Cache
)
GetNodeCache
(
name
string
)
(
nodeCache
*
NodeCache
,
exists
bool
)
{
v
,
exists
:=
c
.
LoadOrStore
(
name
,
newNodeCache
())
c
.
mu
.
Lock
()
nodeCache
=
v
.
(
*
NodeCache
)
defer
c
.
mu
.
Unlock
()
if
nodeCache
,
exists
=
c
.
nodeToCache
[
name
];
!
exists
{
nodeCache
=
newNodeCache
()
c
.
nodeToCache
[
name
]
=
nodeCache
}
return
return
}
}
...
@@ -86,13 +97,12 @@ func (c *Cache) InvalidatePredicates(predicateKeys sets.String) {
...
@@ -86,13 +97,12 @@ func (c *Cache) InvalidatePredicates(predicateKeys sets.String) {
if
len
(
predicateKeys
)
==
0
{
if
len
(
predicateKeys
)
==
0
{
return
return
}
}
c
.
Range
(
func
(
k
,
v
interface
{})
bool
{
c
.
mu
.
RLock
()
n
:=
v
.
(
*
NodeCache
)
defer
c
.
mu
.
RUnlock
()
for
_
,
n
:=
range
c
.
nodeToCache
{
n
.
invalidatePreds
(
predicateKeys
)
n
.
invalidatePreds
(
predicateKeys
)
return
true
}
})
glog
.
V
(
5
)
.
Infof
(
"Cache invalidation: node=*,predicates=%v"
,
predicateKeys
)
glog
.
V
(
5
)
.
Infof
(
"Cache invalidation: node=*,predicates=%v"
,
predicateKeys
)
}
}
// InvalidatePredicatesOnNode clears cached results for the given predicates on one node.
// InvalidatePredicatesOnNode clears cached results for the given predicates on one node.
...
@@ -100,8 +110,9 @@ func (c *Cache) InvalidatePredicatesOnNode(nodeName string, predicateKeys sets.S
...
@@ -100,8 +110,9 @@ func (c *Cache) InvalidatePredicatesOnNode(nodeName string, predicateKeys sets.S
if
len
(
predicateKeys
)
==
0
{
if
len
(
predicateKeys
)
==
0
{
return
return
}
}
if
v
,
ok
:=
c
.
Load
(
nodeName
);
ok
{
c
.
mu
.
RLock
()
n
:=
v
.
(
*
NodeCache
)
defer
c
.
mu
.
RUnlock
()
if
n
,
ok
:=
c
.
nodeToCache
[
nodeName
];
ok
{
n
.
invalidatePreds
(
predicateKeys
)
n
.
invalidatePreds
(
predicateKeys
)
}
}
glog
.
V
(
5
)
.
Infof
(
"Cache invalidation: node=%s,predicates=%v"
,
nodeName
,
predicateKeys
)
glog
.
V
(
5
)
.
Infof
(
"Cache invalidation: node=%s,predicates=%v"
,
nodeName
,
predicateKeys
)
...
@@ -109,7 +120,9 @@ func (c *Cache) InvalidatePredicatesOnNode(nodeName string, predicateKeys sets.S
...
@@ -109,7 +120,9 @@ func (c *Cache) InvalidatePredicatesOnNode(nodeName string, predicateKeys sets.S
// InvalidateAllPredicatesOnNode clears all cached results for one node.
// InvalidateAllPredicatesOnNode clears all cached results for one node.
func
(
c
*
Cache
)
InvalidateAllPredicatesOnNode
(
nodeName
string
)
{
func
(
c
*
Cache
)
InvalidateAllPredicatesOnNode
(
nodeName
string
)
{
c
.
Delete
(
nodeName
)
c
.
mu
.
Lock
()
defer
c
.
mu
.
Unlock
()
delete
(
c
.
nodeToCache
,
nodeName
)
glog
.
V
(
5
)
.
Infof
(
"Cache invalidation: node=%s,predicates=*"
,
nodeName
)
glog
.
V
(
5
)
.
Infof
(
"Cache invalidation: node=%s,predicates=*"
,
nodeName
)
}
}
...
...
pkg/scheduler/core/equivalence/eqivalence_test.go
View file @
a2cc1b1a
...
@@ -731,7 +731,7 @@ func TestInvalidateCachedPredicateItemOfAllNodes(t *testing.T) {
...
@@ -731,7 +731,7 @@ func TestInvalidateCachedPredicateItemOfAllNodes(t *testing.T) {
// there should be no cached predicate any more
// there should be no cached predicate any more
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
if
nodeCache
,
exist
:=
ecache
.
GetNodeCache
(
test
.
nodeName
)
;
exist
{
if
nodeCache
,
exist
:=
ecache
.
nodeToCache
[
test
.
nodeName
]
;
exist
{
if
_
,
exist
:=
nodeCache
.
cache
[
testPredicate
];
exist
{
if
_
,
exist
:=
nodeCache
.
cache
[
testPredicate
];
exist
{
t
.
Errorf
(
"Failed: cached item for predicate key: %v on node: %v should be invalidated"
,
t
.
Errorf
(
"Failed: cached item for predicate key: %v on node: %v should be invalidated"
,
testPredicate
,
test
.
nodeName
)
testPredicate
,
test
.
nodeName
)
...
...
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