-
Notifications
You must be signed in to change notification settings - Fork 337
Update client-side stats to use light weight Hashtable #11382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dougqh
wants to merge
142
commits into
master
Choose a base branch
from
dougqh/optimize-metric-key
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
142 commits
Select commit
Hold shift + click to select a range
bc42093
Trim per-span work on metrics aggregator publish path
dougqh 808d63d
Add SpanKindFilter and CoreSpan.isKind for bitmask-based kind checks
dougqh 6aa620e
Use SpanKindFilter in ConflatingMetricsAggregator
dougqh a02d0a9
Add DDSpan-based variant of ConflatingMetricsAggregator JMH benchmark
dougqh ed38f18
Tighten SpanKindFilter encapsulation
dougqh 034afc0
Defer MetricKey construction and cache lookups to the aggregator thread
dougqh 3a056b3
Report aggregator inbox-full drops via health metrics
dougqh 3355865
Merge branch 'master' into dougqh/conflating-metrics-producer-wins
dougqh 950499c
Merge branch 'dougqh/conflating-metrics-producer-wins' into dougqh/co…
dougqh 0294058
Add Hashtable and LongHashingUtils to datadog.trace.util
dougqh f751ab4
Add AggregateTable + AggregateEntry backed by Hashtable
dougqh f1b030a
Swap LRUCache for AggregateTable in Aggregator + route disable() clear
dougqh 3738c85
Eliminate MetricKey: inline its fields onto AggregateEntry
dougqh 46a9055
Add unit tests for Hashtable and LongHashingUtils
dougqh 031dc89
Apply spotless formatting to Hashtable and LongHashingUtils
dougqh f9e63b9
Add JMH benchmarks for Hashtable.D1 and D2
dougqh a534e4f
Add benchmark results to HashtableBenchmark header
dougqh ba66a36
Address review feedback on Hashtable
dougqh 3108941
Fix dropped argument in HashingUtils 5-arg Object hash
dougqh 1415f12
Address review feedback on Hashtable
dougqh b7cee2f
Drop reflection in iterator tests via package-private D1.buckets
dougqh 8414960
Resize previousCounts for inbox-full health metric
dougqh 553ffb8
Fold AggregateMetric into AggregateEntry
dougqh 07ed635
Avoid capturing lambda in Aggregator.report
dougqh df58ad7
Add context-passing forEach to Hashtable.D1 and D2
dougqh 9c6e95c
Move forEach loop body to Support helper
dougqh 7ab47f7
Merge branch 'dougqh/util-hashtable' into dougqh/optimize-metric-key
dougqh 590ab4a
Delegate AggregateTable.forEach to Support.forEach
dougqh 447ea33
Move bucket-head cast to Support.bucket helper
dougqh 46f147a
Merge branch 'dougqh/util-hashtable' into dougqh/optimize-metric-key
dougqh dd5e13f
Use Support.bucket and type chain walks as AggregateEntry
dougqh df7f98f
Drop d1_/d2_ prefix from per-table benchmark methods
dougqh e6ecc16
Add Hashtable.Support helpers: MAX_RATIO, insertHeadEntry, MutatingTa…
dougqh a409d5d
Merge branch 'dougqh/util-hashtable' into dougqh/optimize-metric-key
dougqh 96b40b8
Simplify AggregateTable via new Hashtable.Support helpers
dougqh 55ca204
Swap MAX_RATIO numerator/denominator pair for a single float + scaled…
dougqh 7b9eccd
Merge branch 'dougqh/util-hashtable' into dougqh/optimize-metric-key
dougqh 192de0c
Address second-round review on AggregateTable / Aggregator
dougqh 4bac439
Tighten Hashtable docs + rename MAX_CAPACITY to MAX_BUCKETS
dougqh de289a0
Dedupe chain-head splice in D1/D2 via keyHash insertHeadEntry overload
dougqh 2dd65ed
Tighten Entry.next encapsulation; doc hasNext; add D1/D2 getOrCreate
dougqh cc8d98a
Merge branch 'dougqh/util-hashtable' into dougqh/optimize-metric-key
dougqh 6a9063b
Use keyHash insertHeadEntry overload in AggregateTable.findOrInsert
dougqh dbb1702
Replace // nullable comments with @Nullable annotations on AggregateE…
dougqh 545e74c
Drop redundant load-factor comment from AggregateTable ctor
dougqh 9983a59
Import java.util.Objects in AggregateEntry instead of fully qualifying
dougqh d2e4477
Document evictOneStale cost and disable() best-effort offer
dougqh 24969db
Skip SpanSnapshot allocation when the inbox is already at capacity
dougqh 66ec7f6
Hashtable: add missing braces and detach removed/replaced entries
dougqh be823ab
Merge branch 'dougqh/util-hashtable' into dougqh/optimize-metric-key
dougqh 10956b2
Add Hashtable and LongHashingUtils to datadog.trace.util
dougqh 035dc09
Add unit tests for Hashtable and LongHashingUtils
dougqh 7728b60
Apply spotless formatting to Hashtable and LongHashingUtils
dougqh 8cd2d86
Add JMH benchmarks for Hashtable.D1 and D2
dougqh c689ef9
Add benchmark results to HashtableBenchmark header
dougqh 75790eb
Address review feedback on Hashtable
dougqh 6056ff7
Fix dropped argument in HashingUtils 5-arg Object hash
dougqh da55021
Address review feedback on Hashtable
dougqh 8b8b088
Drop reflection in iterator tests via package-private D1.buckets
dougqh 0fde7cd
Add context-passing forEach to Hashtable.D1 and D2
dougqh 6d6c2e0
Move forEach loop body to Support helper
dougqh 268de2b
Move bucket-head cast to Support.bucket helper
dougqh 93813b9
Drop d1_/d2_ prefix from per-table benchmark methods
dougqh 11a58bf
Add Hashtable.Support helpers: MAX_RATIO, insertHeadEntry, MutatingTa…
dougqh 8f1828d
Swap MAX_RATIO numerator/denominator pair for a single float + scaled…
dougqh c0d3e26
Tighten Hashtable docs + rename MAX_CAPACITY to MAX_BUCKETS
dougqh a0978ba
Dedupe chain-head splice in D1/D2 via keyHash insertHeadEntry overload
dougqh e604a8f
Tighten Entry.next encapsulation; doc hasNext; add D1/D2 getOrCreate
dougqh e2642cd
Hashtable: add missing braces and detach removed/replaced entries
dougqh 585ca56
Rename LongHashingUtils.hashCodeX(Object) to hash(Object) for API con…
dougqh aab5b3b
Merge remote-tracking branch 'origin/master' into dougqh/optimize-met…
dougqh 88f169f
Merge branch 'dougqh/util-hashtable' into dougqh/optimize-metric-key
dougqh 795ba76
Merge remote-tracking branch 'origin/master' into dougqh/conflating-m…
dougqh e455801
Introduce slim PeerTagSchema; capture peer-tag values not pairs
dougqh c2ff012
Merge branch 'dougqh/conflating-metrics-background-work' into dougqh/…
dougqh e766fd3
Address PR #11381 review (round 2)
dougqh 8cfa4a5
Cover inbox-full fast-path in ConflatingMetricsAggregator.publish
dougqh 3644470
Reconcile PeerTagSchema once per reporting cycle on the aggregator th…
dougqh 1d1ba4d
Merge branch 'dougqh/conflating-metrics-background-work' into dougqh/…
dougqh e7d0b42
Add bootstrap + reconcile coverage for PeerTagSchema
dougqh 3d4f380
Merge branch 'dougqh/conflating-metrics-background-work' into dougqh/…
dougqh 9391c48
Use writer.finishBucket() count in bootstrap test for cascade compati…
dougqh ba3225c
Use writer.finishBucket() count in bootstrap test for cascade compati…
dougqh ec857b2
Merge branch 'master' into dougqh/conflating-metrics-background-work
dougqh ba0d390
Merge branch 'dougqh/conflating-metrics-background-work' into dougqh/…
dougqh 0b86066
Preserve TRACER_METRICS_MAX_PENDING semantic + drop stale imports
dougqh f71384e
Merge branch 'dougqh/conflating-metrics-background-work' into dougqh/…
dougqh 5c78dbb
Add AdversarialMetricsBenchmark for capacity-bound stress testing
dougqh 471f8f7
Merge branch 'dougqh/conflating-metrics-background-work' into dougqh/…
dougqh 70c20ef
Trim AdversarialMetricsBenchmark counters and clarify printout
dougqh 7a074e0
Merge branch 'dougqh/conflating-metrics-background-work' into dougqh/…
dougqh 68848ad
Close PeerTagSchema reconcile race + cover the swap branch
dougqh 3fa7ac7
Merge branch 'dougqh/conflating-metrics-background-work' into dougqh/…
dougqh df3b31d
Adapt reconcileSwapsSchemaWhenTagSetChanges to AggregateEntry shape
dougqh 2ea61c5
Clarify materializePeerTags hit-counting loop
dougqh 8ec956d
Merge branch 'dougqh/conflating-metrics-background-work' into dougqh/…
dougqh a606692
Fix MetricsIntegrationTest entry recording call site
dougqh 913e7d7
Make ConflatingMetricAggregatorTest counter checks actually verify
dougqh 2dcea9a
Drop dead recordDurations(int, AtomicLongArray) batch API
dougqh 50b06e5
Warn about colon split in AggregateEntry.of test factory
dougqh b0f21bf
Add coverage for disable() -> ClearSignal threading path
dougqh 5a4685f
Drop unused Tags imports flagged by codenarc
dougqh 200028d
Merge branch 'dougqh/conflating-metrics-background-work' into dougqh/…
dougqh a1863db
Update dd-trace-core/src/main/java/datadog/trace/common/metrics/PeerT…
dougqh a75bc4a
Address sarahchen6's review pass
dougqh 4871892
Clamp TRACER_METRICS_MAX_PENDING instead of throwing on overflow
dougqh 5f73c2d
Fix duplicate-entry bug for null-fielded SpanSnapshots
dougqh 9dddf0a
Clear dirty flag in ClearSignal handler
dougqh 2c8ad26
Merge branch 'master' into dougqh/conflating-metrics-background-work
dougqh 80778c4
Drop conditional null-skip from peer-tag hashing
dougqh 21e7545
Delete dead Aggregator.clearAggregates()
dougqh 877d95c
Cursor-resume eviction in AggregateTable via half-open MutatingTableI…
dougqh e2f2585
Move AggregateEntry.of() test factory out of production class
dougqh 2536aa2
Fix AggregateEntry equals/hashCode contract violation
dougqh c0449a3
Don't trample queued STOP in ClearSignal handler
dougqh be13431
Implement PeerTagSchema.equals symmetric with hashCode
dougqh d174938
Route service and spanKind through canonicalize for null-safety
dougqh 641b5ef
Suppress forbiddenApis for tearDown's System.err diagnostics
dougqh 7eedb25
Merge branch 'master' into dougqh/conflating-metrics-background-work
dougqh ce5b38b
Use DDAgentFeaturesDiscovery.state() hash for PeerTagSchema reconcile
dougqh 2eaa58f
Convert TRACER_METRICS_MAX_PENDING rationale to /* */ block comment
dougqh cd56981
Merge remote-tracking branch 'origin/dougqh/conflating-metrics-backgr…
dougqh d1df95e
Add cardinality-isolation companions to AdversarialMetricsBenchmark
dougqh 4a4b72e
Merge remote-tracking branch 'origin/dougqh/conflating-metrics-backgr…
dougqh 133d3c1
Consolidate contentEquals; remove redundant stringContentEquals
dougqh 2ae738b
Rename AggregateEntries -> AggregateEntryFixtures
dougqh f68ad4f
Tidy PR-iteration history out of test comments
dougqh 6fdc2de
Merge remote-tracking branch 'origin/master' into dougqh/optimize-met…
dougqh 3f32dfd
Merge remote-tracking branch 'origin/master' into dougqh/optimize-met…
dougqh 2d1536c
Make AggregateEntry.ERROR_TAG / TOP_LEVEL_TAG package-private
dougqh 5bf4d90
Move AggregateEntry equality contract to test-only helper
dougqh a67ac23
Consolidate AggregateEntryFixtures into AggregateEntryTestUtils
dougqh 1eb6826
Document deliberate cohesion + single-writer invariant on AggregateEntry
dougqh d5065f2
Avoid recomputing keyHash on AggregateTable miss
dougqh e6f2399
Document AggregateEntry.clear key-field persistence + SignalItem sing…
dougqh dcb1898
Drop useless @SuppressFBWarnings on AggregateEntry
dougqh a06c2a8
Update stale Javadoc on AggregateEntry's no-equals contract
dougqh acf2ffa
Tighten AggregateEntry / PeerTagSchema surface area
dougqh ccb4a4b
Tighten AggregateEntry surface — drop one-line factory, doc the conve…
dougqh d0c0be8
Merge branch 'master' into dougqh/optimize-metric-key
dougqh 4af16c1
Drop unused UTF8BytesString import in MetricsIntegrationTest
dougqh dcd3407
Merge branch 'master' into dougqh/optimize-metric-key
dougqh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
433 changes: 433 additions & 0 deletions
433
dd-trace-core/src/main/java/datadog/trace/common/metrics/AggregateEntry.java
Large diffs are not rendered by default.
Oops, something went wrong.
103 changes: 0 additions & 103 deletions
103
dd-trace-core/src/main/java/datadog/trace/common/metrics/AggregateMetric.java
This file was deleted.
Oops, something went wrong.
140 changes: 140 additions & 0 deletions
140
dd-trace-core/src/main/java/datadog/trace/common/metrics/AggregateTable.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| package datadog.trace.common.metrics; | ||
|
|
||
| import datadog.trace.util.Hashtable; | ||
| import datadog.trace.util.Hashtable.MutatingTableIterator; | ||
| import datadog.trace.util.Hashtable.Support; | ||
| import java.util.function.BiConsumer; | ||
| import java.util.function.Consumer; | ||
|
|
||
| /** | ||
| * Consumer-side {@link AggregateEntry} store, keyed on the raw fields of a {@link SpanSnapshot}. | ||
| * | ||
| * <p>Replaces the prior {@code LRUCache<MetricKey, AggregateMetric>}. The win is on the | ||
| * steady-state hit path: a snapshot lookup is a 64-bit hash compute + bucket walk + field-wise | ||
| * {@code matches}, with no per-snapshot {@link AggregateEntry} allocation and no UTF8 cache | ||
| * lookups. The UTF8-encoded forms (formerly held on {@code MetricKey}) and the mutable counters | ||
| * (formerly held on {@code AggregateMetric}) both live on the {@link AggregateEntry} now, built | ||
| * once per unique key at insert time. | ||
| * | ||
| * <p><b>Not thread-safe.</b> The aggregator thread is the sole writer of both this table and its | ||
| * contained {@link AggregateEntry} state. Any cross-thread request that needs to mutate -- e.g. | ||
| * {@link ConflatingMetricsAggregator#disable()} -- must funnel onto the aggregator thread via the | ||
| * inbox (see the {@code ClearSignal} routing in {@link Aggregator}). The invariant is convention- | ||
| * enforced; nothing here checks the calling thread at runtime, so a wrong-thread call would corrupt | ||
| * bucket chains silently. | ||
| */ | ||
| final class AggregateTable { | ||
|
|
||
| private final Hashtable.Entry[] buckets; | ||
| private final int maxAggregates; | ||
| private int size; | ||
|
|
||
| /** | ||
| * Bucket index where the last {@link #evictOneStale} successfully removed an entry. The next call | ||
| * resumes from this bucket so a fast-evicting workload doesn't repeatedly re-walk the same hot | ||
| * entries clustered near bucket 0. Reset to {@code 0} by {@link #clear}. | ||
| */ | ||
| private int evictCursor; | ||
|
|
||
| AggregateTable(int maxAggregates) { | ||
| this.buckets = Support.create(maxAggregates, Support.MAX_RATIO); | ||
| this.maxAggregates = maxAggregates; | ||
| } | ||
|
|
||
| int size() { | ||
| return size; | ||
| } | ||
|
|
||
| boolean isEmpty() { | ||
| return size == 0; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the {@link AggregateEntry} to update for {@code snapshot}, lazily creating one on miss. | ||
| * Returns {@code null} when the table is at capacity and no stale entry can be evicted -- the | ||
| * caller should drop the data point in that case. | ||
| */ | ||
| AggregateEntry findOrInsert(SpanSnapshot snapshot) { | ||
| long keyHash = AggregateEntry.hashOf(snapshot); | ||
| for (AggregateEntry candidate = Support.bucket(buckets, keyHash); | ||
| candidate != null; | ||
| candidate = candidate.next()) { | ||
| if (candidate.matches(keyHash, snapshot)) { | ||
| return candidate; | ||
| } | ||
| } | ||
| if (size >= maxAggregates && !evictOneStale()) { | ||
| return null; | ||
| } | ||
| AggregateEntry entry = new AggregateEntry(snapshot, keyHash); | ||
| Support.insertHeadEntry(buckets, keyHash, entry); | ||
| size++; | ||
| return entry; | ||
| } | ||
|
|
||
| /** | ||
| * Unlinks the first entry whose {@code getHitCount() == 0}, resuming the scan from {@link | ||
| * #evictCursor} so back-to-back evictions amortize to O(1) per call. Worst case for a single call | ||
| * is still O(N) when nearly every entry is hot, but a sustained eviction stream never re-scans | ||
| * the hot prefix more than twice across N evictions. | ||
| * | ||
| * <p>The semantic intent: at cap with all entries live, drop the new key (reported via {@code | ||
| * onStatsAggregateDropped}) rather than evicting an established one. Cap is sized to the | ||
| * steady-state working set, so eviction is rare; this cursor optimization handles the | ||
| * pathological "persistently at cap" case. | ||
| */ | ||
| private boolean evictOneStale() { | ||
| // Two passes -- [cursor, length) then [0, cursor) -- using the half-open-range iterator. The | ||
| // second pass is naturally empty when cursor==0, so no extra check needed. | ||
| return evictOneStaleInRange(evictCursor, buckets.length) | ||
| || evictOneStaleInRange(0, evictCursor); | ||
| } | ||
|
|
||
| /** Scans {@code [startBucket, endBucket)} for the first stale entry and unlinks it. */ | ||
| private boolean evictOneStaleInRange(int startBucket, int endBucket) { | ||
| MutatingTableIterator<AggregateEntry> iter = | ||
| Support.mutatingTableIterator(buckets, startBucket, endBucket); | ||
| while (iter.hasNext()) { | ||
| AggregateEntry e = iter.next(); | ||
| if (e.getHitCount() == 0) { | ||
| int bucket = iter.currentBucket(); | ||
| iter.remove(); | ||
| size--; | ||
| evictCursor = bucket; | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| void forEach(Consumer<AggregateEntry> consumer) { | ||
| Support.forEach(buckets, consumer); | ||
| } | ||
|
|
||
| /** | ||
| * Context-passing forEach. Useful for callers that want to avoid a capturing-lambda allocation on | ||
| * each invocation -- pass a non-capturing {@link BiConsumer} (typically a {@code static final}) | ||
| * plus whatever side-band state it needs as {@code context}. | ||
| */ | ||
| <T> void forEach(T context, BiConsumer<T, AggregateEntry> consumer) { | ||
| Support.forEach(buckets, context, consumer); | ||
| } | ||
|
|
||
| /** Removes entries whose {@code getHitCount() == 0}. */ | ||
| void expungeStaleAggregates() { | ||
| for (MutatingTableIterator<AggregateEntry> iter = Support.mutatingTableIterator(buckets); | ||
| iter.hasNext(); ) { | ||
| AggregateEntry e = iter.next(); | ||
| if (e.getHitCount() == 0) { | ||
| iter.remove(); | ||
| size--; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void clear() { | ||
| Support.clear(buckets); | ||
| size = 0; | ||
| evictCursor = 0; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.