-
Notifications
You must be signed in to change notification settings - Fork 107
[WIP] Add method to cache many chunks at once #940
Changes from all commits
3b6ab0c
a7c3453
d852ca4
851f6ba
b245187
d321e7a
75065dc
387c401
7665c13
b0be867
63c4e5d
a675396
8542fd5
0a2643e
0f12f95
54d363f
25eea51
3727dfe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,7 +104,7 @@ func (c *CCache) DelMetric(rawMetric schema.MKey) (int, int) { | |
} | ||
|
||
// adds the given chunk to the cache, but only if the metric is sufficiently hot | ||
func (c *CCache) CacheIfHot(metric schema.AMKey, prev uint32, itergen chunk.IterGen) { | ||
func (c *CCache) AddIfHot(metric schema.AMKey, prev uint32, itergen chunk.IterGen) { | ||
c.RLock() | ||
|
||
var met *CCacheMetric | ||
|
@@ -136,8 +136,8 @@ func (c *CCache) Add(metric schema.AMKey, prev uint32, itergen chunk.IterGen) { | |
|
||
ccm, ok := c.metricCache[metric] | ||
if !ok { | ||
ccm = NewCCacheMetric() | ||
ccm.Init(metric.MKey, prev, itergen) | ||
ccm = NewCCacheMetric(metric.MKey) | ||
ccm.Add(prev, itergen) | ||
c.metricCache[metric] = ccm | ||
|
||
// if we do not have this raw key yet, create the entry with the association | ||
|
@@ -157,6 +157,38 @@ func (c *CCache) Add(metric schema.AMKey, prev uint32, itergen chunk.IterGen) { | |
c.accnt.AddChunk(metric, itergen.Ts, itergen.Size()) | ||
} | ||
|
||
func (c *CCache) AddRange(metric schema.AMKey, prev uint32, itergens []chunk.IterGen) { | ||
if len(itergens) == 0 { | ||
return | ||
} | ||
c.Lock() | ||
defer c.Unlock() | ||
|
||
ccm, ok := c.metricCache[metric] | ||
if !ok { | ||
ccm = NewCCacheMetric(metric.MKey) | ||
ccm.AddRange(prev, itergens) | ||
c.metricCache[metric] = ccm | ||
|
||
// if we do not have this raw key yet, create the entry with the association | ||
ccms, ok := c.metricRawKeys[metric.MKey] | ||
if !ok { | ||
c.metricRawKeys[metric.MKey] = map[schema.Archive]struct{}{ | ||
metric.Archive: {}, | ||
} | ||
} else { | ||
// otherwise, make sure the association exists | ||
ccms[metric.Archive] = struct{}{} | ||
} | ||
} else { | ||
ccm.AddRange(prev, itergens) | ||
} | ||
|
||
for _, itergen := range itergens { | ||
c.accnt.AddChunk(metric, itergen.Ts, itergen.Size()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Dieterbe when you looked at the cpu profiles, did this method ever show up? If so, we could batch-add those as well. The benefit is probably going to be smaller because this function just directly pushes the data into a channel. We could also push a whole batch into the channel instead of one-by-one and then optimize the accounting to handle batches, but i'm not sure if there is any benefit to that because in the request-handling thread this will only result in less function calls and less pushes into that channel There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i was wondering the same thing. it would definitely help with |
||
} | ||
} | ||
|
||
func (cc *CCache) Reset() (int, int) { | ||
cc.Lock() | ||
cc.accnt.Reset() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a nice idea, to still add those that were not corrupted