Skip to content

Commit

Permalink
Remove validity from FIFO cache
Browse files Browse the repository at this point in the history
We can remove the validity setting of 1h in 2.4 for the
chunks cache because it doesn't reduce memory usage and instead leads to
valid chunks being ignore when querying the cache. Chunks are immutable
so it doesn't make sense to not return them if they are present in the
cache.

Closes #4922

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
  • Loading branch information
chaudum committed Jan 17, 2022
1 parent 985e965 commit 62e2ffd
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 18 deletions.
1 change: 1 addition & 0 deletions pkg/canary/reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func NewReader(writer io.Writer,
fmt.Fprintf(rd.w, "shutting down reader\n")
rd.shuttingDown = true
_ = rd.conn.Close()
rd.conn = nil
}
}()

Expand Down
19 changes: 1 addition & 18 deletions pkg/storage/chunk/cache/fifo_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ type FifoCache struct {
maxSizeItems int
maxSizeBytes uint64
currSizeBytes uint64
validity time.Duration

entries map[string]*list.Element
lru *list.List
Expand All @@ -80,7 +79,6 @@ type FifoCache struct {
entriesCurrent prometheus.Gauge
totalGets prometheus.Counter
totalMisses prometheus.Counter
staleGets prometheus.Counter
memoryBytes prometheus.Gauge
}

Expand Down Expand Up @@ -109,7 +107,6 @@ func NewFifoCache(name string, cfg FifoCacheConfig, reg prometheus.Registerer, l
return &FifoCache{
maxSizeItems: cfg.MaxSizeItems,
maxSizeBytes: maxSizeBytes,
validity: cfg.Validity,
entries: make(map[string]*list.Element),
lru: list.New(),

Expand Down Expand Up @@ -161,14 +158,6 @@ func NewFifoCache(name string, cfg FifoCacheConfig, reg prometheus.Registerer, l
ConstLabels: prometheus.Labels{"cache": name},
}),

staleGets: promauto.With(reg).NewCounter(prometheus.CounterOpts{
Namespace: "querier",
Subsystem: "cache",
Name: "stale_gets_total",
Help: "The total number of Get calls that had an entry which expired",
ConstLabels: prometheus.Labels{"cache": name},
}),

memoryBytes: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
Namespace: "querier",
Subsystem: "cache",
Expand Down Expand Up @@ -284,13 +273,7 @@ func (c *FifoCache) Get(ctx context.Context, key string) ([]byte, bool) {
element, ok := c.entries[key]
if ok {
entry := element.Value.(*cacheEntry)
if c.validity == 0 || time.Since(entry.updated) < c.validity {
return entry.value, true
}

c.totalMisses.Inc()
c.staleGets.Inc()
return nil, false
return entry.value, true
}

c.totalMisses.Inc()
Expand Down

0 comments on commit 62e2ffd

Please sign in to comment.