Skip to content

perf(datastreams): reduce DSM produce/consume overhead - #21963

Draft
labbati wants to merge 8 commits into
mainfrom
labbati/dsm2-794-python-dsm-performance-overhead
Draft

labbati wants to merge 8 commits into
mainfrom
labbati/dsm2-794-python-dsm-performance-overhead

Conversation

@labbati

@labbati labbati commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Description

Reduces the CPU cost of Data Streams Monitoring on the produce/consume path with two changes:

  • Pathway hash cache (perf(datastreams): cache pathway hash computation + test and cache-size follow-ups): memoizes the pathway hash with a bounded LRU cache (256 entries); a steady-state pathway otherwise recomputes the same hash for every message.
  • Native hashing and pathway encoding (perf(datastreams): compute fnv1_64 natively, perf(datastreams): encode and decode pathway context natively): moves FNV-1 64 hashing and base64 pathway context encode/decode to the Rust extension. Inputs the native path does not handle (lenient base64, malformed contexts, out-of-range timestamps) fall back to the Python implementation, so output and error handling are unchanged.
  • Release note.

Benchmark

Speedlab CI, each change measured alone on main (8918a5a). DSM share = (apm+dsm − apm-only) / (apm-only − baseline).

Variant DSM added DSM share of duration
control (main) 175.0 ms 157.7%
hash cache 86.3 ms 76.7%
native fnv1_64 + encode/decode 71.1 ms 61.9%

Combined numbers to follow.

Testing

  • tests/datastreams: native encode/decode is checked byte for byte against the pure-Python reference on random inputs, plus fallback outside the native range, malformed contexts, and hash cache hit/miss behavior.
  • tests/contrib/kafka: full suite passes locally.
  • Rust unit tests in src/native/datastreams.rs.

Risks

Low. The hash cache is bounded (256 entries). The native paths fall back to Python for any input they do not handle.

Additional Notes

None.

@linear-code

linear-code Bot commented Nov 20, 2026

Copy link
Copy Markdown

DSM2-794

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codeowners resolved as

Resolved from the full PR diff against main using the target branch CODEOWNERS file.
CODEOWNERS team requests not listed below are not required by the current file set.

ddtrace/internal/datastreams/encoding.py                                @DataDog/data-streams-monitoring
ddtrace/internal/datastreams/processor.py                               @DataDog/data-streams-monitoring
ddtrace/internal/native/__init__.py                                     @DataDog/apm-core-python
ddtrace/internal/native/_native.pyi                                     @DataDog/apm-core-python
ddtrace/internal/utils/fnv.py                                           @DataDog/apm-core-python
mypy.ini                                                                @DataDog/apm-python-guild @DataDog/apm-core-python
releasenotes/notes/dsm-reduce-produce-consume-overhead-fe9d409993173e90.yaml  @DataDog/apm-python
src/native/datastreams.rs                                               @DataDog/apm-core-python
src/native/lib.rs                                                       @DataDog/apm-core-python
tests/datastreams/test_encoding.py                                      @DataDog/data-streams-monitoring
tests/datastreams/test_fnv.py                                           @DataDog/data-streams-monitoring
tests/datastreams/test_processor.py                                     @DataDog/data-streams-monitoring

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

There are 22 dependency direction violations that already exist on the base branch and have not been changed by this PR.

Show existing violations (showing 5 of 22 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=103)
ddtrace.llmobs._integrations.base -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=101)
ddtrace.llmobs._integrations.bedrock_agents -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=101)
ddtrace.internal.span_bus -×-> ddtrace._trace.span  (internal-core -> product:tracing, score=35)
ddtrace.llmobs._llmobs -×-> ddtrace._trace.span  (product:llmobs -> product:tracing, score=33)

To see all violations, download the layers-base.json and layers-pr.json artifacts from this CI job and run:

uv run --script scripts/import-analysis/layers.py compare layers-base.json layers-pr.json

@pr-commenter

pr-commenter Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-11-23 18:24:15

Comparing candidate commit 2fe7ace in PR branch labbati/dsm2-794-python-dsm-performance-overhead with baseline commit 1481176 in branch main.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 635 metrics, 10 unstable metrics, 1 flaky benchmarks without significant changes.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:coreapiscenario-context_with_data_listeners

  • unstable execution_time [-576.513ns; +855.775ns] or [-5.431%; +8.062%]

scenario:coreapiscenario-core_dispatch_1_listener

  • unstable execution_time [-35.307ns; +41.017ns] or [-5.498%; +6.387%]

scenario:coreapiscenario-core_dispatch_50_listeners

  • unstable execution_time [-1698.946ns; +1995.008ns] or [-8.579%; +10.074%]

scenario:coreapiscenario-core_dispatch_exception_listeners

  • unstable execution_time [-1440.630ns; +2120.291ns] or [-7.490%; +11.023%]

scenario:coreapiscenario-core_dispatch_listeners

  • unstable execution_time [-288.156ns; +440.268ns] or [-6.834%; +10.442%]

scenario:coreapiscenario-core_dispatch_no_args_listeners

  • unstable execution_time [-164.381ns; +279.548ns] or [-6.249%; +10.627%]

scenario:coreapiscenario-core_dispatch_with_results_1_listener

  • unstable execution_time [-161.077ns; +24.084ns] or [-11.689%; +1.748%]

scenario:coreapiscenario-core_dispatch_with_results_50_listeners

  • unstable execution_time [-4541.500ns; +4586.055ns] or [-9.321%; +9.413%]

scenario:coreapiscenario-core_dispatch_with_results_listeners

  • unstable execution_time [-948.864ns; +907.571ns] or [-9.193%; +8.793%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • unstable execution_time [-68.777µs; +44.103µs] or [-11.555%; +7.410%]

Known flaky benchmarks

These benchmarks are marked as flaky and will not trigger a failure. Modify FLAKY_BENCHMARKS_REGEX to control which benchmarks are marked as flaky.

Known flaky benchmarks without significant changes:

  • scenario:packagespackageforrootmodulemapping-cache_off

@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Pipelines  Tests

❌ Errors

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 1 Pipeline job failed

DataDog/apm-reliability/dd-trace-py | llmobs/vllm 1/2 — 🔄 Retry may pass, looks flaky

View more details · View in GitLab

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 2fe7ace | Docs | View more details | Give us feedback!

Move the FNV-1 64-bit hash used for pathway, schema and process-tag hashes
to the Rust extension. Output is identical to the previous pure-Python
implementation.
Encode and decode the base64 pathway context in the Rust extension. Inputs
the native path does not handle (lenient base64, malformed contexts,
out-of-range timestamps) fall back to the Python implementation, so output
and error handling are unchanged.
@labbati
labbati force-pushed the labbati/dsm2-794-python-dsm-performance-overhead branch from a16e8de to 1a4263c Compare November 20, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant