From 1e4eba65a09f7d8ac1d04c646f402166162ccf12 Mon Sep 17 00:00:00 2001 From: bwplotka Date: Thu, 5 Feb 2026 13:47:31 +0000 Subject: [PATCH] exp: BenchmarkScrapeLoopAppend_RefSampleST Signed-off-by: bwplotka --- scrape/scrape_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/scrape/scrape_test.go b/scrape/scrape_test.go index cab2b2918a..ecbbd2d3ca 100644 --- a/scrape/scrape_test.go +++ b/scrape/scrape_test.go @@ -44,6 +44,7 @@ import ( "github.com/prometheus/common/expfmt" "github.com/prometheus/common/model" "github.com/prometheus/common/promslog" + "github.com/prometheus/procfs" "github.com/stretchr/testify/require" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/propagation" @@ -1852,6 +1853,46 @@ func BenchmarkScrapeLoopAppend_HistogramsWithExemplars(b *testing.B) { } } +/* + export bench=appendRefSample && go test ./scrape/... \ + -run '^$' -bench '^BenchmarkScrapeLoopAppend_RefSampleST$' \ + -benchtime 2s -count 6 -cpu 2 -timeout 999m \ + | tee ${bench}.txt +*/ +func BenchmarkScrapeLoopAppend_RefSampleST(b *testing.B) { + parsableText := readTextParseTestMetrics(b) // "237FamsAllTypes" + metricsProto := promTextToProto(b, parsableText) + contentType := "application/vnd.google.protobuf" + + s := teststorage.New(b, func(opt *tsdb.Options) { opt.EnableMetadataWALRecords = false }) + sl, _ := newTestScrapeLoop(b, withAppendable(s, true), func(sl *scrapeLoop) { sl.appendMetadataToWAL = false }) + + p, err := procfs.Self() // Works only on linux. + require.NoError(b, err) + + stat, err := p.Stat() + require.NoError(b, err) + + ts := time.Time{} + b.ReportAllocs() + b.ResetTimer() + for b.Loop() { + app := sl.appender() + ts = ts.Add(time.Second) + _, _, _, err := app.append(metricsProto, contentType, ts) + if err != nil { + b.Fatal(err) + } + if err := app.Commit(); err != nil { + b.Fatal(err) + } + } + + stat2, err := p.Stat() + require.NoError(b, err) + b.ReportMetric(stat2.CPUTime()-stat.CPUTime(), "procfscpu") +} + func TestScrapeLoopScrapeAndReport(t *testing.T) { foreachAppendable(t, func(t *testing.T, appV2 bool) { testScrapeLoopScrapeAndReport(t, appV2)