Skip to content

feat(dogstatsd): enforce memory admission with idle-cache reclaim and drop telemetry - #3509

Open
blt wants to merge 1 commit into
blt/1m-19-opt-in-byte-budgetfrom
blt/1m-20-memory-admission
Open

blt wants to merge 1 commit into
blt/1m-19-opt-in-byte-budgetfrom
blt/1m-20-memory-admission

Conversation

@blt

@blt blt commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A configured memory bound needs enforcement where memory grows. DogStatsD decodes lines and grows aggregate rows without consulting any budget. Under a flood of unique contexts, the process grows until an OOM kill drops every buffered metric.

This change adds non-mutating growth estimators for dense aggregate storage and reserves budget before DogStatsD decodes a line and before an aggregate row grows, whenever a budget is attached. On a failed reservation, it runs at most one idle-context reclaim sweep per 250 ms and retries. If the retry still fails, it refuses the line and preserves the existing row. It counts the refused line and its wire bytes once.

The opt-in flood sends 50,000 lines of 8 KiB per second of unique gauges or sets into a 1 GiB container with 200,000 idle contexts. Stripped optimized-release runs peak at 978.6 MiB for gauges and 896.5 MiB for sets, under a 1,008 MiB ceiling, with zero OOM kills. Default unbounded runs attach no budget and refuse nothing.

Change Type

  • Bug fix
  • New feature
  • Non-functional
  • Performance

How did you test this PR?

  • cargo check --locked --workspace --tests
  • cargo test --locked -p saluki-components --lib estimates_set_growth_without_mutating_the_row
  • cargo test --locked -p saluki-components --lib byte_budget
  • cargo test --locked -p saluki-components --lib lines_preserve_delimiters_without_counting_stream_prefixes

References

Series overview

@dd-octo-sts dd-octo-sts Bot added area/core Core functionality, event model, etc. area/components Sources, transforms, and destinations. source/dogstatsd DogStatsD source. transform/aggregate Aggregate transform. labels Nov 26, 2026
@blt
blt added this pull request to stack #3510 November 26, 2026 23:03
@blt
blt marked this pull request as ready for review November 26, 2026 23:11
@blt
blt requested a review from a team as a code owner November 26, 2026 23:12
@github-actions

Copy link
Copy Markdown
Contributor

AI review by Claude - workflow run

Patch is correct, with 0 blocking findings. The admission accounting and growth estimates hold up. The main concerns are that DogStatsD-specific admission state and global dsd_* counters live in the core MetricMetadata, and that the new drop counters bypass the standard component_events_dropped_total metric.


lib/saluki-core/src/data_model/event/metric/metadata.rs L29

Not blocking: Why does the core MetricMetadata carry DogStatsD-specific admission state? The event types under src/data_model/event/ are Saluki's own model. This field also makes Drop and Clone on every metric emit global telemetry (dsd_byte_budget_*). A cloned tracked metric also allocates an Arc on each fan-out copy. Could the field be a generic "admission ticket" that the source owns, with the counters registered by the DogStatsD source? That keeps protocol names and side effects out of the data model.


lib/saluki-core/src/data_model/event/metric/metadata.rs L147

Not blocking: These counters use the global counter! macro from a LazyLock, so they get no component tags. They also bind to whichever recorder is installed at first use. We emit drops through the standard component_events_dropped_total with a drop_reason tag, for example drop_reason=byte_budget. Could the source and aggregate count refusals there, through their MetricsBuilder? The refused wire-bytes counter could stay as a separate source metric.


lib/saluki-components/src/transforms/aggregate/mod.rs L401

Not blocking: aggregate_byte_budget_refused_events_total is a component-specific name for a drop. We use component_events_dropped_total with drop_reason for this, like the context-limit path in record_rejected_metric.


lib/saluki-components/src/sources/dogstatsd/mod.rs L1723

Not blocking: Nothing tests this source-side refusal path. The new tests only cover the aggregate side. Please add a test that sets a tiny budget on the decoder and checks three things: handle_frame returns Ok(None), no event is produced, and the refusal counters increase by one line and its wire bytes.


lib/saluki-components/src/sources/dogstatsd/mod.rs L1718

Not blocking: 2, 32, and 288 here, plus the + 32 per configured tag in DogStatsDDecoder::new, are unexplained estimate constants. Please put them in named constants at the top of the file, each with a short comment on what it covers (for example, per-tag overhead and fixed event size).


lib/saluki-core/src/data_model/event/value/histogram.rs L113

Not blocking: The 3 behind inline_merge_growth_bytes is the inline sample capacity of the aggregate's dense storage. That's an aggregate storage detail, not a property of Histogram. I would keep this helper private in transforms/aggregate/storage.rs and leave only merge_growth_bytes on the public type.


lib/saluki-components/src/transforms/aggregate/mod.rs L1305

Not blocking: This unit test inserts one million contexts and can use hundreds of MiB, which is heavy for the unit test job. Could it use a smaller count, with a budget scaled to match, or move to a benchmark or #[ignore] test?


lib/saluki-core/src/data_model/event/metric/metadata.rs L161

Nit: "e.g. an aggregation bypass, a filter" -> "such as an aggregation bypass or a filter". The sentence before it states a topology assumption without a reason. Say why one aggregating branch is enough for exactly-once counting, or link to where the topology enforces it.

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 Bot left a comment

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.

