Repository navigation
Conversation
The collector-views path decoded every OTLP point into an Observation (copying and UTF-8-checking each label) and then built, hashed and compared a sorted series-key string per point, though nearly every point is of a series seen before. decode_each_scalar passes each float point as a ScalarPoint whose labels stay encoded: its identity is the resource labels, series scope labels and point string attributes as length-prefixed bytes, written into one reused buffer. ViewExecutor::observe_point looks the identity up in a per-metric map of identity bytes to series id; only a miss decodes the labels and goes through the series key as before, then remembers the identity. The map compares the bytes on every hit, so a hash collision is never a match. Evicted series drop their identities before their ids are reused. On the 10,000-series, 100,000 samples/s q01 replay the collector takes 1.107 us per sample instead of 1.265 (median of 3). Emitted states are unchanged: the golden bytes match through both decode paths. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K1M6bo8kYWd83zXwh2Nobf
zzylol
force-pushed
the
perf/collector-views-series-intern
branch
from
November 30, 2026 15:44
832011c to
df6ba01
Compare
zzylol
changed the base branch from
feat/collector-views-late-corrections
to
feat/collector-views-lineage-deltas
November 30, 2026 15:44
This was referenced Nov 30, 2026
collector_views: carry the lineage in a binary frame in sketch.envelope (48.7 → 3.8 B per state)
#64
Draft
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
collector_viewsspends most of its per-sample CPU on the walk from OTLP point to series id, not on sketches. Every point was decoded into anObservation(each label copied and checked as UTF-8), and then a sortedk=v;series-key string was built, hashed and compared, even though nearly every point belongs to a series already seen. On the q01 replay (10,000 series × 10 samples/s), the collector used 1.265 µs/sample. ASAPQuery-backend uses ≈1.24 µs/sample for the same work (OTLP decode + series lookup + sketch update).decode_each_scalar). Each point's labels stay as bytes: its identity is the resource labels, series-scope labels and point string attributes, length-prefixed, written into one reused buffer.ViewExecutor::observe_pointlooks the identity up in a per-metric map from identity bytes to series id. Only on a miss does it decode the labels and go through the old series-key path, and then it remembers the identity.Review guide
feat/collector-views-lineage-deltas(collector_views: sequence numbers and delta emission (full, then deltas per window) #61). Stack: Use Prometheus (start, end] windows, drop late out-of-order samples, add matchers #53 → Print the collector's capabilities in ASAPPlanner's vocabulary (--print-capabilities) #54 → Load collector-views.json and write the view identity into OTLP metric metadata #55 → raw_forward: drop the raw samples of metrics only collector views read #56 → Build collector views on ASAPPlanner's executor (collector_views processor) #57 → Collector views: read OTLP in place, filter raw metrics on the bytes, export view counters #59 → collector_views: send late samples within retention as correction states #60 → collector_views: sequence numbers and delta emission (full, then deltas per window) #61 → this PR. One commit,df6ba01.832011con collector_views: send late samples within retention as correction states #60. Rebasing it onto collector_views: sequence numbers and delta emission (full, then deltas per window) #61 conflicted insrc/otap/codec.rsandtests/collector_views_e2e.rs. The resolution keeps collector_views: sequence numbers and delta emission (full, then deltas per window) #61's lineage decoding, and its golden test that strips the lineage, on top of this PR's in-place point path. The one newSketchEnvelopebuilt from aScalarPointgetslineage: None. The measurements below were taken on the collector_views: send late samples within retention as correction states #60 base; the restack changes nothing on that path. The lineage frame is the next PR on top of this one.codec.rs:DecodeAccumulator::push_data_point(the attribute loop now appends to the identity instead of writing labels; reserved keys are compared as bytes),ScalarPoint,push_identity_pair/push_identity_labels/identity_pairs(the byte layout), and wheredecode_viewwrites the per-scope identity prefix.view_executor.rs:SourceMetric::intern_point(hit, or miss →intern_labels→ remember), andevict_closed_series(identities of evicted series are dropped before their ids can be reused).ViewExecutor::observeandobserve_pointshare the routing body, nowViewExecutor::take, unchanged apart from parameter names.decode_eachkeeps its behaviour throughObservationSink.collector_views.rschanges one call.send,seal,encode) is unchanged.Behavior: before → after
The input is the e2e replay: the collector binary (
colA: OTLP receiver → fanout →collector_views+raw_forward→ OTLP exporter to a dummy sink) pinned to 2 CPUs, withcollector-views.json= q01 ondata(DDSketch, 5 s windows). A paced feeder sends 10,000 series × 10 samples/s (100,000 samples/s) as OTLP/HTTP, 10,000 points per request, with 4 string attributes per point. Collector CPU is read from/procover 40 s after a 25 s warm-up.0f77113)832011c)Profile (perf, 499 Hz, the whole collector process), as a share of collector CPU and the µs/sample it amounts to:
codec(attribute loop, label copy + UTF-8 check → identity write)write_series_key/write_attributes_key)observerouting + map lookup (incl. hashing)try_add≈3%)This serves the collector-views evaluation: the collector should not cost more CPU per sample than ASAPQuery-backend spends ingesting the same raw samples.
Interfaces
codec.rsview_executor.rs/// The collector views of one installed plan, built on the executor (stays). pub struct ViewExecutor { compiled: CompiledPhysicalDAG, metrics: HashMap<String, SourceMetric, ahash::RandomState>, pool: LocalPool, counts: Vec<ViewCounts>, } impl ViewExecutor { /// Takes one point as an `Observation` (tests, `asap-views-bench`). pub fn observe(&mut self, obs: &Observation); + /// `observe` of a point read in place by `decode_each_scalar`: a point whose identity was + /// seen before finds its series without decoding its labels. The processor's path. + pub fn observe_point(&mut self, point: &ScalarPoint<'_>); } /// One source metric: its series and the run groups reading it (private; stays). struct SourceMetric { ids: HashMap<String, u32, ahash::RandomState>, + /// `ScalarPoint::identity` → series id, one entry per attribute order a series arrived in. + by_identity: HashMap<Box<[u8]>, u32, IdentityHasher>, series: Vec<Option<Series>>, free_ids: Vec<u32>, groups: Vec<RunGroup>, key: String, codes: Vec<u32>, }Usage: the processor's path, as
collector_views.rsruns it for each OTLP message:Algorithm changes
Series lookup per point
push_data_pointwrites series-scope labels and string attributes into the scratchObservation(set_label).internrunswrite_series_key(resource, labels)(sortedk=v;).ids[key]; on a miss it creates the series.push_data_pointappends each string attribute to the identity (after the scope's prefix of resource and series labels). Nothing is copied into aStringand nothing is UTF-8 checked.intern_pointlooks upby_identity[identity]. The hash map compares the full bytes, so a hit is exact.labels()decodes the labels,intern_labelsruns the old steps 2–3, andby_identitygetsidentity → id.Observationlabels, and therefore the same series key and id. A miss always falls back to the old key path, so the canonical key alone still decides which series a point belongs to. This means the same attributes in a different order end up in one series, as before; the second order just gets its own identity entry.free_idscan be reused.equal_attributes_in_different_requests_are_one_series;different_attributes_never_share_a_series;evicted_identities_are_forgotten.IdentityHasherhashes every identity to 0, so each lookup there is decided by a full byte compare, as it is on a hash collision.retainoverby_identity.observe(&Observation)(tests, bench) still uses the key path.Decisions and open questions
u64and storing only the hash. That needs a separate verify step against the stored labels, which fails for a second attribute order. Keying the map by the bytes gets the full compare for free.a=b;c=d(two labels) apart froma="b;c=d"(one label whose value contains;and=). This PR keeps that behaviour (the identity map sits in front of the key), and the new test leaves such values out. Changing it would change the locked key layout.Verification
Run with
--features collectorin a separate target dir.cargo fmt --checkcargo clippy --features collector --all-targets -- -D warningsview_executor collector_views codec matchers baseline_nodes raw_forwardmatchers)tests/collector_views_e2e.rsemitted_states_match_the_golden_bytesnow checksdecode_each_scalar+observe_pointanddecode_each+observeagainst the golden bytes;otlp_in_view_states_outruns the processor (new path) against directobservetests/otap_pipeline_e2e.rsdecode_each/decode_pdata_to_observationscallersNew tests:
equal_attributes_in_different_requests_are_one_series: points with equal attributes, sent in three requests in two attribute orders, form one series (count 4, labels in first-seen order), with one identity entry per order.different_attributes_never_share_a_series: label sets whose bytes differ only in how they split (ab=cvsa=bc, a resource label vs the same point attribute, one label vs two) stay distinct series across two requests, with every hash colliding.evicted_identities_are_forgotten: after eviction and reuse of an id, the old identity does not find the new series.The end-to-end measurement is in the before → after table. The harness is the replay described there, with 3 interleaved runs per binary.
Follow-ups
🤖 Generated with Claude Code
https://claude.ai/code/session_01K1M6bo8kYWd83zXwh2Nobf