Repository navigation
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
More details
Source inspection supports that idle trimming preserves completed and unfinished messages, and payload handoff restarts the two-second grace period. No actionable regressions were identified.
🤖 Bits Code Review · Commit b0026c8
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
Kafka / producer-benchmarkParameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 3 metrics, 0 unstable metrics. See unchanged results
|
Kafka / consumer-benchmarkParameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 3 metrics, 0 unstable metrics. See unchanged results
|
dcc3b8d to
6d6d2c7
Compare
b0026c8 to
09bbaa5
Compare
There was a problem hiding this comment.
More details
Idle trimming preserves buffers containing completed or unfinished data, and sending a payload restarts the two-second retention delay. The completed static review reported no actionable defects.
🤖 Bits Code Review · Commit 09bbaa5
09bbaa5 to
f8763de
Compare
There was a problem hiding this comment.
More details
The trim guard preserves completed and unfinished messages, and the dispatcher delays trimming until two seconds after the last payload. The completed static review found no actionable defects; no human PR discussion was present.
🤖 Bits Code Review · Commit f8763de
f8763de to
180e327
Compare
There was a problem hiding this comment.
More details
The idle-trim guards preserve completed and unfinished data, and payload handoffs restart the two-second delay. The completed static review identified no reportable defects.
🤖 Bits Code Review · Commit 180e327
180e327 to
94c486b
Compare
There was a problem hiding this comment.
A failed switch from v0.4 to v0.5 can leave several MiB of obsolete payload chunks pinned. Idle flushes cannot release them while the dispatcher has no packer.
🤖 Bits Code Review · Commit 94c486b
|
|
||
| private Recording batchTimer; | ||
| private RemoteMapper mapper; | ||
| private ChunkedStreamingBuffer buffer; |
There was a problem hiding this comment.
Release the old payload buffer before mapper rediscovery
When a writer switches from its v0.4 fallback to v0.5 after a large payload, selectMapper() clears packer but the new buffer field keeps the old chunks alive while the new mapper allocates its 2 MiB dictionary. If that allocation fails, the trace worker catches the error and idle flushes return early because packer is null. The old chunks remain pinned until a later mapper initialization succeeds, leaving less heap available for recovery. Clear buffer alongside packer before rediscovery.
React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it
What each reaction means
- 👍 Useful: correct, and you're fixing it or will.
- 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
- 😕 Unclear: you can't tell what it means or why it matters.
- 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.
🤖 Bits Code Review · Open Bits AI session
ChunkedBuffer only releases chunks in reset(), and the trace writer only resets when it sends a payload. A service that goes quiet after a burst kept the burst's chunks indefinitely: a quiet-phase heap dump of PetClinic at 128m showed the writer's buffer holding 6 chunks (1.5 MB) with no messages in it. ChunkedBuffer.trim() applies reset()'s retention to an idle buffer: it does nothing while the buffer holds any data, completed or unfinished, and otherwise halves the surplus, so repeated calls drain it to one chunk. PayloadDispatcherImpl.flush() calls it when there is nothing to send, so the periodic flush drains an idle writer within a few seconds (6 -> 3 -> 2 -> 1 chunks), down to the small first chunk. The trim sits in the dispatcher rather than in ChunkedStreamingBuffer .flush(): MsgPackWriter.flush() never reaches the buffer when it's empty, and its oversize-retry path already resets after an empty flush, which would have halved twice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Covers the halving sequence without writes in between, that completed and unfinished messages are left alone, that a rewound message counts as empty, and that trimming a fresh buffer allocates nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Trimming on every idle flush meant traffic that pauses for a second between large payloads freed chunks only to reallocate them for the next payload. The dispatcher now records when it last handed over a payload, whether the buffer filled or a flush sent it, and an idle flush trims only once that was at least 2 s ago. A quiet writer still drains to one chunk within a few seconds; bursts with shorter gaps keep their chunks. The delay is measured in time rather than in idle flushes so it doesn't shrink with dd.trace.flush.interval. The dispatcher takes a TimeSource for tests, and exposes its buffer's chunk count to them; that needs ChunkedBuffer.allocatedChunks() to be public. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The class Javadoc said resets only happen when payloads do, which is how the trace writer uses the buffer, not a property of ChunkedBuffer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Covers that an idle flush keeps the chunks until the delay has passed, that later idle flushes drain them to one, and that a newer payload restarts the delay. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
94c486b to
d775380
Compare
There was a problem hiding this comment.
A trace payload send that takes two seconds can use up the idle delay while it still holds the buffer. The next empty flush can release chunks just before a new burst needs them.
🤖 Bits Code Review · Commit d775380
| // or when the packer is flushed at a heartbeat | ||
| if (messageCount > 0) { | ||
| payloadStarted = false; | ||
| lastPayloadTicks = timeSource.getNanoTicks(); |
There was a problem hiding this comment.
Start the idle trim delay after the synchronous send
The dispatcher starts the two-second idle timer before calling sendSerializedTraces(), and the buffer stays in use until the synchronous send returns. If the send takes at least two seconds, the next empty flush can release chunks almost immediately. A burst that arrives just after that flush can have to reallocate chunks even though the buffer was available for reuse for less than two seconds. Start the delay when the send finishes so the buffer gets the full reuse window.
React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it
What each reaction means
- 👍 Useful: correct, and you're fixing it or will.
- 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
- 😕 Unclear: you can't tell what it means or why it matters.
- 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.
🤖 Bits Code Review · Open Bits AI session
What Does This Do
When the tracer has no traces to send, it now gradually releases the serialization buffer memory left over from the last burst of traffic. After a couple of seconds with nothing to send, the trace writer's payload buffer shrinks to a single small chunk instead of keeping the burst's chunks indefinitely.
Motivation
Steady-state heap dumps of PetClinic at a 128m heap show the trace writer's buffer holding chunks but no messages. Each dump was taken after 150 s of load, then idle until past 6.5 minutes of uptime, so past the agent's 5-minute type-pool clear:
That is about a quarter of the agent's whole steady-state heap cost over the same app without the agent (+13.4 MB with v0.4). It is retained for as long as the service stays quiet, which is exactly when it is easiest to give back. On small heaps, it competes with the application's live set.
ChunkedBufferalready releases surplus chunks gradually: eachreset()keeps what the completed messages used plus half of any earlier surplus. But the trace writer only resets when it sends a payload, so once traffic stops, nothing releases anything.Additional Notes
ChunkedBuffer.trim()appliesreset()'s retention to an idle buffer. It does nothing while the buffer holds any data, completed or unfinished. Otherwise it halves the surplus, so repeated calls drain it to one chunk.PayloadDispatcherImpl.flush()callstrim()when there is nothing to send and no payload has been handed over for at least 2 s. The time of the last payload resets whenever one is sent, from a full buffer or from a flush. After that, the periodic flush (1 s by default) drains an idle writer in a few calls: for the v0.4 case above, 13 → 7 → 4 → 2 → 1 chunks.dd.trace.flush.intervalis lowered.Why the dispatcher and not
ChunkedStreamingBuffer.flush():MsgPackWriter.flush()never calls the buffer when it is empty. Its oversize-retry path also already callsreset()after an empty flush, so trimming inside the buffer's flush would halve twice there.Stacked on Serialize client stats payloads into a chunked buffer #13097, which makes chunks start at 4 KiB and double. With both changes, an idle writer drains to a 4 KiB chunk rather than a 256 KiB one.
Not affected: the client stats and data streams writers. Each of their payloads is a single marked message that they flush or reset themselves.
Measured (before/after heap dumps):
Heap dumps of PetClinic at a 128m heap with the default v0.4 protocol. Each was taken at about 390 s of uptime, after 150 s of owners-query load, so past the agent's 5-minute type-pool clear. Retained sizes are MAT dominator-tree sizes, one dump per jar:
PayloadDispatcherImplretainedWithout the trim, the idle buffer holds whatever the last payload before going idle needed: 2.6 MB and 5.0 MB here, and 3.4 MB in an earlier dump. That is why the two "before" rows differ. With the trim, it drains to the single 4 KiB first chunk every time.
🤖 Generated with Claude Code