feat: Adds statistics to debug/vars for tag value cache size#27259
feat: Adds statistics to debug/vars for tag value cache size#27259devanbenz wants to merge 9 commits intomaster-1.xfrom
Conversation
| // take an initial sample | ||
| atomic.StoreInt64(&i.cacheBytes, int64(i.tagValueCache.HeapSize())) | ||
|
|
||
| const cacheTrigger = 10 * time.Second |
There was a problem hiding this comment.
10 second updates should be fine 🤔
There was a problem hiding this comment.
Why collect on a schedule other than Monitor? Run the code when there is a call to Shard.Statistics like we do for SeriesN. This lets the Monitor service control frequency of collection, and reduces complexity on start and stop.
|
There is a race condition for |
There was a problem hiding this comment.
Pull request overview
Adds visibility into TSI tag value cache memory usage by sampling cache heap size and exporting it via debug/vars database statistics.
Changes:
- Add
tagValueCacheBytesstatistic to per-database store statistics. - Implement tag value cache heap-size estimation and periodic sampling in the TSI index.
- Add tests validating
TagValueSeriesIDCache.HeapSize()behavior (growth/eviction/nil set).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
tsdb/store.go |
Adds tagValueCacheBytes into database statistics by aggregating index-reported cache bytes. |
tsdb/shard.go |
Modifies shard close behavior when nil-ing the index reference. |
tsdb/index/tsi1/index.go |
Adds sampled cache-bytes metric, a closing signal, and a background sampler goroutine. |
tsdb/index/tsi1/cache.go |
Implements HeapSize() estimation for the tag value series ID cache. |
tsdb/index/tsi1/cache_test.go |
Adds tests for HeapSize() growth/eviction/nil handling. |
tsdb/index/inmem/inmem.go |
Implements TagValueCacheBytes() for in-memory index as always zero. |
tsdb/index.go |
Extends the Index interface with TagValueCacheBytes(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…influxdb into db/tag-v-cache-metrics
davidby-influx
left a comment
There was a problem hiding this comment.
It may be possible to simplify this.
| for name, mmap := range c.cache { | ||
| size += len(name) + int(unsafe.Sizeof(mmap)) | ||
| for key, tkmap := range mmap { | ||
| size += len(key) + int(unsafe.Sizeof(tkmap)) |
There was a problem hiding this comment.
For strings like key, is len(key) the size used, or is it unsafe.Sizeof(key) + len(key)
| // take an initial sample | ||
| atomic.StoreInt64(&i.cacheBytes, int64(i.tagValueCache.HeapSize())) | ||
|
|
||
| const cacheTrigger = 10 * time.Second |
There was a problem hiding this comment.
Why collect on a schedule other than Monitor? Run the code when there is a call to Shard.Statistics like we do for SeriesN. This lets the Monitor service control frequency of collection, and reduces complexity on start and stop.
This commit adds metrics to track how many bytes the tag value cache is using
Example output for 3 databases: