-
Notifications
You must be signed in to change notification settings - Fork 786
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
Add max spin count limit to circular buffer #1088
Conversation
@@ -113,7 +113,7 @@ internal long ProcessedCount | |||
/// <inheritdoc/> | |||
public override void OnEnd(Activity activity) | |||
{ | |||
if (this.queue.TryAdd(activity)) | |||
if (this.queue.TryAdd(activity, maxSpinCount: 50000)) |
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.
Do we want to make this configurable?
|
||
var spinCountDown = maxSpinCount; | ||
|
||
while (true) |
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.
Duplicate the code from Add
instead of reusing the code - for better perf.
/// Attempts to add the specified item to the buffer. | ||
/// </summary> | ||
/// <param name="value">The value to add.</param> | ||
/// <param name="maxSpinCount">The maximum allowed spin count, when set to a negative number of zero, will spin indefinitely.</param> |
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.
We might want to avoid spin entirely if we are running on a single core machine. I guess it is a low priority at this moment.
Codecov Report
@@ Coverage Diff @@
## master #1088 +/- ##
==========================================
- Coverage 76.01% 75.85% -0.16%
==========================================
Files 225 225
Lines 6208 6225 +17
==========================================
+ Hits 4719 4722 +3
- Misses 1489 1503 +14
|
} | ||
} | ||
} | ||
|
||
public IEnumerable<T> Consume(int count) |
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.
@reyang FYI just noticed you don't have any XML comments for Consume. Also might want to rename count
-> maxCount
or something, because you can actually get less?
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.
Good catch, let me send a small PR to fix it.
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.
@ThomsonTan brought up a good point that we might want to avoid spinning indefinitely.
This could happen on a highly concurrent environment since spin lock does not guarantee ordering, so mathematically it is possible that one unfortunate thread ended up to be always spinning while in its own quorum, which is scary for customers who use telemetry SDK.