Skip to content

perf(otlp): series cache keyed by metric number and attribute bytes; request bodies in kept buffers - #894

Draft
zzylol wants to merge 3 commits into
feat/collector-views-filefrom
perf/otlp-push-ingest-path
Draft

zzylol wants to merge 3 commits into
feat/collector-views-filefrom
perf/otlp-push-ingest-path

Conversation

@zzylol

@zzylol zzylol commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: on the W2 shape (quantile_over_time(0.99, data[1m]) only, DDSketch view, 10k series × 10 samples/s over OTLP/HTTP, push precompute), ASAPQuery-backend spends about 1.40 µs of CPU per sample, end to end. The DDSketch updates are a small part of that.
  • Change: the OTLP decoder's series-cache key becomes a per-metric number plus the point's attribute bytes, so the resource labels and metric name are no longer copied and compared for every point. Request bodies are read into a small pool of buffers kept between requests, so their pages stay resident instead of faulting in on every request.
  • Effect: W2 over OTLP goes from 1.386 to 1.336 µs/sample (−3.6 %, median of 6 runs, each paired with a before run on the other core set). The OTLP threads (tokio-rt-worker) drop from 0.040 to 0.033 cores; the ingest shards are unchanged. Answers are unchanged.

Restack (2026-11-30) onto #891 40d0d0d, at 0900bea

Review guide

Behavior: before → after

The input is a paced feeder sending OTLP/HTTP protobuf, 10k series of data at 10 samples/s, 4 requests in flight, to data_plane --plan plan-w2-sps10.json --ingest-threads 2 --precompute-threads 2 --query-threads 2 --no-view-persistence (push precompute). CPU is the data plane's per-thread CPU over 100 s of steady state.

Before (#891 head) After
CPU per sample, end to end 1.386 µs 1.336 µs
OTLP decode threads (tokio-rt-worker) 0.040 cores 0.033 cores
Ingest shards (ingest-*) 0.093 cores 0.095 cores
Answers identical identical

Interfaces

None. Every changed item is private: otlp::Decoder's fields, Walk, and data_plane's write_otlp / BodyBuffer. A body over the limit still gets 413, and a body that cannot be read gets 400, with the texts axum's body extractor answered with.

Algorithm changes

Series lookup per OTLP point.

  • Before:
    1. Build the key: the resource's labels (length-prefixed), the metric name and suffix, then the attributes.
    2. Look it up in SeriesCache: predicted next entry, else ahash plus byte compare.
    3. On a miss, build the labels and intern.
  • After:
    1. Once per Metric message, find metric_id(resource, name, suffix): the same bytes as before up to the attributes, mapped to a number given on first sight.
    2. Per point, the key is the 4-byte number followed by the attribute bytes. The rest is unchanged.
  • Correctness: the old key splits uniquely into (resource labels, name and suffix, attributes), because each part is length-prefixed or self-delimiting. The number is a bijection on the first two parts, so two points share a new key exactly when they shared the old one. Every cache hit is still a full byte compare of the key, so a hash collision only costs a compare.

Remaining profile (after, W2 over OTLP, perf 30 s)

Over the same 100 s: 1.16 µs/sample in a quiet run (11.7 s CPU for 10.1 M samples). Of that, 74 % is the ingest shards, 22 % the OTLP threads and 3 % jemalloc's background thread. Self time, as a share of all data-plane CPU:

  • OTLP threads:
    • otlp::Walk::metric 9.1 % (the protobuf walk, key build and cache probe, inlined).
    • memmove 5.8 % (the body copy into the kept buffer and the samples' Vec).
    • memcmp 4.1 % (cache key compares).
    • InstalledPrecompute::try_ingest 1.5 % (splitting samples by shard).
  • One ingest shard (two run):
    • GroupTable::column_parts / ColumnParts::part 6.4 %.
    • RawData::append 2.8 % and its stable sort 2.0 % (each push morsel is turned into raw data).
    • PushShard::push / fold 2.8 % / 2.0 %.
    • summary::execute poll 2.4 %.
    • StateColumnUpdater::update_value 2.0 %.
    • DdSketch::try_add 2.0 % plus log 1.3 %.
    • Routing::route 1.6 %.
    • Value drop 1.2 %.

This profile was taken with an extra commit, later dropped (see below), that only changed how a shard finds a sample's push groups. The OTLP side is the same code as this PR.

Not done / open

  • The ingest shards are now about three quarters of the CPU. Their cost is the push pipeline per morsel: building RawData and sorting it (RawData::append), the executor's GroupTable / summary operator, and dropping Values. DDSketch try_add is about 2 %. Cutting this means feeding push morsels to the summary operator without the generic raw-data → batch → executor path, which is a larger change.
  • A per-metric lookup of the push groups by interned pointer was measured and showed no gain (1.396 vs 1.410 µs/sample, medians of 6 and 3), so it was dropped.

Gates

  • cargo fmt --check, cargo clippy --workspace --all-targets -D warnings: clean.
  • otlp 18, storage 52, precompute 12; data_plane: ingest_protocols, collector_views, server, push_precompute, planner_executor_parity, ingest_shards, window_levels: all pass (with ulimit -n 65536; parity 6/6).

🤖 Generated with Claude Code

https://claude.ai/code/session_01K1M6bo8kYWd83zXwh2Nobf

@zzylol zzylol added enhancement New feature or request area: data plane Runtime ingestion, storage, and query-serving data paths labels Nov 30, 2026
zzylol and others added 3 commits November 30, 2026 06:43
…across requests and orders

Guards the series cache's key before it changes: the same encoded
attributes under the same resource and metric take the same series, built
once, whatever the order of metrics and resources; under another metric
(one name a prefix of the other) or resource, another series.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6bo8kYWd83zXwh2Nobf
…utes

A point's series cache key was the resource's labels, the metric name
and the encoded attributes, copied into the key buffer and compared for
every point. Each resource's labels and metric name (with its suffix) now
get a number once per metric message, and a point's key is that number and
its attributes' bytes: less copied and compared per point. Labels are
still built only for a series not cached, and every hit is still a
byte-for-byte key match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6bo8kYWd83zXwh2Nobf
An OTLP body was collected into a new allocation per request, whose pages
faulted in on every request (page faults and the copy were about a tenth
of the decode threads' CPU at 100k samples/s). The handler now reads the
body frame by frame into a buffer from a small pool (at most 16, none over
the 32 MiB a decoder keeps), sized by Content-Length when given, and
returns it after decoding. Bodies over the limit still get 413, with the
text axum's body extractor answers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6bo8kYWd83zXwh2Nobf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: data plane Runtime ingestion, storage, and query-serving data paths enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant