mirror of
https://github.com/prometheus/prometheus.git
synced 2026-06-09 08:32:26 -04:00
histogramSamplesV2 and floatHistogramSamplesV2 tracked the previous
sample's Ref and ST via a *RefHistogramSample pointer (prev). Taking the
address of a loop-local variable (prev = &rh) forced the compiler to
heap-allocate rh on every iteration; the first iteration also allocated
a separate sentinel struct. The pointed-to fields were only ever read as
two int64 scalars, so the pointer added zero semantic value.
Replace prev with two scalar variables (prevRef, prevST) and a boolean
sentinel. rh no longer has its address taken and stays on the stack.
This affects every caller of dec.HistogramSamples that produces V2
records (EnableSTStorage=true): WAL replay, the WAL watcher (remote
write tail), and checkpoint creation.
Benchmarks (go test -count=6 -benchmem, benchstat):
BenchmarkDecodeHistogramSamples (tsdb/record)
│ before │ after │
│ allocs/op │ allocs/op vs base │
buckets=0/v2 │ 2.001k ± 0%│ 1.000k ± 0% -50.02% (p=0.002)│
buckets=4/v2 │ 4.001k ± 0%│ 3.000k ± 0% -25.02% (p=0.002)│
buckets=16/v2 │ 4.001k ± 0%│ 3.000k ± 0% -25.02% (p=0.002)│
│ before │ after │
│ B/op │ B/op vs base │
buckets=0/v2 │ 187.5Ki ± 0%│ 156.2Ki ± 0% -16.68% (p=0.002)│
buckets=4/v2 │ 250.0Ki ± 0%│ 218.8Ki ± 0% -12.51% (p=0.002)│
buckets=16/v2 │ 437.5Ki ± 0%│ 406.2Ki ± 0% -7.15% (p=0.002)│
BenchmarkLoadWLs end-to-end WAL replay (tsdb), stStorage=true only
│ before │ after │
│ allocs/op │ allocs/op vs base │
histogramSeriesPct=1.000 │ 19.70M ± 0% │ 14.90M ± 0% -24.39% (p=0.002)│
histogramSeriesPct=0.500 │ 10.47M ± 0% │ 8.06M ± 0% -23.00% (p=0.002)│
│ before │ after │
│ B/op │ B/op vs base │
histogramSeriesPct=1.000 │ 1.539Gi ± 0%│ 1.394Gi ± 0% -9.42% (p=0.002)│
histogramSeriesPct=0.500 │ 1051.3Mi ± 0%│ 975.1Mi ± 0% -7.25% (p=0.002)│
│ before │ after │
│ sec/op │ sec/op vs base │
histogramSeriesPct=1.000 │ 824.9m ± 0% │ 762.6m ± 1% -7.55% (p=0.002)│
histogramSeriesPct=0.500 │ 488.6m ± 1% │ 451.4m ± 1% -7.61% (p=0.002)│
V1 paths and float-only shapes are unchanged (p >> 0.05 throughout).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Miguel Bernabeu Diaz <miguel.bernabeu@coralogix.com>
|
||
|---|---|---|
| .. | ||
| agent | ||
| chunkenc | ||
| chunks | ||
| compression | ||
| docs | ||
| encoding | ||
| fileutil | ||
| goversion | ||
| index | ||
| record | ||
| testdata | ||
| tombstones | ||
| tsdbutil | ||
| wlog | ||
| .gitignore | ||
| block.go | ||
| block_test.go | ||
| blockwriter.go | ||
| blockwriter_test.go | ||
| CHANGELOG.md | ||
| compact.go | ||
| compact_test.go | ||
| db.go | ||
| db_append_v2_test.go | ||
| db_test.go | ||
| example_test.go | ||
| exemplar.go | ||
| exemplar_test.go | ||
| head.go | ||
| head_append.go | ||
| head_append_v2.go | ||
| head_append_v2_test.go | ||
| head_bench_test.go | ||
| head_dedupelabels.go | ||
| head_other.go | ||
| head_read.go | ||
| head_read_test.go | ||
| head_test.go | ||
| head_wal.go | ||
| isolation.go | ||
| isolation_test.go | ||
| label_values_bench_test.go | ||
| mocks_test.go | ||
| ooo_head.go | ||
| ooo_head_read.go | ||
| ooo_head_read_test.go | ||
| ooo_head_test.go | ||
| ooo_isolation.go | ||
| ooo_isolation_test.go | ||
| querier.go | ||
| querier_bench_test.go | ||
| querier_test.go | ||
| README.md | ||
| repair.go | ||
| repair_test.go | ||
| testutil.go | ||
| tsdbblockutil.go | ||
TSDB
This directory contains the Prometheus TSDB (Time Series DataBase) library, which handles storage and querying of all Prometheus v2 data.
Documentation
External resources
- A writeup of the original design can be found here.
- Video: Storing 16 Bytes at Scale from PromCon 2017.
- Compression is based on the Gorilla TSDB white paper.
A series of blog posts explaining different components of TSDB: