This repository has been archived by the owner on Dec 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 527
[Proposal] Pool WriteContext per thread #469
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
97d3340
Resuse writes, initalize queues
benaadams 992664e
Process cascaded work immediately
benaadams 3e42904
Pool UvWriteReqs instead of SocketOutput.WriteContexts
halter73 5665eba
Pool WriteContexts additionally
benaadams 6e7186b
Pool WriteContext per thread rather than connection
benaadams File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
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'm afraid of adding a ThreadStatic. We don't use ThreadStatics anywhere else in Kestrel that I'm aware of.
I just checked the default maximum number of worker threads on my machine using ThreadPool.GetMaxThreads, and it was 32,767. I don't like having potentially that many static queues. Considering that each queue could pool up to 128 WriteContexts (and you just calculated the size WriteContext being 88 bytes), that's up to ~370MB of WriteContexts that will never be freed. That's not even considering the size of the queues themselves.
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.
Don't hold off merging #466 based on this (no issues in that one; and this is straight on top)
Know what you mean about
ThreadStatic
s though been doing some investigation.So the
ThreadStatic
is GC'd after thread exit; assuming it has no other outstanding strong references - which should be ok for this. Objects with a finalizer aren't so good as they'll hang around till the finalizer runs - but the WriteContext that's been reset is just a POCO managed type; so the queue will be happily GC'd when the threadpool scales back down.If you are up to 32k of live threadpool threads; then the 32GB of thread stack space they need might be more of an issue than the 370MB of pooled
WriteContext
s.However... I'm not sure this PR is a great win; it doesn't reduce any contention, as there already isn't any; but it should reduce the memory for a very large number of connections - but that scenerio will probably have all sorts of other stuff to look at.
Happy to close for now and come back to; if it is an issue?