-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Use Channel Instead of BufferBlock #5123
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5123 +/- ##
==========================================
- Coverage 75.66% 75.55% -0.11%
==========================================
Files 993 995 +2
Lines 178168 179316 +1148
Branches 19122 19298 +176
==========================================
+ Hits 134802 135487 +685
- Misses 38143 38564 +421
- Partials 5223 5265 +42
|
Codecov Report
@@ Coverage Diff @@
## master #5123 +/- ##
==========================================
- Coverage 75.66% 73.68% -1.98%
==========================================
Files 993 1022 +29
Lines 178168 190353 +12185
Branches 19122 20473 +1351
==========================================
+ Hits 134802 140264 +5462
- Misses 38143 44557 +6414
- Partials 5223 5532 +309
|
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 think this looks good.
Thanks @eerhardt! I'll make similar changes to the other items and will mark this PR ready. |
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 think you can remove this line as well:
|
_deadCount = 0; | ||
} | ||
|
||
while (_liveCount < _poolRows && !_doneConsuming) | ||
{ | ||
// We are under capacity. Try to get some more. | ||
int got = _toConsume.Receive(); | ||
if (got == 0) | ||
var hasReadItem = _toConsumeChannel.Reader.TryRead(out int got); |
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.
Previously _toConsume.Receive()
would block the thread until something was available. But now TryRead
will return false
immediately if something wasn't available. In that case, we will keep spinning in the while
loop and checking the reader constantly.
It might make sense to keep the previous behavior and block the thread until _toConsumeChannel
has an item available, so we aren't wasting CPU cycles spinning here.
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 believe this comment has been addressed yet: |
@eerhardt I may need some guidance on the best way to block the thread there. 😃 Would using the |
I believe you can call // Get a TCS to represent the receive operation and wait for it to complete.
// If it completes successfully, return the result. Otherwise, throw the
// original inner exception representing the cause. This could be an OCE.
Task<TOutput> task = ReceiveCore(source, false, timeout, cancellationToken);
try
{
return task.GetAwaiter().GetResult(); // block until the result is available
} |
@eerhardt Updated to use |
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.
Looks good! Thanks for the great work here, @jwood803.
@jwood803 Thank you for your contribution. I am merging the PR now. |
Updates for #4482.
@eerhardt I took a shot at a single replacement to make sure it looks good before continuing. Does this look good or am I missing anything?