Skip to content

scrape: benchmark OM 1.0 vs OM 2.0 scraping of a real Prometheus /metrics page - #19906

Closed
bwplotka wants to merge 2 commits into
mainfrom
bwplotka/om-scrape-bench
Closed

bwplotka wants to merge 2 commits into
mainfrom
bwplotka/om-scrape-bench

Conversation

@bwplotka

@bwplotka bwplotka commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

Adds an OpenMetrics 2.0 case to BenchmarkScrapeLoopAppend so we can compare OM 1.0 and OM 2.0 scraping end to end (parse + append) on a realistic page rather than only the synthetic 2000-gauge one.

Commits, in reading order:

  1. build: bump prometheus/common to v0.72.0: needed for expfmt.MetricFamilyToOpenMetrics20 summary support, used to generate the OM 2.0 payloads.
  2. scrape: benchmark OM 1.0 vs OM 2.0 scraping of a real Prometheus /metrics page: the benchmark itself.

What changed in the benchmark:

  • New fmt=OMText2 case and a parseST=<bool> dimension (EnableStartTimestampParsing).
  • The appV2 dimension is gone; the benchmark always uses AppenderV2. AppenderV2 is the Prometheus default (
    // This only applies to AppenderV2 flow (Prometheus default).
    ), AppenderV1 is only kept until the OTel collector moves over and is scheduled for removal (
    // NOTE: This option has no effect for AppenderV2 and will be removed with the AppenderV1
    ), and parseST only exists on the V2 path, so keeping appV2=false doubled the matrix (already 6 dimensions) for a code path Prometheus itself does not run and that cannot exercise the ST difference this benchmark is about.
  • Datasets are declared once in benchDatasets with the payload per format, and TestBenchDatasets asserts every format of a dataset appends the same number of samples, so the formats are compared on equal work.
  • Two datasets from a real server: model/textparse/testdata/prometheus.om1.txt is the /metrics page of prometheus.demo.prometheus.io (265 families: 123 counters, 105 gauges, 24 histograms, 13 summaries) in OM 1.0 with a _created line for every counter, summary and histogram, as client_golang exposes them. prometheus.om2.txt is the same page in OM 2.0 with start timestamps inline (st@). Both were generated with expfmt from the same parsed families, with the created timestamp set to the page's process_start_time_seconds. 265FamsPrometheusNHCB is the same page with convertClassicHistogramsToNHCB. The synthetic 237FamsAllTypes page is dropped from this benchmark: it has 6 _created lines for 142 eligible families, so with parseST=true OM 1.0 spends almost all of its time re-lexing for _created lines that are not there (150 ms vs 4 ms on the real page), which hides every other difference.

The benchmark name is now withStorage=%v/appendMetadataToWAL=%v/data=%v/fmt=%v/coldCache=%v/parseST=%v. Beware that -bench matches each / segment unanchored, so fmt=OMText also selects fmt=OMText2; the recommended invocation in the comment anchors with fmt=OMText$.

Numbers on current main plus 55bb7924c1 (the small pooling fix I am sending separately; it does not change the picture below). withStorage=false, appendMetadataToWAL=false, -benchtime 2s -count 6 -cpu 2, OM 1.0 and OM 2.0 run as separate processes, benchstat -col /fmt:

                                                     │   OMText    │             OMText2              │
                                                     │   sec/op    │   sec/op     vs base             │
1Fam2000Gauges/coldCache=false/parseST=false-2         1.044m ± 1%   1.253m ± 2%  +20.01% (p=0.002 n=6)
1Fam2000Gauges/coldCache=true/parseST=false-2          3.189m ± 7%   3.530m ± 2%  +10.69% (p=0.002 n=6)
265FamsPrometheus/coldCache=false/parseST=true-2       4.168m ± 1%   2.710m ± 2%  -34.99% (p=0.002 n=6)
265FamsPrometheus/coldCache=false/parseST=false-2      2.459m ± 1%   2.686m ± 1%   +9.24% (p=0.002 n=6)
265FamsPrometheus/coldCache=true/parseST=true-2        7.296m ± 2%   4.598m ± 1%  -36.98% (p=0.002 n=6)
265FamsPrometheusNHCB/coldCache=false/parseST=true-2   5.514m ± 1%   1.623m ± 2%  -70.58% (p=0.002 n=6)
265FamsPrometheusNHCB/coldCache=false/parseST=false-2  4.417m ± 1%   1.619m ± 1%  -63.34% (p=0.002 n=6)

                                                     │   OMText    │              OMText2               │
                                                     │    B/op     │    B/op       vs base              │
265FamsPrometheus/coldCache=false/parseST=true-2       212.7Ki ± 0%  178.0Ki ± 0%    -16.30% (p=0.002 n=6)
265FamsPrometheus/coldCache=false/parseST=false-2      3.248Ki ± 1%  178.0Ki ± 0%  +5380.97% (p=0.002 n=6)
265FamsPrometheusNHCB/coldCache=false/parseST=true-2   543.0Ki ± 0%  57.23Ki ± 0%    -89.46% (p=0.002 n=6)
265FamsPrometheusNHCB/coldCache=false/parseST=false-2  527.9Ki ± 0%  57.22Ki ± 0%    -89.16% (p=0.002 n=6)

What this already surfaces, which is the point of having it in tree:

  • With start timestamps parsed, OM 2.0 is ~35% faster on the real page and ~70% faster when converting to NHCB, because OM 1.0 has to re-lex each family to find _created lines.
  • With parseST=false, OM 2.0 is still ~9% slower and allocates 178 KiB vs 3 KiB per warm scrape, because the OM 2.0 parser on main builds labels eagerly for every exploded histogram/summary series. textparse [PERF]: defer OM2 composite and exemplar label allocations #19895 addresses that.
  • The gauge-only synthetic page is 10-20% slower in OM 2.0; that is per-line overhead a page with no composites cannot amortise, worth a separate look.
NONE

Needed for expfmt.MetricFamilyToOpenMetrics20 summary support, used by the
scrape benchmarks to generate OpenMetrics 2.0 payloads from the Prometheus
text test data.

Signed-off-by: Bartek Plotka <[email protected]>
…rics page

BenchmarkScrapeLoopAppend gains an OMText2 format, a parseST dimension and
two datasets built from a real Prometheus server page, and drops the
AppenderV1 case. Datasets are now declared once (benchDatasets) with the
payload per format, and TestBenchDatasets checks that every format of a
dataset appends the same number of samples, so the benchmark compares
equal work.

prometheus.om1.txt is the /metrics page of prometheus.demo.prometheus.io
(265 families: 123 counters, 105 gauges, 24 histograms, 13 summaries) in
OpenMetrics 1.0 with a _created line for every counter, summary and
histogram, as client_golang exposes them. prometheus.om2.txt is the same
page in OpenMetrics 2.0 with the start timestamps inline (st@). Both were
generated with expfmt from the same parsed families, with the created
timestamp set to the page's process_start_time_seconds. The synthetic
237FamsAllTypes page (6 _created lines for 142 eligible families) is
replaced by it in this benchmark: with parseST=true OM 1.0 spends almost
all of its time re-lexing for _created lines that are not there (150 ms
vs 4 ms on the real page), which hides every other difference between
the parsers.

The OM 2.0 payload of the gauge dataset is generated with
expfmt.MetricFamilyToOpenMetrics20, hence the prometheus/common bump.

Signed-off-by: Bartek Plotka <[email protected]>
@bwplotka
bwplotka force-pushed the bwplotka/om-scrape-bench branch from 1e6c827 to a5ee37c Compare October 4, 2026 11:26
Comment thread scrape/scrape_test.go
sl.alwaysScrapeClassicHist = false
sl.enableOpenMetrics2 = true
// Only AppenderV2 uses parseST; false skips p.StartTimestamp() entirely.
sl.parseST = parseST

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its true that false skips the start timestamp, but in that case it still ingests the _created series as regular series. So with parseST=false it isn't quite comparing apples to apples.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree.

OM1 specifies optional _created lines, so we should benchmark the full spec, even if e.g. Go does not produce those lines by default (against the spec). Default path is scraper is to collect all without ST parsing, so that would be the full effect.

Not all data inputs have _created lines so we can ensure we have no _created line comparision too.

@bwplotka

Copy link
Copy Markdown
Member Author

This has been merged in #19907

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants