-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Expiring set lock free #6577
Expiring set lock free #6577
Conversation
Can one of the admins verify this patch? |
After thinking about this a bit with my friend @Scooletz we concluded spinning is not necessary and simply changing the volatile field is good enough. Will benchmark this again tomorrow. |
sdk/servicebus/Microsoft.Azure.ServiceBus/src/Primitives/ConcurrentExpiringSet.cs
Show resolved
Hide resolved
sdk/servicebus/Microsoft.Azure.ServiceBus/src/Primitives/ConcurrentExpiringSet.cs
Show resolved
Hide resolved
sdk/servicebus/Microsoft.Azure.ServiceBus/src/Primitives/ConcurrentExpiringSet.cs
Outdated
Show resolved
Hide resolved
sdk/servicebus/Microsoft.Azure.ServiceBus/src/Primitives/ConcurrentExpiringSet.cs
Outdated
Show resolved
Hide resolved
@nemakam I pushed an update. Let me know what you think |
…f delayBetweenCleanups
…dated in the meantime
e9766a9
to
51c1026
Compare
51c1026
to
febefba
Compare
sdk/servicebus/Microsoft.Azure.ServiceBus/src/Primitives/ConcurrentExpiringSet.cs
Show resolved
Hide resolved
sdk/servicebus/Microsoft.Azure.ServiceBus/src/Primitives/ConcurrentExpiringSet.cs
Outdated
Show resolved
Hide resolved
{ | ||
await cleanupTaskCompletionSource.Task.ConfigureAwait(false); | ||
this.cleanupTaskCompletionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously); | ||
await Task.Delay(delayBetweenCleanups, token).ConfigureAwait(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this also throw ObjectDisposedException
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it can given that dispose of the CTS only releases the timer and the linked registrations if any
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't completely know the inner details of CTS. I am going to trust your word that this would not throw ObjectDisposedException
and also that this.dictionaryAsCollection.Remove(kvp);
will not throw while iteration/dictionary.Clear() is in progress.
sdk/servicebus/Microsoft.Azure.ServiceBus/src/Primitives/ConcurrentExpiringSet.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @danielmarbach for this fix. |
Related to Azure Service Bus
Lock-free alternative to #6576
Task.Delay
if cleanup was scheduled to not leak the task for the duration of the timeout.Keys
access that locks the whole concurrent dictionaryCaveat (but highly unlikely):
With spinning
Without
TBD