Bits Code Review: FAIL

Packed histogram and timer payloads can allocate roughly four times their pre-decode reservation, consuming unreserved memory before aggregation can reject them.

Open Bits AI session

🤖 Bits Code Review · Commit 85ac43c

@pr-commenter

pr-commenter Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Binary Size Analysis (Agent Data Plane)

Baseline: 625e229 · Comparison: df7b9ff · diff
Analysis Configuration: optimized-release profile, stripped binaries · Pass/Fail Threshold: +5%
Sizes: 25.96 MiB (baseline) vs 26.05 MiB (comparison)
Size Change: +96.16 KiB (+0.36%)

✅ Binary size difference within threshold

Changes by Module
Module File Size Symbols
saluki_core::data_model::event +31.39 KiB 93
saluki_core::topology::interconnect +19.16 KiB 77
saluki_app::accounting::initialize_memory_bounds +15.73 KiB 3
saluki_transform_kernels::filterlist::PrefixFilterKernel +14.46 KiB 1
agent_data_plane::components::dogstatsd_prefix_filter -12.55 KiB 57
saluki_components::transforms::dd_trace_normalizer -12.07 KiB 29
core +10.81 KiB 7587
saluki_transform_kernels::aggregate::storage +10.54 KiB 33
[sections] +6.78 KiB 11
saluki_transform_kernels::aggregate::AggregateCore<M> +6.72 KiB 5
datadog_agent_metrics_v3::writer::write_packed_column -6.62 KiB 36
saluki_components::transforms::logs_processing_rules -5.07 KiB 9
agent_data_plane::components::dogstatsd_post_aggregate_filter +4.86 KiB 32
hashbrown -3.63 KiB 309
[Unmapped] +3.50 KiB 1
saluki_core::accounting::byte_budget +3.38 KiB 6
saluki_components::sources::dogstatsd +2.61 KiB 354
smallvec +2.42 KiB 127
agent_data_plane::cli::run +2.16 KiB 54
saluki_core::observability::metrics -2.14 KiB 12
Detailed Symbol Changes
    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.9% +96.7Ki  +0.9% +93.2Ki    [17871 Others]
  [NEW] +76.3Ki  [NEW] +76.3Ki    saluki_components::common::datadog::io::run_endpoint_io_loop::_{{closure}}::h8ca47fa7714ca2c6
  [NEW] +54.3Ki  [NEW] +54.3Ki    agent_data_plane::cli::run::create_topology::_{{closure}}::hd4bddb7cd350a463
  [NEW] +53.9Ki  [NEW] +53.9Ki    datadog_agent_runtime::env::workload::RemoteAgentWorkloadProvider::new::_{{closure}}::h219faedadb4f38fa
  [NEW] +49.8Ki  [NEW] +49.8Ki    saluki_components::common::otlp::OtlpServerConfiguration::build::_{{closure}}::hfad00c539641b63c
  [NEW] +49.1Ki  [NEW] +49.1Ki    _<saluki_components::sources::apm::Apm as saluki_core::components::sources::Source>::run::_{{closure}}::_{{closure}}::h9a6cc5c21ebb1f2d
  [NEW] +47.1Ki  [NEW] +47.1Ki    saluki_components::common::otlp::traces::translator::OtlpTracesTranslator::translate_spans::hf901da29c04dec8a
  [NEW] +45.8Ki  [NEW] +45.8Ki    agent_data_plane::cli::run::handle_run_command::_{{closure}}::h355872a7e11ac26b
  [NEW] +45.8Ki  [NEW] +45.8Ki    _<agent_data_plane::internal::control_surfaces::DogStatsDAPIWorker as saluki_core::runtime::supervisable::Supervisable>::initialize::_{{closure}}::h7555598354fce9b1
  [NEW] +44.0Ki  [NEW] +44.0Ki    agent_data_plane::async_main::_{{closure}}::h87678173e2440e00
  [NEW] +42.6Ki  [NEW] +42.6Ki    saluki_core::topology::built::BuiltTopology::spawn_inner::_{{closure}}::h32e95f2e2833f1bd
  [DEL] -44.0Ki  [DEL] -44.0Ki    agent_data_plane::async_main::_{{closure}}::hb8016db0312ae556
  [DEL] -44.2Ki  [DEL] -44.2Ki    _<saluki_components::transforms::aggregate::Aggregate as saluki_core::components::transforms::Transform>::run::_{{closure}}::hbe4669d3e5e78a65
  [DEL] -45.8Ki  [DEL] -45.8Ki    _<agent_data_plane::internal::control_surfaces::DogStatsDAPIWorker as saluki_core::runtime::supervisable::Supervisable>::initialize::_{{closure}}::h453fabd55c638f47
  [DEL] -45.9Ki  [DEL] -45.9Ki    agent_data_plane::cli::run::handle_run_command::_{{closure}}::h35643375dbbb1dd0
  [DEL] -47.1Ki  [DEL] -47.1Ki    saluki_components::common::otlp::traces::translator::OtlpTracesTranslator::translate_spans::hed7e937a569f3f3c
  [DEL] -49.1Ki  [DEL] -49.1Ki    _<saluki_components::sources::apm::Apm as saluki_core::components::sources::Source>::run::_{{closure}}::_{{closure}}::hc5be7c9d8f4120ca
  [DEL] -49.7Ki  [DEL] -49.7Ki    saluki_components::common::otlp::OtlpServerConfiguration::build::_{{closure}}::h44e5a95fe933dcbf
  [DEL] -53.2Ki  [DEL] -53.2Ki    agent_data_plane::cli::run::create_topology::_{{closure}}::h00ae91d818430b2b
  [DEL] -53.9Ki  [DEL] -53.9Ki    datadog_agent_runtime::env::workload::RemoteAgentWorkloadProvider::new::_{{closure}}::ha190132c3565deca
  [DEL] -76.3Ki  [DEL] -76.3Ki    saluki_components::common::datadog::io::run_endpoint_io_loop::_{{closure}}::hbf85cf971a95638e
  +0.4% +96.2Ki  +0.3% +92.6Ki    TOTAL

@pr-commenter

pr-commenter Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Regression Detector (Agent Data Plane)

Run ID: c07e82a6-5f52-40aa-a0a1-59306fe594a7
Baseline: 625e2290 · Comparison: df7b9ffa · diff

Optimization Goals: ✅ No significant changes detected

Fine details of change detection per experiment (5)

Experiments configured erratic: true are tagged (ignored) and skipped when determining which experiments regressed or improved. Experiments which are detected as erratic at runtime are tagged (erratic) to flag that the run's sample dispersion was high, but their regression / improvement signal still counts.

experiment goal Δ mean % links
quality_gates_rss_dsd_low memory utilization ⚪ +1.95 metrics profiles logs
quality_gates_rss_dsd_medium memory utilization ⚪ +0.80 metrics profiles logs
quality_gates_rss_idle memory utilization ⚪ -0.70 metrics profiles logs
quality_gates_rss_dsd_ultraheavy memory utilization ⚪ -3.36 metrics profiles logs
quality_gates_rss_dsd_heavy memory utilization ⚪ -3.73 metrics profiles logs
Bounds Checks: ✅ Passed (5)
experiment check replicates observed links
quality_gates_rss_dsd_heavy memory_usage 10/10 ✅ 156.70MiB ≤ 250MiB metrics profiles logs
quality_gates_rss_dsd_low memory_usage 10/10 ✅ 43.98MiB ≤ 55MiB metrics profiles logs
quality_gates_rss_dsd_medium memory_usage 10/10 ✅ 62.60MiB ≤ 92MiB metrics profiles logs
quality_gates_rss_dsd_ultraheavy memory_usage 10/10 ✅ 230.08MiB ≤ 420MiB metrics profiles logs
quality_gates_rss_idle memory_usage 10/10 ✅ 30.38MiB ≤ 36MiB metrics profiles logs
Explanation

A change is flagged as a regression when |Δ mean %| > 5.00% in the regressing direction for its optimization goal AND SMP marks the experiment as a regression (is_regression: true). Improvements use the matching criteria for the improving direction. Experiments configured erratic: true (tagged (ignored)) are skipped outright; experiments detected as erratic at runtime (tagged (erratic)) still count, since that flag describes sample dispersion rather than directional certainty. The Δ mean % cell is colored accordingly: 🟢 = improvement, 🔴 = regression, ⚪ = neutral. Reduction in CPU or memory is an improvement; reduction in ingress throughput is a regression. Experiments tagged (no analysis) show ⚠️ n/a: SMP ran them but produced no analysis, usually because a replicate failed and exhausted its retries. Check the SMP report for that experiment's replicate failures.

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 Bot left a comment

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.

Bits Code Review: PASS

More details

Scalar admission intentionally uses conservative growth estimates, while pre-decode refusals are tracked as wire lines and bytes. The author’s explanations match the affected code, so neither candidate warrants a finding.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit d555791

