Skip to content
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

Take steps to avoid threadpool starvation #11275

Merged
merged 5 commits into from
Feb 26, 2025

Conversation

Erarndt
Copy link
Contributor

@Erarndt Erarndt commented Jan 13, 2025

Fixes #

Context

There are a handful of areas where threadpool threads are unnecessarily blocked by synchronous work, or there is additional contention that can be avoided. The most egregious instance is the synchronous read in BuferedReadStream

image

The outer call to BeginRead() ends up calling BufferedReadStream.Read() which synchronously blocks when _innerStream.Read() is called. This results in a substantial amount of block time for threadpool threads.

Changes Made

Testing

Notes

@JanKrivanek
Copy link
Member

Related to #11160

@JanKrivanek
Copy link
Member

/azp run

Copy link

Pull request contains merge conflicts.

@JanKrivanek JanKrivanek marked this pull request as ready for review January 15, 2025 17:32
@JanKrivanek JanKrivanek self-requested a review January 15, 2025 17:32
@SimaTian SimaTian requested a review from maridematte January 29, 2025 15:14
@SimaTian
Copy link
Member

I've pushed some tweaks involving channels and setting up a drain thread in a slightly different manner - the old construct of
"whenever we're sending a packet, we call DrainQueue" was weird so this is my attempt to remove it.
Please let me know if this is fine, if it needs additional changes or if we want to revert it altogether for some reason I didn't foresee.

@SimaTian SimaTian force-pushed the dev/erarndt/threadUtilization branch from 6bd3585 to 56bee6b Compare February 21, 2025 13:55
@SimaTian
Copy link
Member

I've removed my experimental changes for now. Let's aim to review & merge this, then return to it at a later date.

Copy link
Member

@AR-May AR-May left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I have couple of small comments.

@AR-May
Copy link
Member

AR-May commented Feb 25, 2025

I implemented the changes I suggested, @SimaTian please review again.

@SimaTian SimaTian merged commit de017c7 into dotnet:main Feb 26, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants