Skip to content

Skip finding a Kafka record's produce time when time in queue is off - #13171

Open
dougqh wants to merge 3 commits into
masterfrom
dougqh/kafka-time-in-queue-check
Open

dougqh wants to merge 3 commits into
masterfrom
dougqh/kafka-time-in-queue-check

Conversation

@dougqh

@dougqh dougqh commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Kafka consumers (kafka-clients 0.11 and 3.8, and Kafka Streams) no longer look for a record's produce time when time in queue is off. Time in queue is off by default with legacy Kafka tracing. Before, every record scanned its headers for x_datadog_kafka_produced, and the result was then thrown away.

When time in queue is on, the produce time is read directly from the header's 8 bytes. Four copies of the ByteBuffer.allocate(8) / put / flip / getLong code become one Utils.readProducedTime in kafka-common. A value that isn't 8 bytes is still rejected, logged at debug and read as 0, as before.

Motivation

This prepares for matching Kafka header keys as bytes (see below). On its own, the measured change is small.

KafkaConsumeScenariosBenchmark, which gains a timeInQueue parameter here, with 500-record batches through TracingIterator (JDK 17, 3 forks, per record):

dataStreams timeInQueue before ns after ns before B after B
false false (default) 1637 ± 10 1682 ± 62 3418 ± 6 3420 ± 19
false true 2247 ± 18 2221 ± 57 3994 ± 17 3975 ± 33
true false 2038 ± 12 2076 ± 41 4668 ± 0.4 4660 ± 11
true true 2633 ± 77 2699 ± 32 5629 ± 294 5410 ± 17

The time differences are within noise. The machine was not quiet (load 6–8), and the run after the change was the noisier one. With time in queue on, about 19 B per record of ByteBuffer goes away; the DSM-on allocation difference is within the before run's error. The skipped scan is small here because the benchmark's headers have String keys, and on 3.x clients extraction has already decoded and cached every key.

Additional Notes

Next: matching Kafka header keys as bytes. Extraction will compare raw header key bytes against the keys our propagation styles, header tags, baggage and DSM read, and decode only the headers that match. In the Kafka consumer profile, decoding every header key and value cost about 370 B per record, and extraction was the largest tracer CPU bucket on the consumer thread.

Once extraction stops decoding keys, this produce-time scan, if it still ran first, would decode every key again on every record (lastHeader calls key() on each header). Checking the flag first removes that ahead of the change.

Producer side is unchanged. It still writes the header with ByteBuffer.allocate(8).putLong(...). A matching writeProducedTime could follow separately.

🤖 Generated with Claude Code

dougqh and others added 3 commits November 2, 2026 19:47
…uce time

Finding it scans the record's headers, which consumers did for every record
even with time in queue off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh dougqh added tag: performance Performance related changes type: refactoring inst: kafka Kafka instrumentation tag: ai generated Largely based on code generated by an AI or LLM labels Nov 3, 2026
@dougqh
dougqh marked this pull request as ready for review November 3, 2026 01:27
@dougqh
dougqh requested review from a team as code owners November 3, 2026 01:27
@dougqh
dougqh requested review from ygree and removed request for a team November 3, 2026 01:27
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T01:29:16.376711Z 2229ca6 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@datadog-datadog-prod-us1 datadog-datadog-prod-us1 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 supports that skipping produce-time lookup when time in queue is disabled preserves span creation. The shared decoder preserves big-endian timestamp decoding and malformed-header fallback behavior.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 2229ca6

@dd-octo-sts

dd-octo-sts Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 13.96 s 13.91 s [-0.2%; +0.9%] (no difference)
startup:insecure-bank:tracing:Agent 12.78 s 12.99 s [-2.2%; -1.0%] (significantly better)
startup:petclinic:appsec:Agent 17.75 s 17.55 s [+0.2%; +2.1%] (maybe worse)
startup:petclinic:iast:Agent 17.49 s 17.72 s [-2.1%; -0.5%] (maybe better)
startup:petclinic:profiling:Agent 17.43 s 17.23 s [+0.3%; +2.1%] (maybe worse)
startup:petclinic:sca:Agent 17.77 s 17.52 s [+0.5%; +2.4%] (maybe worse)
startup:petclinic:tracing:Agent 16.78 s 16.69 s [-0.6%; +1.7%] (no difference)

