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
2298e174
Commit
2298e174
authored
Oct 13, 2016
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Increase buffer sizes in cacher for watchers interested in all/many objects.
parent
aa485ce8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
6 deletions
+21
-6
cacher.go
pkg/storage/cacher.go
+21
-6
No files found.
pkg/storage/cacher.go
View file @
2298e174
...
@@ -310,10 +310,25 @@ func (c *Cacher) Watch(ctx context.Context, key string, resourceVersion string,
...
@@ -310,10 +310,25 @@ func (c *Cacher) Watch(ctx context.Context, key string, resourceVersion string,
triggerValue
,
triggerSupported
=
matchValues
[
0
]
.
Value
,
true
triggerValue
,
triggerSupported
=
matchValues
[
0
]
.
Value
,
true
}
}
// If there is triggerFunc defined, but triggerSupported is false,
// we can't narrow the amount of events significantly at this point.
//
// That said, currently triggerFunc is defined only for Pods and Nodes,
// and there is only constant number of watchers for which triggerSupported
// is false (excluding those issues explicitly by users).
// Thus, to reduce the risk of those watchers blocking all watchers of a
// given resource in the system, we increase the sizes of buffers for them.
chanSize
:=
10
if
c
.
triggerFunc
!=
nil
&&
!
triggerSupported
{
// TODO: We should tune this value and ideally make it dependent on the
// number of objects of a given type and/or their churn.
chanSize
=
1000
}
c
.
Lock
()
c
.
Lock
()
defer
c
.
Unlock
()
defer
c
.
Unlock
()
forget
:=
forgetWatcher
(
c
,
c
.
watcherIdx
,
triggerValue
,
triggerSupported
)
forget
:=
forgetWatcher
(
c
,
c
.
watcherIdx
,
triggerValue
,
triggerSupported
)
watcher
:=
newCacheWatcher
(
watchRV
,
initEvents
,
filterFunction
(
key
,
c
.
keyFunc
,
pred
),
forget
)
watcher
:=
newCacheWatcher
(
watchRV
,
chanSize
,
initEvents
,
filterFunction
(
key
,
c
.
keyFunc
,
pred
),
forget
)
c
.
watchers
.
addWatcher
(
watcher
,
c
.
watcherIdx
,
triggerValue
,
triggerSupported
)
c
.
watchers
.
addWatcher
(
watcher
,
c
.
watcherIdx
,
triggerValue
,
triggerSupported
)
c
.
watcherIdx
++
c
.
watcherIdx
++
...
@@ -610,10 +625,10 @@ type cacheWatcher struct {
...
@@ -610,10 +625,10 @@ type cacheWatcher struct {
forget
func
(
bool
)
forget
func
(
bool
)
}
}
func
newCacheWatcher
(
resourceVersion
uint64
,
initEvents
[]
watchCacheEvent
,
filter
FilterFunc
,
forget
func
(
bool
))
*
cacheWatcher
{
func
newCacheWatcher
(
resourceVersion
uint64
,
chanSize
int
,
initEvents
[]
watchCacheEvent
,
filter
FilterFunc
,
forget
func
(
bool
))
*
cacheWatcher
{
watcher
:=
&
cacheWatcher
{
watcher
:=
&
cacheWatcher
{
input
:
make
(
chan
watchCacheEvent
,
10
),
input
:
make
(
chan
watchCacheEvent
,
chanSize
),
result
:
make
(
chan
watch
.
Event
,
10
),
result
:
make
(
chan
watch
.
Event
,
chanSize
),
filter
:
filter
,
filter
:
filter
,
stopped
:
false
,
stopped
:
false
,
forget
:
forget
,
forget
:
forget
,
...
@@ -728,7 +743,7 @@ func (c *cacheWatcher) process(initEvents []watchCacheEvent, resourceVersion uin
...
@@ -728,7 +743,7 @@ func (c *cacheWatcher) process(initEvents []watchCacheEvent, resourceVersion uin
// We should understand what is blocking us in those cases (e.g.
// We should understand what is blocking us in those cases (e.g.
// is it lack of CPU, network, or sth else) and potentially
// is it lack of CPU, network, or sth else) and potentially
// consider increase size of result buffer in those cases.
// consider increase size of result buffer in those cases.
const
initProcessThreshold
=
5
0
*
time
.
Millisecond
const
initProcessThreshold
=
10
0
*
time
.
Millisecond
startTime
:=
time
.
Now
()
startTime
:=
time
.
Now
()
for
_
,
event
:=
range
initEvents
{
for
_
,
event
:=
range
initEvents
{
c
.
sendWatchCacheEvent
(
event
)
c
.
sendWatchCacheEvent
(
event
)
...
@@ -739,7 +754,7 @@ func (c *cacheWatcher) process(initEvents []watchCacheEvent, resourceVersion uin
...
@@ -739,7 +754,7 @@ func (c *cacheWatcher) process(initEvents []watchCacheEvent, resourceVersion uin
if
len
(
initEvents
)
>
0
{
if
len
(
initEvents
)
>
0
{
objType
=
reflect
.
TypeOf
(
initEvents
[
0
]
.
Object
)
.
String
()
objType
=
reflect
.
TypeOf
(
initEvents
[
0
]
.
Object
)
.
String
()
}
}
glog
.
V
(
2
)
.
Infof
(
"processing %d initEvents of %stook %v"
,
len
(
initEvents
),
objType
,
processingTime
)
glog
.
V
(
2
)
.
Infof
(
"processing %d initEvents of %s
took %v"
,
len
(
initEvents
),
objType
,
processingTime
)
}
}
defer
close
(
c
.
result
)
defer
close
(
c
.
result
)
...
...
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