Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
Signed-off-by: Mauro Stettler <mauro.stettler@gmail.com>
  • Loading branch information
replay committed Feb 9, 2022
1 parent 20f3746 commit 8b4bfa2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tsdb/chunks/chunk_write_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ import (
)

const (
chunkRefMapFreeThreshold = 10
// Minimum recorded peak since since the last freeing
// of chunkWriteQueue.chunkrefMap to free it again.
chunkRefMapFreeThreshold = 10

// Minimum interval between freeing of chunkWriteQueue.chunkRefMap.
chunkRefMapMinFreeInterval = 10 * time.Minute
)

Expand Down Expand Up @@ -122,13 +126,14 @@ func (c *chunkWriteQueue) processJob(job chunkWriteJob) {

c.completed.Inc()

if len(c.chunkRefMap) == 0 && c.chunkRefMapPeak > chunkRefMapFreeThreshold && time.Since(c.chunkRefMapLastFree) > chunkRefMapMinFreeInterval {
now := time.Now()
if len(c.chunkRefMap) == 0 && c.chunkRefMapPeak > chunkRefMapFreeThreshold && now.Sub(c.chunkRefMapLastFree) > chunkRefMapMinFreeInterval {
// Re-initialize the chunk ref map to half of the peak size that was in use since the last re-init event.
// By setting it to half of the peak we try to minimize the number of allocations required for a "normal" usage
// while ensuring that if its usage has decreased we shrink it over time.
c.chunkRefMap = make(map[ChunkDiskMapperRef]chunkenc.Chunk, c.chunkRefMapPeak/2)
c.chunkRefMapPeak = 0
c.chunkRefMapLastFree = time.Now()
c.chunkRefMapLastFree = now
}
}

Expand Down

0 comments on commit 8b4bfa2

Please sign in to comment.