-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
HTTP/2 output processing make over #40925
Conversation
src/Servers/Kestrel/Core/src/Internal/Http2/Http2FrameWriter.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/Core/src/Internal/Http2/Http2FrameWriter.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/Core/src/Internal/Http2/Http2FrameWriter.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/Core/src/Internal/Http2/Http2FrameWriter.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/Core/src/Internal/Http2/Http2FrameWriter.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/Core/src/Internal/Http2/Http2OutputProducer.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/Core/src/Internal/Http2/Http2FrameWriter.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/Core/src/Internal/Http2/Http2FrameWriter.cs
Outdated
Show resolved
Hide resolved
7864a25
to
8b42920
Compare
Fixed merge conflicts. |
src/Servers/Kestrel/Core/src/Internal/Http2/Http2FrameWriter.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/Core/src/Internal/Http2/Http2FrameWriter.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/Core/src/Internal/Http2/Http2OutputProducer.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/Core/src/Internal/Http2/Http2OutputProducer.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/Core/src/Internal/Http2/Http2FrameWriter.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.
I'd like to be clearer about whether we're referring to the connection or stream window.
src/Servers/Kestrel/Core/src/Internal/Http2/Http2FrameWriter.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/Core/src/Internal/Http2/Http2FrameWriter.cs
Outdated
Show resolved
Hide resolved
|
||
if (producer.IsTimingWrite) | ||
{ | ||
_timeoutControl.StopTimingWrite(); |
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.
Nit: We should avoid stopping the timing if we're just going to restart it.
src/Servers/Kestrel/Core/src/Internal/Http2/Http2FrameWriter.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/Core/src/Internal/Http2/Http2OutputProducer.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/Core/src/Internal/Http2/Http2FrameWriter.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/Core/src/Internal/Http2/Http2FrameWriter.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/Core/src/Internal/Http2/Http2FrameWriter.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/Core/src/Internal/Http2/Http2FrameWriter.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/Core/src/Internal/Http2/Http2FrameWriter.cs
Outdated
Show resolved
Hide resolved
@halter73 your last commit broke quite a few new tests, I’ll revert and apply some of the suggestions from the review. |
src/Servers/Kestrel/Core/src/Internal/Http2/Http2FrameWriter.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/test/Interop.FunctionalTests/HttpClientHttp2InteropTests.cs
Outdated
Show resolved
Hide resolved
|
src/Servers/Kestrel/Core/src/Internal/Http2/Http2OutputProducer.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelTrace.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/Core/src/Internal/Http2/QueueWithMovableHead.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2StreamTests.cs
Show resolved
Hide resolved
I'm attempting to make the pipe buffer change and fix one more round of tests... Wish me luck... |
I removed the |
src/Servers/Kestrel/Core/src/Internal/Http2/Http2OutputProducer.cs
Outdated
Show resolved
Hide resolved
c7cf0b0
to
6557e99
Compare
- Today its possible for a single stream to keep getting rescheduled and draining the connection window. This change makes it so that streams that have data to be written and haven't written anything are preferred over ones that have written something. It does this by changing the head of the queue before dequeuing everything to start at the first index of the stream that hasn't written anything.
- Reworked logic in frameworker to use the state enum as well as the read result. - Fixed races around how work can be scheduled now that we're not running inline with a small pause threshold.
- Store the last window consumer in as a field and make sure it gets queued last on the next window update.
- Over scheduling races (cancel during a dequeue that will complete the pipe) - Handle cancellation when there are trailers
- Added current state to make sure state is terminal. We base decisions on the current state and use the unobserved state to determine when to reschedule. - Remove CancelPendingRead since there's never a pending read and we're scheduling the pipe reads manually. - Rename the Canceled state to Aborted
6557e99
to
02319f0
Compare
We're good @halter73 ! |
Nice! One request: run the gRPC benchmark with 70 streams and 28 connections. I’d like to see how the change performs when the server is at capacity |
@JamesNK do you have a command for me to run? 😄 |
It’s the same one but add “—variable connections=28” |
28 connections, 70 streamsBefore
After
|
@@ -74,6 +71,7 @@ internal partial class Http2Connection : IHttp2StreamLifetimeHandler, IHttpStrea | |||
internal readonly Http2KeepAlive? _keepAlive; | |||
internal readonly Dictionary<int, Http2Stream> _streams = new Dictionary<int, Http2Stream>(); | |||
internal PooledStreamStack<Http2Stream> StreamPool; | |||
internal Action<Http2Stream>? _onStreamCompleted; |
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.
Is this just for testing?
I don't think it needs to be fixed now, but I'd like to see this reworked to utilize IHttp2StreamLifetimeHandler
. Tests should support customizing the handler so it can be used to raise this event. I did this in the HTTP/3 tests and it works well.
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.
Maybe create a follow-up issue.
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.
🚢 🇮🇹
|
This changes the HTTP/2's output processing to be use queues instead of locks (a channel to be precise). We're manually scheduling the Http2OutputProducer's intent to write instead of a write operation. This removes locks and allows the thread to do other useful work while processing in line for processing in a low allocation way.
Fixes #30235
~~Putting this up as a draft for now while I run performance tests and to get early feedback. ~~
Scenaro: Unary invocation with 70 concurrent requests with one connection
Current
PR
Scenario: Unary invocation 1 stream and 1 connection
Current
PR