datadog-agent icon indicating copy to clipboard operation
datadog-agent copied to clipboard

pkg/trace/api: limit simultaneous otlp requests, do not drop payloads

Open knusbaum opened this issue 1 year ago • 7 comments

What does this PR do?

This commit causes the Trace Agent OTLP Receiver to not drop traces when the payload channel is full.

This commit also limits the number of simultaneous RPC requests, forwarding the backpressure from the pipeline to the client, and limiting our memory to O(MaxConnections * MaxStreams * MaxPayloadSize) in the receiver, with MaxStreams being 1.

Finally, it eliminates the trace buffer in the collector component exporter, preventing the core agent from buffering GiBs of traces under load.

All of these changes reduce trace drops while preventing uncontrolled memory growth.

Motivation

Previously, the OTLP Receiver in the Trace Agent dropped traces when the processor channel was full. This means that the receiver was dropping traces unnecessarily, and a better strategy is to block on the send. This will cause backpressure up through the otlp pipeline.

By default, a gRPC server will allow practically unlimited concurrent RPC requests, spawning a goroutine for each. The routine will read and deserialize the payload before calling the handler, which is now blocking.

This means that our memory usage is not reasonably bounded, since we could be holding hundreds of payloads in memory waiting to be processed. Limiting the number of concurrent RPC requests is required.

Finally, the backpressure goes to the core agent collector component. Here we need to remove the trace buffer to prevent GiBs of trace payloads from being buffered when it feels the backpressure from the Trace Agent.

Additional Notes

Possible Drawbacks / Trade-offs

Eliminating the trace buffer in the collector component could in theory result in higher trace loss in certain bursty scenarios. In practice, we don't see such scenarios and so this is a fair trade-off.

Describe how to test/QA your changes

We will use the new OTel load testing environment to exercise this change.

We should compare:

throughput (are traces being dropped) memory usage (is memory usage better or worse) See @knusbaum for details about more specifics regarding infrastructure.

knusbaum avatar Feb 22 '24 20:02 knusbaum

Bloop Bleep... Dogbot Here

Regression Detector Results

Run ID: c0508a00-2993-4501-bd7c-688aaba42bf2 Baseline: a82a8f97aa98a0654fa09dfd295c5f01a3162423 Comparison: 31698d2d001c3fc82a172e5b523c563d59116708 Total CPUs: 7

Performance changes are noted in the perf column of each table:

  • ✅ = significantly better comparison variant performance
  • ❌ = significantly worse comparison variant performance
  • ➖ = no significant change in performance

Experiments with missing or malformed data

  • basic_py_check

Usually, this warning means that there is no usable optimization goal data for that experiment, which could be a result of misconfiguration.

No significant changes in experiment optimization goals

Confidence level: 90.00% Effect size tolerance: |Δ mean %| ≥ 5.00%

There were no significant changes in experiment optimization goals at this confidence level and effect size tolerance.

Experiments ignored for regressions

Regressions in experiments with settings containing erratic: true are ignored.

perf experiment goal Δ mean % Δ mean % CI
file_to_blackhole % cpu utilization -1.98 [-8.47, +4.52]

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI
otel_to_otel_logs ingress throughput +1.38 [+0.76, +2.00]
process_agent_real_time_mode memory utilization +0.33 [+0.29, +0.37]
uds_dogstatsd_to_api_cpu % cpu utilization +0.27 [-1.19, +1.72]
idle memory utilization +0.07 [+0.04, +0.10]
tcp_syslog_to_blackhole ingress throughput +0.06 [+0.00, +0.12]
file_tree memory utilization +0.03 [-0.06, +0.12]
trace_agent_json ingress throughput +0.02 [-0.02, +0.06]
process_agent_standard_check memory utilization +0.02 [-0.02, +0.06]
tcp_dd_logs_filter_exclude ingress throughput +0.00 [-0.00, +0.00]
trace_agent_msgpack ingress throughput +0.00 [-0.00, +0.00]
uds_dogstatsd_to_api ingress throughput +0.00 [-0.00, +0.00]
process_agent_standard_check_with_stats memory utilization -0.40 [-0.43, -0.37]
file_to_blackhole % cpu utilization -1.98 [-8.47, +4.52]

Explanation

A regression test is an A/B test of target performance in a repeatable rig, where "performance" is measured as "comparison variant minus baseline variant" for an optimization goal (e.g., ingress throughput). Due to intrinsic variability in measuring that goal, we can only estimate its mean value for each experiment; we report uncertainty in that value as a 90.00% confidence interval denoted "Δ mean % CI".

For each experiment, we decide whether a change in performance is a "regression" -- a change worth investigating further -- if all of the following criteria are true:

  1. Its estimated |Δ mean %| ≥ 5.00%, indicating the change is big enough to merit a closer look.

  2. Its 90.00% confidence interval "Δ mean % CI" does not contain zero, indicating that if our statistical model is accurate, there is at least a 90.00% chance there is a difference in performance between baseline and comparison variants.

  3. Its configuration does not mark it "erratic".

pr-commenter[bot] avatar Feb 22 '24 21:02 pr-commenter[bot]

Re: regression detector, This is a false positive, as we're touching nothing remotely related to UDS or dogstatsd.

knusbaum avatar Feb 23 '24 18:02 knusbaum

/merge

dineshg13 avatar Feb 25 '24 23:02 dineshg13

:steam_locomotive: MergeQueue

Pull request added to the queue.

This build is going to start soon! (estimated merge in less than 49m)

Use /merge -c to cancel this operation!

dd-devflow[bot] avatar Feb 25 '24 23:02 dd-devflow[bot]

:x: MergeQueue

This PR is rejected because it was updated

If you need support, contact us on Slack #ci-interfaces with those details!

dd-devflow[bot] avatar Feb 25 '24 23:02 dd-devflow[bot]

/merge

dineshg13 avatar Feb 26 '24 00:02 dineshg13

:steam_locomotive: MergeQueue

Pull request added to the queue.

This build is going to start soon! (estimated merge in less than 49m)

Use /merge -c to cancel this operation!

dd-devflow[bot] avatar Feb 26 '24 00:02 dd-devflow[bot]