Skip to content

enhancement(metrics): reuse the zstd context and gate column recompression - #3504

Open
blt wants to merge 3 commits into
blt/1m-14-metrics-v3-symbol-idsfrom
blt/1m-15-metrics-zstd-reuse
Open

blt wants to merge 3 commits into
blt/1m-14-metrics-v3-symbol-idsfrom
blt/1m-15-metrics-zstd-reuse

Conversation

@blt

@blt blt commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The metrics encoder creates a new zstd compression context for each request. Each context allocates its window and match tables before it compresses a byte, and the encoder frees them after the request. The V3 encoder also recompresses every column separately to report per-column sizes, even when serializer profiling is off.

This change keeps one zstd context and its output storage per encoder. Each request still gets an independent frame that declares its exact uncompressed size. Per-column recompression runs only when serializer profiling is enabled, and telemetry otherwise reports uncompressed column sizes.

Stripped optimized-release Tier 1 runs measure this change together with V3 arena reuse. Cgroup CPU falls 46.6% on 1M RUM and 90.5% on all-unique. Peak memory falls 9.8 MiB on 1M RUM and 165.1 MiB on all-unique.

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-io --lib reusable_compressor_emits_one_sized_frame_per_input
  • 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.

References

Series overview

@github-actions github-actions 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.

AI review by Claude - workflow run

Patch is correct, with 0 blocking findings. The reused zstd context still writes one independent frame for each request, and the column recompression gate only changes telemetry. The main follow-ups: zstd::bulk::Compressor already does what the new compressor type does, and the profiling switch has no documentation.

Comment thread lib/saluki-io/src/compression.rs Resolved
Comment thread lib/saluki-io/Cargo.toml Resolved

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

Copy link
Copy Markdown

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 zstd path preserves request-owned compressed bytes while reusing encoder state. Static review found no reportable defect; runtime verification was blocked by an uncached piecemeal dependency.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 49e2a1c

@pr-commenter

pr-commenter Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Binary Size Analysis (Agent Data Plane)

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

✅ Binary size difference within threshold

Changes by Module
Module File Size Symbols
saluki_core::topology::interconnect +31.11 KiB 77
agent_data_plane::components::dogstatsd_prefix_filter -12.55 KiB 57
saluki_components::transforms::dd_trace_normalizer -11.84 KiB 29
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.77 KiB 32
hashbrown -3.63 KiB 307
_RNvXst_NtNtCs27Vx93FoQ6z_4core3str7patternReNtB5_7Pattern15is_contained_in.12223 +2.12 KiB 1
_RNvXst_NtNtCs27Vx93FoQ6z_4core3str7patternReNtB5_7Pattern15is_contained_in.13040 +2.12 KiB 1
_RNvXst_NtNtCs27Vx93FoQ6z_4core3str7patternReNtB5_7Pattern15is_contained_in.12189 -2.12 KiB 1
_RNvXst_NtNtCs27Vx93FoQ6z_4core3str7patternReNtB5_7Pattern15is_contained_in.13004 -2.12 KiB 1
_RNvXst_NtNtCs27Vx93FoQ6z_4core3str7patternReNtB5_7Pattern15is_contained_in.13356 +2.05 KiB 1
_RNvXst_NtNtCs27Vx93FoQ6z_4core3str7patternReNtB5_7Pattern15is_contained_in.13320 -2.05 KiB 1
agent_data_plane::cli::run +1.98 KiB 54
_ZN12serde_saphyr2de6events33attach_alias_locations_if_missing17hd49dea7029be1b37E.12356 +1.62 KiB 1
_ZN12serde_saphyr2de6events33attach_alias_locations_if_missing17hd49dea7029be1b37E.13152 +1.62 KiB 1
_ZN12serde_saphyr2de6events33attach_alias_locations_if_missing17hd49dea7029be1b37E.12322 -1.62 KiB 1
_ZN12serde_saphyr2de6events33attach_alias_locations_if_missing17hd49dea7029be1b37E.13116 -1.62 KiB 1
datadog_agent_metrics_v3::interner::Interner<K> -1.43 KiB 1
smallvec +1.39 KiB 120
Detailed Symbol Changes
    FILE SIZE        VM SIZE    
 --------------  -------------- 
  [NEW] +76.3Ki  [NEW] +76.3Ki    saluki_components::common::datadog::io::run_endpoint_io_loop::_{{closure}}::h8ca47fa7714ca2c6
  [NEW] +54.1Ki  [NEW] +54.1Ki    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.7Ki  [NEW] +49.7Ki    saluki_components::common::otlp::OtlpServerConfiguration::build::_{{closure}}::hc5f8e0fee108fc35
  [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.9Ki  [NEW] +45.9Ki    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.2Ki  [NEW] +44.2Ki    _<saluki_components::transforms::aggregate::Aggregate as saluki_core::components::transforms::Transform>::run::_{{closure}}::haa7c6fbf5c6fcd8d
  [NEW] +44.0Ki  [NEW] +44.0Ki    agent_data_plane::async_main::_{{closure}}::h87678173e2440e00
  +0.0% +3.24Ki  +0.0% +2.83Ki    [17695 Others]
  [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.0% +4.09Ki  +0.0% +3.69Ki    TOTAL

@pr-commenter

pr-commenter Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Regression Detector (Agent Data Plane)

Run ID: 2d19d936-cc2d-4dad-8eb5-70b900e784df
Baseline: 625e2290 · Comparison: bbcc416f · 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_medium memory utilization ⚪ +3.04 metrics profiles logs
quality_gates_rss_dsd_low memory utilization ⚪ +2.36 metrics profiles logs
quality_gates_rss_dsd_heavy memory utilization ⚪ +2.19 metrics profiles logs
quality_gates_rss_dsd_ultraheavy memory utilization ⚪ +0.75 metrics profiles logs
quality_gates_rss_idle memory utilization ⚪ -0.50 metrics profiles logs
Bounds Checks: ✅ Passed (5)
experiment check replicates observed links
quality_gates_rss_dsd_heavy memory_usage 10/10 ✅ 165.18MiB ≤ 250MiB metrics profiles logs
quality_gates_rss_dsd_low memory_usage 10/10 ✅ 44.05MiB ≤ 55MiB metrics profiles logs
quality_gates_rss_dsd_medium memory_usage 10/10 ✅ 64.71MiB ≤ 92MiB metrics profiles logs
quality_gates_rss_dsd_ultraheavy memory_usage 10/10 ✅ 264.88MiB ≤ 420MiB metrics profiles logs
quality_gates_rss_idle memory_usage 10/10 ✅ 30.23MiB ≤ 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.

@blt
blt force-pushed the blt/1m-15-metrics-zstd-reuse branch from 49e2a1c to a3a2e6b Compare November 27, 2026 00:01

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

Copy link
Copy Markdown

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

Compression buffer reuse preserves ownership of queued request bodies, and disabling column profiling still records uncompressed column sizes. The completed static review identified no actionable regression.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit a3a2e6b

@blt
blt force-pushed the blt/1m-15-metrics-zstd-reuse branch from a3a2e6b to 75d9b8b Compare November 27, 2026 00:22

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

Copy link
Copy Markdown

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

Releasing the zstd context between flushes addresses the low-traffic memory-retention concern documented in the human discussion. The completed static review identified no reportable defect.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 75d9b8b

@blt
blt force-pushed the blt/1m-15-metrics-zstd-reuse branch from 75d9b8b to abd4bca Compare November 27, 2026 01:01
@blt
blt removed this pull request from stack #3510 November 27, 2026 01:01
@blt
blt added this pull request to stack #3512 November 27, 2026 01:04

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

Copy link
Copy Markdown

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

Per-flush compressor reuse preserves independent request bodies and releases zstd tables between flushes. Column recompression is confined to explicit trace profiling; the static reviewer identified no actionable regression.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit abd4bca

@blt
blt force-pushed the blt/1m-15-metrics-zstd-reuse branch from abd4bca to bf33203 Compare November 27, 2026 01:11

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

Copy link
Copy Markdown

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

Compressed request bodies retain their bytes across buffer reuse, and uncompressed column telemetry remains active when profiling is disabled.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit bf33203

@blt
blt force-pushed the blt/1m-15-metrics-zstd-reuse branch from bf33203 to 2a38f92 Compare November 27, 2026 01:49
@blt
blt force-pushed the blt/1m-15-metrics-zstd-reuse branch from c39384a to b785dec Compare December 3, 2026 02:05

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

Copy link
Copy Markdown

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

Flush-scoped compression reuse releases zstd tables before idle periods. The completed static review identified no actionable regression; runtime behavior remains unverified.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit b785dec

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

Copy link
Copy Markdown

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

Each request owns its compressed output, so buffer reuse does not overwrite queued request bodies. Compression tables are released between V3 flushes.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit f7117b4

@blt
blt force-pushed the blt/1m-15-metrics-zstd-reuse branch from f7117b4 to fd97708 Compare December 3, 2026 19:00

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

Copy link
Copy Markdown

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

Compression state is released between flushes, avoiding persistent retention of zstd tables. The static reviewer reported no remaining defect; runtime tests were not run.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit fd97708

@blt
blt force-pushed the blt/1m-15-metrics-zstd-reuse branch from fd97708 to 73bdc8f Compare December 3, 2026 19:57

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

Copy link
Copy Markdown

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

Requests own their compressed bytes before the reusable output buffer is overwritten. Disabling column profiling preserves uncompressed-size telemetry.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 73bdc8f

@tobz
tobz force-pushed the blt/1m-15-metrics-zstd-reuse branch from 73bdc8f to 3286ab9 Compare December 4, 2026 15:28

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

Copy link
Copy Markdown

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

Request bodies retain independent compressed bytes across compressor reuse, and telemetry distinguishes unmeasured column sizes from measured zero sizes. The completed static review identified no reportable defect.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 3286ab9

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

Copy link
Copy Markdown

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

Each request owns its compressed bytes before buffer reuse, preventing subsequent payloads from overwriting queued requests. Uncompressed column telemetry remains recorded when trace profiling is disabled.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 7803cee

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

Copy link
Copy Markdown

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

Compression-buffer reuse preserves independently owned request bodies. Optional column sizes are handled consistently, so disabling profiling retains uncompressed telemetry without recording fictitious compressed measurements.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit d656c72

@blt
blt force-pushed the blt/1m-15-metrics-zstd-reuse branch from d656c72 to 495d921 Compare December 4, 2026 18:51

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

Copy link
Copy Markdown

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

Request bodies own their compressed bytes before buffers are reused, and per-column recompression is gated by the targeted trace filter. Runtime behavior remains unverified because a required Git dependency was unavailable offline.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 495d921

@blt
blt force-pushed the blt/1m-15-metrics-zstd-reuse branch from 495d921 to d479ffb Compare December 4, 2026 19:25

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

Copy link
Copy Markdown

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

Request-owned compressed bytes protect already-built payloads when the shared buffer is reused, while flush-scoped contexts release zstd tables between flushes. The completed static review returned no reportable findings.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit d479ffb

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

Copy link
Copy Markdown

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

Compression state is released between V3 flushes, and request bodies retain their compressed bytes before the workspace is reused. The completed static review identified no reportable correctness issue.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit f6e0ac2

blt added 3 commits December 4, 2026 21:28
…ssion

## Summary

The metrics encoder creates a new `zstd` compression context for each request. Each context allocates its window and match tables before it compresses a byte, and the encoder frees them after the request. The V3 encoder also recompresses every column separately to report per-column sizes, even when serializer profiling is off.

This change keeps one `zstd` context and its output storage per encoder. Each request still gets an independent frame that declares its exact uncompressed size. Per-column recompression runs only when serializer profiling is enabled, and telemetry otherwise reports uncompressed column sizes.

Stripped `optimized-release` Tier 1 runs measure this change together with V3 arena reuse. Cgroup CPU falls 46.6% on 1M RUM and 90.5% on all-unique. Peak memory falls 9.8 MiB on 1M RUM and 165.1 MiB on all-unique.

## 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-io --lib reusable_compressor_emits_one_sized_frame_per_input`
- 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.

## References

- Requires: V3 arena column ranges.
- Required by: none.
- Release note: `releasenotes/notes/reuse-zstd-context-32cecc80878e1dc2.yaml`

### Series overview

- Context & Tag Density: pack contexts into one allocation and drop unused cache overhead.
- Dense Aggregation: replace 177 B buckets with per-kind typed pages.
- Resumable Flush: shrink metric buffers and interleave bounded flush chunks.
- Idle Pipeline Bypass: skip inactive transforms and borrow client telemetry.
- **`300m` CPU:** cut encoder, codec and worker-pool hot-path cost.
  - PR TBD: reuse V3 dictionary arenas and frame payloads in one pass
  - PR TBD: map packed tag symbols directly to V3 payload IDs
  - **Current:** reuse the `zstd` context and gate per-column recompression
  - PR TBD: parse DogStatsD metrics in one pass and fast-path singleton scalars
  - PR TBD: classify and deduplicate metric tags on the stack
  - PR TBD: size the dedicated topology worker pool to available CPUs
- Memory Admission: enforce opt-in configured memory limits with idle reclaim and counted drops.

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

Copy link
Copy Markdown

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

Requests own their compressed bytes before the output buffer is reused, and the zstd context is released between flushes. Column telemetry explicitly represents unmeasured compressed sizes when profiling is disabled.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit bbcc416

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/io General I/O and networking. encoder/datadog-metrics Datadog Metrics encoder.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant