-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathingest_bench_test.go
More file actions
59 lines (50 loc) · 1.83 KB
/
Copy pathingest_bench_test.go
File metadata and controls
59 lines (50 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package storage
import (
"context"
"testing"
)
// Ingest-path profiling benchmark — the write-side analog of headquery_bench_test.go's read set.
//
// The live /src/oteldb/benchmark profile shows oteldb's at-rest CPU is 100% ingest (vmagent
// remote-writes 2560 node_exporter series every 15s), and the top live-heap holder is
// slices.Clone[uint8] — the per-series label/attribute byte clones taken on the head append path.
// This benchmark drives that exact path with the node_exporter-shaped headCorpus (2560 series,
// 4 labels each: job/instance on the resource, cpu/mode on the points) so the clone + projection +
// head-append costs show up cleanly under pprof, isolated from the docker harness:
//
// go test -run=^$ -bench=^BenchmarkHeadIngest$ -benchtime=3s \
// -cpuprofile=/tmp/cpu.out -memprofile=/tmp/mem.out .
// go tool pprof -top /tmp/cpu.out
// go tool pprof -top -sample_index=alloc_space /tmp/mem.out
//
// It periodically Resets the head so per-series buffers don't grow without bound; the first write
// after each reset registers the series (label clone), the rest re-append to known series — the
// steady-state live mix.
func BenchmarkHeadIngest(b *testing.B) {
ctx := context.Background()
md := headCorpus()
total := headSeries * headPoints
// ~1M buffered points between resets: amortizes one-time series registration over many appends
// while keeping the head's resident sample buffers modest.
resetEvery := max((1<<20)/total, 1)
s, err := InMemory()
if err != nil {
b.Fatal(err)
}
defer func() { _ = s.Close(ctx) }()
b.ReportAllocs()
b.ResetTimer()
for i := range b.N {
if _, err := s.WriteMetrics(ctx, md); err != nil {
b.Fatal(err)
}
if (i+1)%resetEvery == 0 {
b.StopTimer()
if err := s.Reset(ctx); err != nil {
b.Fatal(err)
}
b.StartTimer()
}
}
goldenReportPoints(b, total)
}