Commit: 2229ca66 · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@datadog-datadog-prod-us1

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 68.82% (+9.16%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 2229ca6 | Docs | Give us feedback!

@pr-commenter

pr-commenter Bot commented Nov 3, 2026

Copy link
Copy Markdown

Kafka / producer-benchmark

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch master dougqh/kafka-time-in-queue-check
git_commit_date 1793659518 1793669045
git_commit_sha 5b2fa2a 2229ca6
See matching parameters
Baseline Candidate
ci_job_date 1793670235 1793670235
ci_job_id 2204714004 2204714004
ci_pipeline_id 149635026 149635026
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
jdkVersion 11.0.31 11.0.31
jmhVersion 1.36 1.36
jvm /usr/lib/jvm/java-11-openjdk-amd64/bin/java /usr/lib/jvm/java-11-openjdk-amd64/bin/java
jvmArgs -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=15002 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=15002 -Dhttp.nonProxyHosts=localhost *.localhost
kernel_version Linux runner-zfyrx7zua-project-304-concurrent-0-c4sa37nm 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux Linux runner-zfyrx7zua-project-304-concurrent-0-c4sa37nm 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
vmName OpenJDK 64-Bit Server VM OpenJDK 64-Bit Server VM
vmVersion 11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu 11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu

Summary

Found 0 performance improvements and 1 performance regressions! Performance is the same for 2 metrics, 0 unstable metrics.

scenario Δ mean throughput
scenario:only-tracing-dsm-enabled-benchmarks/KafkaProduceBenchmark.benchProduce worse
[-5573.504op/s; -1290.377op/s] or [-4.337%; -1.004%]
See unchanged results
scenario Δ mean throughput
scenario:not-instrumented/KafkaProduceBenchmark.benchProduce same
scenario:only-tracing-dsm-disabled-benchmarks/KafkaProduceBenchmark.benchProduce unsure
[+444.701op/s; +5358.213op/s] or [+0.283%; +3.408%]

@pr-commenter

pr-commenter Bot commented Nov 3, 2026

Copy link
Copy Markdown

Kafka / consumer-benchmark

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch master dougqh/kafka-time-in-queue-check
git_commit_date 1793659518 1793669045
git_commit_sha 5b2fa2a 2229ca6
See matching parameters
Baseline Candidate
ci_job_date 1793670281 1793670281
ci_job_id 2204714005 2204714005
ci_pipeline_id 149635026 149635026
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
jdkVersion 11.0.31 11.0.31
jmhVersion 1.36 1.36
jvm /usr/lib/jvm/java-11-openjdk-amd64/bin/java /usr/lib/jvm/java-11-openjdk-amd64/bin/java
jvmArgs -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=15002 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=15002 -Dhttp.nonProxyHosts=localhost *.localhost
kernel_version Linux runner-zfyrx7zua-project-304-concurrent-0-ry7ysfm5 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux Linux runner-zfyrx7zua-project-304-concurrent-0-ry7ysfm5 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
vmName OpenJDK 64-Bit Server VM OpenJDK 64-Bit Server VM
vmVersion 11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu 11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu

Summary

Found 0 performance improvements and 0 performance regressions! Performance is the same for 3 metrics, 0 unstable metrics.

See unchanged results
scenario Δ mean throughput
scenario:not-instrumented/KafkaConsumerBenchmark.benchConsume same
scenario:only-tracing-dsm-disabled-benchmarks/KafkaConsumerBenchmark.benchConsume same
scenario:only-tracing-dsm-enabled-benchmarks/KafkaConsumerBenchmark.benchConsume same

@ygree ygree 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.

IDM approved

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

inst: kafka Kafka instrumentation tag: ai generated Largely based on code generated by an AI or LLM tag: performance Performance related changes type: refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants