perf(runtime): reduce callback tracking contention#10062
Draft
ReubenBond wants to merge 1 commit into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces contention in callback tracking by replacing the existing callback dictionaries with a striped implementation and by embedding a stripe selector into CorrelationId values generated for outgoing requests.
Changes:
- Introduce
StripedCallbackDictionary<TValue>for callback tracking with per-stripe locking. - Update inside/outside runtime clients to use the striped dictionary keyed by
CorrelationId. - Update correlation id generation to encode stripe bits into the upper bits of the id (and adjust
CorrelationId.GetHashCode()).
Show a summary per file
| File | Description |
|---|---|
| src/Orleans.Runtime/Core/InsideRuntimeClient.cs | Switch callback tracking to StripedCallbackDictionary and simplify keying/removal to CorrelationId. |
| src/Orleans.Core/Runtime/OutsideRuntimeClient.cs | Switch client-side callback tracking to StripedCallbackDictionary and update request counting. |
| src/Orleans.Core/Messaging/StripedCallbackDictionary.cs | Add new striped dictionary implementation (per-stripe lock + snapshot enumeration). |
| src/Orleans.Core/Messaging/MessageFactory.cs | Encode stripe index into generated CorrelationId values. |
| src/Orleans.Core/Messaging/CorrelationId.cs | Update hash code implementation for CorrelationId. |
Copilot's findings
- Files reviewed: 5/5 changed files
- Comments generated: 3
Comment on lines
26
to
30
| private readonly ILogger logger; | ||
| private readonly ClientMessagingOptions clientMessagingOptions; | ||
|
|
||
| private readonly ConcurrentDictionary<CorrelationId, CallbackData> callbacks; | ||
| private readonly StripedCallbackDictionary<CallbackData> callbacks; | ||
| private InvokableObjectManager localObjects; |
Comment on lines
+155
to
+165
| lock (stripe.Lock) | ||
| { | ||
| foreach (var kvp in stripe.Dictionary) | ||
| { | ||
| if (predicate(kvp)) | ||
| { | ||
| count++; | ||
| } | ||
| } | ||
| } | ||
| } |
Comment on lines
50
to
55
| private CorrelationId GetNextCorrelationId() | ||
| { | ||
| var id = _seed ^ Interlocked.Increment(ref _nextId); | ||
| return new CorrelationId(unchecked((long)id)); | ||
| var stripeIndex = StripedCallbackDictionary<object>.GetCurrentThreadStripeIndex(); | ||
| return StripedCallbackDictionary<object>.CreateCorrelationId(unchecked((long)id), stripeIndex); | ||
| } |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
fcbac7d to
1efc300
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
StripedCallbackDictionaryfor callback tracking.Validation
git diff --checkdotnet build src\Orleans.Core\Orleans.Core.csproj -mNotes
Microsoft Reviewers: Open in CodeFlow