Repository navigation
Size client stats cardinality tables to the values seen, not the budget - #13508
Conversation
Each cardinality handler allocated its current and prior tables up front at twice its budget. A peer-tag handler (limit 512) held four 1,024-slot arrays, about 16 KB, and the tracer builds one per peer tag the agent advertises (43 today, across all languages). Most never see a value in a Java service, so a quiet-phase heap dump of PetClinic showed the client stats aggregator retaining about 700 KB of empty tables. Tables are now null until a handler's first value, start at 8 slots and double up to the old size, so the budget and the 0.5 load factor are unchanged. Each reset sizes the next cycle's table for as many values as the completed cycle held, reusing the older table when it's already that size, and a cycle with no values releases the tables. The current and prior tables can now differ in size, so each is probed with its own mask. Lookups and budget behavior, including prior-cycle reuse, are unchanged. Both PropertyCardinalityHandler and TagCardinalityHandler get the same change, keeping their table code parallel. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eset Covers no table before the first value, growth that keeps every value findable, growth stopping at the budget, reset sizing the next table for the last cycle and releasing it after an empty cycle, and prior-cycle reuse when the current and prior tables differ in size. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ister Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…docs Both Javadocs still said the hash gives the initial probe slot in both tables, which stopped being true once the current and prior tables could differ in size. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both handlers carried the same minimum size, budget-sized maximum and 0.5-load-factor capacity math. The policy now lives in one place; the probe code stays parallel in each handler because their tables hold different key types. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 96f9924d1b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
Growing a property cardinality table can make previously accepted CharSequence values unfindable, causing repeated resource or operation names to be replaced by tracer_blocked_value.
🤖 Bits Code Review · Commit 96f9924
🟢 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. |
AlexeyKuznetsov-DD
left a comment
There was a problem hiding this comment.
Pre-approving. With couple of minor notes and questions and one minor issue found by Codex.
Lookups probed with the incoming value's own hash, while growth rehashed stored values by their String hash, so a StringBuilder or CharBuffer that doesn't hash by content couldn't be found after the table grew: it used up budget again or came back blocked. Hash every value by content. Also test CardinalityTables' sizing corner cases, rename freeSlot to findFreeSlot, update Config's cardinality-limit Javadocs for lazy tables, and explain the double reset in a test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
More details
Lazy table growth and cycle resets preserve cardinality limits and prior-cycle value reuse, including when table sizes differ. No actionable defects remained in the reviewed revision.
🤖 Bits Code Review · Commit 18cd193
|
Time and allocation before/after, to go with the retained-memory numbers above. Base
No cost on the app threads: throughput is no worse and allocation is flat. These benchmarks time the publish on the app thread, and the inbox stays full. Both sides drop on the same order, about 1.2–1.5B inbox-full drops per fork, with no aggregate drops. Dropping there is intended, since it keeps the app thread's cost down. But the scores are publish attempts, not metrics processed, so they say little about the handler work on the background thread. The retained-memory saving above covers that side. |
|
/merge |
|
View all feedbacks in Devflow UI.
It will be processed automatically as soon as GitHub reports it as mergeable. View in MergeQueue UI.
The expected merge time in
|
|
For the record, the third pair, |
What Does This Do
Client-side stats cardinality handlers now allocate their lookup tables only once they see a value, and size them to the number of values actually seen rather than to the full cardinality budget. A peer tag the service never emits no longer costs any table memory. A tag with a handful of values holds a small table instead of one sized for 512.
Motivation
Each handler allocated its current-cycle and prior-cycle tables up front at twice its budget. For peer tags (limit 512), that is four 1,024-slot arrays per handler, about 16 KB each. The tracer builds one handler per peer tag the agent advertises: 43 today, across all tracer languages.
A Java service sets only a few of those tags. About 19 of the 43 are never set by any Java instrumentation (for example
active_record.db.vendor,msmq.queue.pathandmongodb.db), and a typical service touches 5–15 of them. The values it does set are usually low-cardinality: a few database hosts, a few downstream services.A quiet-phase heap dump of PetClinic at a 128m heap showed the client stats aggregator retaining about 700 KB, almost all of it these mostly empty tables. That cost is permanent: it is paid on every JVM with client-side stats, whether or not the tags ever appear.
Additional Notes
Lazy and grow-to-fit. Tables are null until the first value, start at 8 slots and double up to the previous fixed size. The budget and the 0.5 load factor are unchanged, so a handler at its full budget ends up exactly where it was before.
Reset resizes. Each reset sizes the next cycle's table for as many values as the completed cycle held. It reuses the older table's array when that is already the right size, so steady traffic does not allocate. A cycle with no values releases the tables entirely.
Separate masks. The current and prior tables can now differ in size, so each is probed with its own mask. Reusing an encoded value from the prior cycle still works across sizes, and a test covers it.
Both handlers change.
PropertyCardinalityHandlerandTagCardinalityHandlerget the same change, which keeps their table code parallel. The property handlers (resource,service,span.kind, …) always see values, so for them only grow-to-fit matters, mostly for low-cardinality fields likespan.kindandhttp.method.Cost on the aggregator thread.
register()gains a null check and a growth branch. Growth is amortized: a high-cardinality field likeresourcereallocates a few times in its first cycle, and later cycles start at the right size.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:
ClientStatsAggregatorretainedSerialize client stats payloads into a chunked buffer #13097 and Let an idle trace writer release its payload buffer's surplus chunks #13507 don't touch the cardinality handlers, so the whole 697 KB → 7 KB drop comes from this PR.
🤖 Generated with Claude Code