Repository navigation
scrape: avoid a full-body copy of every scrape response - #19394
Conversation
02ed63f to
51efeaf
Compare
51efeaf to
2c9a850
Compare
|
Hi, thanks for your interest in the Prometheus project. When you post benchmark results, post the whole comparison including timings, not a subset. Beyond that, this PR is way longer than necessary for the actual changes. "I ain't reading all that". |
fc8503d to
43dff26
Compare
|
Thanks, and sorry for the noise. Cut the description, commit messages and comments right back, and the full benchstat for both packages is now in the description. |
Above the pool's largest bucket pool.Get returns a slice with cap == len, so bytes.Buffer.ReadFrom's final grow copies the whole body. One spare byte does not help: ReadFrom grows by bytes.MinRead before every Read. Co-authored-by: Copilot <[email protected]> Signed-off-by: Shubh Gupta <[email protected]>
The exposition format requires a trailing newline, so the append is normally redundant, but it copies the whole body when the caller's slice has no spare capacity. Co-authored-by: Copilot <[email protected]> Signed-off-by: Shubh Gupta <[email protected]>
43dff26 to
b25fc0f
Compare
Co-authored-by: Copilot <[email protected]> Signed-off-by: Shubh Gupta <[email protected]>
Co-authored-by: Copilot <[email protected]> Signed-off-by: Shubh Gupta <[email protected]>
Co-authored-by: Copilot <[email protected]> Signed-off-by: Shubh Gupta <[email protected]>
Co-authored-by: Copilot <[email protected]> Signed-off-by: Shubh Gupta <[email protected]>
Co-authored-by: Copilot <[email protected]> Signed-off-by: Shubh Gupta <[email protected]>
bboreham
left a comment
There was a problem hiding this comment.
OK, this is getting closer. I still have a few questions / clarifications below.
except for closing HTTP responses in BenchmarkTargetScraperGzip,
I didn't see this. Sounds like it would belong in a different PR since it's nothing to do with copying responses.
I guess these are the benchmark results you would highlight?
ParsePromText_NoMeta/parser=promtext-2 303.8Ki ± 0% 303.8Ki ± 0% ~ (p=0.361 n=6)
ParsePromText/parser=promtext-exact-2 550.8Ki ± 0% 310.7Ki ± 0% -43.58% (p=0.002 n=6)
ScrapeLoopScrapeAndReport/appV2=false/pooled=true-2 13.80Ki ± 4% 14.11Ki ± 7% ~ (p=0.699 n=6)
ScrapeLoopScrapeAndReport/appV2=false/pooled=false-2 584.3Ki ± 0% 206.3Ki ± 0% -64.69% (p=0.002 n=6)
ScrapeLoopScrapeAndReport/appV2=true/pooled=true-2 670.2Ki ± 1% 666.7Ki ± 4% ~ (p=0.310 n=6)
ScrapeLoopScrapeAndReport/appV2=true/pooled=false-2 1177.4Ki ± 1% 824.1Ki ± 1% -30.01% (p=0.002 n=6)
Avoid a full-body copy when checking for EOF or appending a redundant parser newline.
Fixes #19395.
Benchmarks
Production baseline:
6a8453ce4. Candidate production code:6e69d6efa. The gzip benchmark was measured with the same harness-only response-body cleanup on both sides (f5c7cf38d); that cleanup is not part of the final code diff.Go 1.26.1, darwin/arm64, Apple M4 Pro. Six paired runs, alternating order, with
-benchtime=500ms -count=1 -benchmem -cpu=2 -p=1.All 100 original cases are included, plus five added scenarios. Original benchmark setup is preserved except for closing HTTP responses in
BenchmarkTargetScraperGzip, which previously failed the leak check. Added scenarios use the PR harness with a 190,191-byte fixture and a smaller pool to exercise the unpooled path.One existing text-format append case measures about 2% slower in this run. All timings and allocations are retained below; this is not a claim that every workload improves.
Complete before/after comparison