@blt
blt force-pushed the blt/1m-20-memory-admission branch from d555791 to 31b2817 Compare December 3, 2026 02:05
gh-worker-dd-mergequeue-cf854d Bot pushed a commit that referenced this pull request Dec 3, 2026
…it admission (#3492)

## Summary

Packed contexts need to share recurring strings, such as `env:prod`, without storing a copy in every context. The existing `GenericMapInterner` cannot serve that role, and no existing crate meets all four constraints below.

`GenericMapInterner` admits every string on its first lookup. On the 1M RUM workload, each gauge carries one unique 51 B UUID tag. Roughly 143,000 of those one-off tags fill the 8 MiB interner budget, and later recurring tags fall back to the heap. `SymbolTable` admits a string only on its second sighting, through a lazily allocated 8,192-slot thread-local witness (64 KiB per interning thread).

Each of the 16 `SymbolTable` shards also keeps a 512 B atomic bloom filter of resident strings, 8 KiB across all shards. A first sighting checks that filter and the witness without taking any shard lock. Filter false positives cost a read lock but cannot admit a first sighting.

`GenericMapInterner` returns a self-contained 24 B `MetaString` handle around a 16 B `StringState`. A packed context stores many tags in one allocation and needs a 4 B handle per tag. `SymbolTable` returns `u32` IDs into an external table, and owners read them without locking. The same IDs double as dictionary hints for the V3 encoder.

Changing `GenericMapInterner` to match would break its current callers. Workload metadata, the tagger, OTLP traces and strict-mode context resolution rely on self-contained handles and first-hit admission. `SymbolTable` therefore stays a separate type with its own contract.

Existing crates do not fit either. `lasso`, `ustr` and `string-interner` never reclaim dropped strings, so a long-lived agent grows as tags churn. `internment` reclaims strings but lacks a byte cap, two-hit admission and 4 B IDs. `SymbolTable` reference-counts each record and returns its space to a per-shard free list on the last release.

This change adds no caller, so it has no Tier 1 effect by itself. Packed contexts and the V3 packed-symbol mapping depend on it.

## Change Type
- [ ] Bug fix
- [ ] New feature
- [x] Non-functional
- [ ] Performance

## How did you test this PR?

- `cargo check --locked --workspace --tests`
- `cargo test --locked -p stringtheory --lib singletons_leave_space_for_late_shared_symbols`
- `cargo test --locked -p stringtheory`

## References

- Stacked on: #3491 (`blt/1m-02-tagstr-borrowed-views`)
- Requires: none.
- Required by: packed `Context` storage through `SymbolTable` IDs, and V3 packed-symbol mapping through `Symbol` IDs.
- Release note: none, because this change has no externally visible effect.

### Series overview

- **Context & Tag Density:** pack contexts into one allocation and drop unused cache overhead.
  - #3490: shard ContextCache with inline expiry and live-context reuse (merged)
  - #3491: expose borrowed metric names and tags as `&str`
  - **Current (#3492):** add a sharded symbol dictionary with two-hit admission
  - #3511: store Context and its tags in one packed allocation
- Dense Aggregation (#3495–#3496): replace 177 B buckets with per-kind typed pages.
- Resumable Flush (#3497–#3499): shrink metric buffers and interleave bounded flush chunks.
- Idle Pipeline Bypass (#3500–#3501): skip inactive transforms and borrow client telemetry.
- `300m` CPU (#3502–#3507): cut encoder, codec and worker-pool hot-path cost.
- Memory Admission (#3508–#3509): enforce opt-in configured memory limits with idle reclaim and counted drops.



Co-authored-by: brian.troutwine <brian.troutwine@datadoghq.com>
dd-octo-sts Bot pushed a commit that referenced this pull request Dec 3, 2026
…it admission (#3492)

## Summary

Packed contexts need to share recurring strings, such as `env:prod`, without storing a copy in every context. The existing `GenericMapInterner` cannot serve that role, and no existing crate meets all four constraints below.

`GenericMapInterner` admits every string on its first lookup. On the 1M RUM workload, each gauge carries one unique 51 B UUID tag. Roughly 143,000 of those one-off tags fill the 8 MiB interner budget, and later recurring tags fall back to the heap. `SymbolTable` admits a string only on its second sighting, through a lazily allocated 8,192-slot thread-local witness (64 KiB per interning thread).

Each of the 16 `SymbolTable` shards also keeps a 512 B atomic bloom filter of resident strings, 8 KiB across all shards. A first sighting checks that filter and the witness without taking any shard lock. Filter false positives cost a read lock but cannot admit a first sighting.

`GenericMapInterner` returns a self-contained 24 B `MetaString` handle around a 16 B `StringState`. A packed context stores many tags in one allocation and needs a 4 B handle per tag. `SymbolTable` returns `u32` IDs into an external table, and owners read them without locking. The same IDs double as dictionary hints for the V3 encoder.

Changing `GenericMapInterner` to match would break its current callers. Workload metadata, the tagger, OTLP traces and strict-mode context resolution rely on self-contained handles and first-hit admission. `SymbolTable` therefore stays a separate type with its own contract.

Existing crates do not fit either. `lasso`, `ustr` and `string-interner` never reclaim dropped strings, so a long-lived agent grows as tags churn. `internment` reclaims strings but lacks a byte cap, two-hit admission and 4 B IDs. `SymbolTable` reference-counts each record and returns its space to a per-shard free list on the last release.

This change adds no caller, so it has no Tier 1 effect by itself. Packed contexts and the V3 packed-symbol mapping depend on it.

## Change Type
- [ ] Bug fix
- [ ] New feature
- [x] Non-functional
- [ ] Performance

## How did you test this PR?

- `cargo check --locked --workspace --tests`
- `cargo test --locked -p stringtheory --lib singletons_leave_space_for_late_shared_symbols`
- `cargo test --locked -p stringtheory`

## References

- Stacked on: #3491 (`blt/1m-02-tagstr-borrowed-views`)
- Requires: none.
- Required by: packed `Context` storage through `SymbolTable` IDs, and V3 packed-symbol mapping through `Symbol` IDs.
- Release note: none, because this change has no externally visible effect.

### Series overview

- **Context & Tag Density:** pack contexts into one allocation and drop unused cache overhead.
  - #3490: shard ContextCache with inline expiry and live-context reuse (merged)
  - #3491: expose borrowed metric names and tags as `&str`
  - **Current (#3492):** add a sharded symbol dictionary with two-hit admission
  - #3511: store Context and its tags in one packed allocation
- Dense Aggregation (#3495–#3496): replace 177 B buckets with per-kind typed pages.
- Resumable Flush (#3497–#3499): shrink metric buffers and interleave bounded flush chunks.
- Idle Pipeline Bypass (#3500–#3501): skip inactive transforms and borrow client telemetry.
- `300m` CPU (#3502–#3507): cut encoder, codec and worker-pool hot-path cost.
- Memory Admission (#3508–#3509): enforce opt-in configured memory limits with idle reclaim and counted drops.

Co-authored-by: brian.troutwine <brian.troutwine@datadoghq.com> 8299071

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 Bot left a comment

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.

Bits Code Review: PASS

More details

Scalar updates to existing timestamps can be refused near the memory ceiling. The human PR discussion explicitly accepts this conservative estimate to avoid timestamp-overlap scans, so the reviewer's sole candidate was dismissed as intentional behavior.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 5a83c85

gh-worker-dd-mergequeue-cf854d Bot pushed a commit that referenced this pull request Dec 3, 2026
#3511)

## Summary

Each DogStatsD context at base costs about 1 KB across separate heap objects. It holds a 192 B `ArcInner<ContextInner>`, a 48 B tag-set `Arc`, a 128 B to 320 B tag `Vec` and 64 B for spilled UUIDs. On 1M RUM, active `dsd_in` live heap reaches 886.9 MiB to 929.9 MiB.

The `TagSetCache` adds 108 MiB to 145 MiB at the production 2,000,000-entry limit. It hits on 0.095% of lookups, 977 hits against 1,022,675 misses, and its backing slabs never shrink.

Tuning the existing types cannot remove this cost, because the separate allocations and the shared tag-set `Arc` are the overhead. This change stores the name, host, tag descriptors and inline bytes in one immutable allocation behind an 8 B handle. Recurring strings become 4 B `SymbolTable` IDs, and contexts keep sharing origin tags.

A closed `PrefixKind` selects the prefix layout. The `WithOrigin`, `WithLease`, and `WithOriginLease` structs define the layouts that have a prefix.

The default heap-allowed path bypasses the `TagSetCache` entirely. The strict path keeps its interner quota and refuses data that it cannot represent.

Stripped `optimized-release` Tier 1 runs show the gain from this change together with the borrowed views and `SymbolTable` it activates. Peak memory falls by 707.7 MiB on 1M RUM, 679.6 MiB on 500k default, 636.3 MiB on all-unique and 278.0 MiB on mixed churn. Cgroup CPU on 1M RUM falls 14.9%. Active `dsd_in` live heap on 1M RUM falls from 836.8 MiB to 210.2 MiB.

## Change Type
- [ ] Bug fix
- [ ] New feature
- [ ] Non-functional
- [x] Performance

## How did you test this PR?

- `cargo check --locked --workspace --tests`
- `cargo test --locked -p saluki-core --lib data_model::event::metric::context`
- `cargo test --locked -p saluki-components --lib sources::dogstatsd::resolver::tests`
- Tier 1 runs use stripped `optimized-release` builds against base `18f587f5f6` in cgroup v2, in default unbounded mode.
- 1M RUM holds 1,000,000 gauges that each carry one unique 51 B UUID tag and 4 to 10 shared tags.
- 500k default runs the same stream under Saluki's default 500,000-entry context and tag-set cache limits.
- All-unique holds 1,000,000 gauges that each carry eight unique tags of 32 B to 50 B.
- Mixed churn cycles gauges, counters, rates, sets and sketches between 200,000 and 1,000,000 active contexts.

## References

- Stacked on: #3492 (`blt/1m-03-sharded-symbol-table`)
- Supersedes: #3494 (auto-closed by GitHub when reordering #3493 above packed contexts)
- Requires: borrowed `&str` / `ContextTags` views (#3491), and two-hit `SymbolTable` IDs (#3492).
- Required by: V3 packed-symbol mapping through packed tag symbol IDs, and stack tag deduplication through the packed builder.
- Release note: `releasenotes/notes/packed-contexts-0a5b1c9ad15dc05f.yaml`

### Series overview

- **Context & Tag Density:** pack contexts into one allocation and drop unused cache overhead.
  - #3490: shard ContextCache with inline expiry and live-context reuse (merged)
  - #3491: expose borrowed metric names and tags as `&str`
  - #3492: add a sharded symbol dictionary with two-hit admission
  - **Current (#3511):** store Context and its tags in one packed allocation
- Dense Aggregation (#3495–#3496): replace 177 B buckets with per-kind typed pages.
- Resumable Flush (#3497–#3499): shrink metric buffers and interleave bounded flush chunks.
- Idle Pipeline Bypass (#3500–#3501): skip inactive transforms and borrow client telemetry.
- `300m` CPU (#3502–#3507): cut encoder, codec and worker-pool hot-path cost.
- Memory Admission (#3508–#3509): enforce opt-in configured memory limits with idle reclaim and counted drops.


Co-authored-by: brian.troutwine <brian.troutwine@datadoghq.com>
gh-worker-dd-mergequeue-cf854d Bot pushed a commit that referenced this pull request Dec 3, 2026
## Summary

Every aggregated DogStatsD `Set` at base allocates a `HashSet`, even when it holds one member. A singleton set therefore pays for a heap table and its control bytes to store a single string.

Dense aggregate pages need a set representation that fits a fixed-size `SetRow`. Without `SetMembers`, the dense storage build fails with `E0425` for the missing type.

This change adds `SetMembers`, which stores empty and singleton sets inline. It allocates a hash table only when a second distinct member arrives. Merging timestamped buckets still preserves exact deduplication.

This change has no separate Tier 1 measurement. It is a compile prerequisite for dense aggregate pages, which carry the measured gain.

## Change Type
- [ ] Bug fix
- [ ] New feature
- [ ] Non-functional
- [x] Performance

## How did you test this PR?

- `cargo check --locked --workspace --tests`
- `cargo test --locked -p saluki-core --lib promotes_only_for_distinct_members`

## References

- Stacked on: #3511 (`blt/1m-05-packed-context`)
- Requires: none.
- Required by: dense aggregate pages through `SetMembers` in `SetRow`.
- Release note: `releasenotes/notes/inline-sets-b5611095646c97f9.yaml`

### Series overview

- Context & Tag Density (#3490–#3492, #3511): pack contexts into one allocation and drop unused cache overhead.
- **Dense Aggregation:** replace 177 B buckets with per-kind typed pages.
  - **Current (#3495):** store singleton Set values inline
  - #3496: store live aggregate metrics in dense typed pages indexed by u32 slots
- Resumable Flush (#3497–#3499): shrink metric buffers and interleave bounded flush chunks.
- Idle Pipeline Bypass (#3500–#3501): skip inactive transforms and borrow client telemetry.
- `300m` CPU (#3502–#3507): cut encoder, codec and worker-pool hot-path cost.
- Memory Admission (#3508–#3509): enforce opt-in configured memory limits with idle reclaim and counted drops.


Co-authored-by: brian.troutwine <brian.troutwine@datadoghq.com>
@blt
blt force-pushed the blt/1m-20-memory-admission branch from 5a83c85 to 57f1fa8 Compare December 3, 2026 19:00

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 Bot left a comment

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.

Bits Code Review: PASS

More details

The completed static review identified no actionable defect in memory admission or refusal accounting. Runtime tests were not run, and production telemetry was excluded.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 57f1fa8

@blt
blt force-pushed the blt/1m-20-memory-admission branch from 57f1fa8 to df55d5b Compare December 3, 2026 19:57

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 Bot left a comment

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.

Bits Code Review: PASS

More details

The admission paths reserve budget before decoding or growing aggregate storage, while refused aggregate updates preserve existing values. Runtime memory ceilings and the reported flood-test results were not independently validated.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit df55d5b

tobz pushed a commit that referenced this pull request Dec 4, 2026
…ages indexed by u32 slots (#3496)

## Summary

The aggregator stores every series in `HashMap<Context,
AggregatedMetric>`. Each bucket costs 177 B, because `MetricValues`
reserves 104 B for its largest variant, a DDSketch. A gauge pays that
full size plus 48 B of inline metadata. On 1M RUM, the table holds 362.0
MiB to 379.6 MiB of live heap.

The table also doubles at 917,505 contexts, just below the 1M target.
That resize grows it from 192 MiB to 384 MiB and briefly holds 576 MiB
of old and new tables at once. A different hash map type cannot fix
this, because each bucket stays sized for the largest value.

This change moves values into per-kind 32 KiB typed pages. A thin index
stores a 4 B `u32` slot with 3 kind bits and 29 row bits, about 10 MiB
at 1M contexts. A gauge row takes 40 B, about 48 MiB at 1M contexts.
Rare multi-point rows and owned metadata spill to exact overflow stores.

Stripped `optimized-release` Tier 1 runs show peak memory falling by
497.9 MiB on 1M RUM, 506.5 MiB on all-unique and 482.3 MiB on mixed
churn. Cgroup CPU falls 20.8% on 1M RUM, 10.9% on all-unique and 28.6%
on mixed churn. Active `dsd_agg` live heap on 1M RUM falls from 362.0
MiB to 56.3 MiB.

## Change Type
- [ ] Bug fix
- [ ] New feature
- [ ] Non-functional
- [x] Performance

## How did you test this PR?

- `cargo check --locked --workspace --tests`
- `cargo test --locked -p saluki-components --lib
every_type_matches_metric_values_merge`
- Tier 1 runs use stripped `optimized-release` builds against base
`18f587f5f6` in cgroup v2, in default unbounded mode.
- 1M RUM holds 1,000,000 gauges that each carry one unique 51 B UUID tag
and 4 to 10 shared tags.
- All-unique holds 1,000,000 gauges that each carry eight unique tags of
32 B to 50 B.
- Mixed churn cycles gauges, counters, rates, sets and sketches between
200,000 and 1,000,000 active contexts.

## References

- Stacked on: #3495 (`blt/1m-06-inline-singleton-set`)
- Requires: inline `SetMembers`.
- Required by: resumable flush through `u32` slot cursors, and storage
growth estimates through dense rows.
- Release note:
`releasenotes/notes/use-dense-aggregate-storage-8f83ecb8c4eaac61.yaml`

### Series overview

- Context & Tag Density (#3490–#3492, #3511): pack contexts into one
allocation and drop unused cache overhead.
- **Dense Aggregation:** replace 177 B buckets with per-kind typed
pages.
  - #3495: store singleton Set values inline
- **Current (#3496):** store live aggregate metrics in dense typed pages
indexed by u32 slots
- Resumable Flush (#3497–#3499): shrink metric buffers and interleave
bounded flush chunks.
- Idle Pipeline Bypass (#3500–#3501): skip inactive transforms and
borrow client telemetry.
- `300m` CPU (#3502–#3507): cut encoder, codec and worker-pool hot-path
cost.
- Memory Admission (#3508–#3509): enforce opt-in configured memory
limits with idle reclaim and counted drops.
@tobz
tobz force-pushed the blt/1m-20-memory-admission branch from df55d5b to fee6f2c Compare December 4, 2026 15:28
dd-octo-sts Bot pushed a commit that referenced this pull request Dec 4, 2026
…ages indexed by u32 slots (#3496)

## Summary

The aggregator stores every series in `HashMap<Context,
AggregatedMetric>`. Each bucket costs 177 B, because `MetricValues`
reserves 104 B for its largest variant, a DDSketch. A gauge pays that
full size plus 48 B of inline metadata. On 1M RUM, the table holds 362.0
MiB to 379.6 MiB of live heap.

The table also doubles at 917,505 contexts, just below the 1M target.
That resize grows it from 192 MiB to 384 MiB and briefly holds 576 MiB
of old and new tables at once. A different hash map type cannot fix
this, because each bucket stays sized for the largest value.

This change moves values into per-kind 32 KiB typed pages. A thin index
stores a 4 B `u32` slot with 3 kind bits and 29 row bits, about 10 MiB
at 1M contexts. A gauge row takes 40 B, about 48 MiB at 1M contexts.
Rare multi-point rows and owned metadata spill to exact overflow stores.

Stripped `optimized-release` Tier 1 runs show peak memory falling by
497.9 MiB on 1M RUM, 506.5 MiB on all-unique and 482.3 MiB on mixed
churn. Cgroup CPU falls 20.8% on 1M RUM, 10.9% on all-unique and 28.6%
on mixed churn. Active `dsd_agg` live heap on 1M RUM falls from 362.0
MiB to 56.3 MiB.

## Change Type
- [ ] Bug fix
- [ ] New feature
- [ ] Non-functional
- [x] Performance

## How did you test this PR?

- `cargo check --locked --workspace --tests`
- `cargo test --locked -p saluki-components --lib
every_type_matches_metric_values_merge`
- Tier 1 runs use stripped `optimized-release` builds against base
`18f587f5f6` in cgroup v2, in default unbounded mode.
- 1M RUM holds 1,000,000 gauges that each carry one unique 51 B UUID tag
and 4 to 10 shared tags.
- All-unique holds 1,000,000 gauges that each carry eight unique tags of
32 B to 50 B.
- Mixed churn cycles gauges, counters, rates, sets and sketches between
200,000 and 1,000,000 active contexts.

## References

- Stacked on: #3495 (`blt/1m-06-inline-singleton-set`)
- Requires: inline `SetMembers`.
- Required by: resumable flush through `u32` slot cursors, and storage
growth estimates through dense rows.
- Release note:
`releasenotes/notes/use-dense-aggregate-storage-8f83ecb8c4eaac61.yaml`

### Series overview

- Context & Tag Density (#3490–#3492, #3511): pack contexts into one
allocation and drop unused cache overhead.
- **Dense Aggregation:** replace 177 B buckets with per-kind typed
pages.
  - #3495: store singleton Set values inline
- **Current (#3496):** store live aggregate metrics in dense typed pages
indexed by u32 slots
- Resumable Flush (#3497–#3499): shrink metric buffers and interleave
bounded flush chunks.
- Idle Pipeline Bypass (#3500–#3501): skip inactive transforms and
borrow client telemetry.
- `300m` CPU (#3502–#3507): cut encoder, codec and worker-pool hot-path
cost.
- Memory Admission (#3508–#3509): enforce opt-in configured memory
limits with idle reclaim and counted drops. 4f46054

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 Bot left a comment

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.

Bits Code Review: PASS

More details

The completed static review raised no reportable issue in admission, overflow handling, or drop accounting. Runtime memory ceilings and production behavior remain unvalidated.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit fee6f2c

gh-worker-dd-mergequeue-cf854d Bot pushed a commit that referenced this pull request Dec 4, 2026
## Summary

`EventsBuffer` stores every element as an `Event` enum, which sizes each slot for the largest event type at 344 B. A `Metric` needs only 160 B. A full 1,024-event metric batch therefore reserves 344 KiB to carry 160 KiB of metrics. A 1M-context flush emits about a thousand such batches, and many wait in channels at once.

This change stores metric-only batches as `Metric` values. The buffer promotes to mixed `Event` storage when a different event type arrives. It keeps event order when it promotes, filters or drains.

This change halves the payload of a full metric buffer. Its Tier 1 effect appears together with buffer recycling and resumable flush, which lower peak memory by 155.6 MiB on 1M RUM.

## Change Type
- [ ] Bug fix
- [ ] New feature
- [ ] Non-functional
- [x] Performance

## How did you test this PR?

- `cargo check --locked --workspace --tests`
- `cargo test --locked -p saluki-core --lib metric_backing_promotes_in_order_and_restarts_after_clear`

## References

- Stacked on: #3496 (`blt/1m-07-dense-aggregate-pages`)
- Requires: none.
- Required by: buffer recycling through typed `Metric` backing.
- Release note: `releasenotes/notes/typed-event-buffers-d3339735dc45e3a0.yaml`

### Series overview

- Context & Tag Density (#3490–#3492, #3511): pack contexts into one allocation and drop unused cache overhead.
- Dense Aggregation (#3495–#3496): replace 177 B buckets with per-kind typed pages.
- **Resumable Flush:** shrink metric buffers and interleave bounded flush chunks.
  - **Current (#3497):** add typed Metric storage to EventsBuffer
  - #3498: recycle drained EventsBuffer allocations
  - #3499: interleave bounded flush chunks with ingest
- Idle Pipeline Bypass (#3500–#3501): skip inactive transforms and borrow client telemetry.
- `300m` CPU (#3502–#3507): cut encoder, codec and worker-pool hot-path cost.
- Memory Admission (#3508–#3509): enforce opt-in configured memory limits with idle reclaim and counted drops.


Co-authored-by: brian.troutwine <brian.troutwine@datadoghq.com>

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 Bot left a comment

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.

Bits Code Review: PASS

More details

Refused updates preserve existing aggregate values, and pre-decode refusal telemetry deliberately counts wire lines rather than decoded samples. Runtime memory ceilings and flood behavior were not exercised.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit f34f5ea

gh-worker-dd-mergequeue-cf854d Bot pushed a commit that referenced this pull request Dec 4, 2026
## Summary

Each aggregate flush allocates fresh `EventsBuffer` storage for every output batch and frees it once the downstream drains it. A 1M-context flush emits about a thousand batches, so the allocator sees a burst of large requests every interval. The freed storage then returns to jemalloc only for the next flush to request it again.

This change returns drained storage to a recycler local to the producing component. The recycler keeps at most one empty allocation of each kind. `Dispatcher::event_buffer_manager` lets flush code request recycled buffers for its output.

This change has no separate Tier 1 measurement. Resumable flush and the idle pipeline bypass depend on it, and resumable flush carries the measured gain.

## Change Type
- [ ] Bug fix
- [ ] New feature
- [ ] Non-functional
- [x] Performance

## How did you test this PR?

- `cargo check --locked --workspace --tests`
- `cargo test --locked -p saluki-core --lib downstream_drain_recycles_backing_across_buffered_outputs`

## References

- Stacked on: #3497 (`blt/1m-08-typed-metric-buffer`)
- Requires: typed `Metric` storage in `EventsBuffer`.
- Required by: resumable flush and the idle pipeline bypass through `Dispatcher::event_buffer_manager`.
- Release note: `releasenotes/notes/recycle-event-buffers-1029b421ff51c533.yaml`

### Series overview

- Context & Tag Density (#3490–#3492, #3511): pack contexts into one allocation and drop unused cache overhead.
- Dense Aggregation (#3495–#3496): replace 177 B buckets with per-kind typed pages.
- **Resumable Flush:** shrink metric buffers and interleave bounded flush chunks.
  - #3497: add typed Metric storage to EventsBuffer
  - **Current (#3498):** recycle drained EventsBuffer allocations
  - #3499: interleave bounded flush chunks with ingest
- Idle Pipeline Bypass (#3500–#3501): skip inactive transforms and borrow client telemetry.
- `300m` CPU (#3502–#3507): cut encoder, codec and worker-pool hot-path cost.
- Memory Admission (#3508–#3509): enforce opt-in configured memory limits with idle reclaim and counted drops.


Co-authored-by: brian.troutwine <brian.troutwine@datadoghq.com>

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 Bot left a comment

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.

Bits Code Review: PASS

More details

Decoder refusals intentionally count wire lines and bytes before decoded event counts are known; aggregate refusals also update component drop telemetry. The code supports the PR discussion’s explanation, resolving the specialist’s sole candidate.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 32ca4e4

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 Bot left a comment

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.

Bits Code Review: PASS

More details

Three unavailable base-version blobs limited verification of the memory-admission changes. The available changes yielded no reportable findings.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 1651d3f

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 Bot left a comment

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.

Bits Code Review: PASS

More details

Conservative growth estimates are intentional to keep admission work bounded. Runtime memory ceilings and flood behavior remain unverified by execution or production data.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit b4722c5

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 Bot left a comment

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.

Bits Code Review: PASS

More details

Source review raised no reportable concern in the pre-decode and aggregate-growth admission paths. Runtime enforcement under memory pressure remains unvalidated.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 7bc512b

…gate

Move conservative storage growth estimation and guard-holding budgeted admission hooks (try_insert_with / try_insert_during_flush) into saluki-transform-kernels::aggregate while keeping saluki-transform-kernels free of ByteBudget dependencies. Keep saluki-components/src/transforms/aggregate/mod.rs as a thin ByteBudget wrapper that settles wire-line admission tickets once per unblocked outcome, and enforce opt-in admission in the DogStatsD source and framer.

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 Bot left a comment

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.

Bits Code Review: PASS

More details

The completed static review identified no actionable defect in admission, idle reclamation, or refusal accounting. Runtime enforcement of the memory ceiling remains unvalidated.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit df7b9ff

This branch has not been deployed

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

Labels

area/components Sources, transforms, and destinations. area/core Core functionality, event model, etc. source/dogstatsd DogStatsD source. transform/aggregate Aggregate transform.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant