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

Consider letting the transport own the creation of IDuplexPipe #4752

Closed
davidfowl opened this issue Mar 25, 2018 · 12 comments · Fixed by #10321
Closed

Consider letting the transport own the creation of IDuplexPipe #4752

davidfowl opened this issue Mar 25, 2018 · 12 comments · Fixed by #10321
Assignees
Labels
accepted This issue has completed "acceptance" testing (including accessibility) area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions 🥌 Bedrock enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-kestrel

Comments

@davidfowl
Copy link
Member

Today the transport is responsible for exposing properties on the connection that can be used by Kestrel to create a duplex pipe. It does this today for a few reasons:

  • It wants to directly apply the MaxResponseBufferSize and MaxRequestBuffer size to pipe options
  • It communicates "fin" via cancelling the transport's output reader (this is super hacky and we should get rid of it anyways).
  • It wants to control where "user code" runs. This includes:
    • ConnectionAdapters (soon to be deprecated)
    • CancellationToken callbacks
    • the request processing delegate

Delegating to the transport has some other benefits:

  • Transports aren't tied to a specific pipe implementation.
  • We can potentially delete ITransportSchedulerFeature, IApplicationTransportFeature

To make this change though, we need to pass the relevant settings from kestrel to the transport without coupling. My current though is to pass a settings object to ITransportFactory.Create.

See https://github.com/geoffkizer/KestrelHttpServer/blob/7bd21cdb1581fc3559479842262a24deecf171bb/src/Kestrel.Transport.Sockets/Internal/SocketConnection.cs for an example of the socket transport with a direct pipe implementation.

/cc @tmds @benaadams (only other people that wrote transports 😄)

@tmds
Copy link
Member

tmds commented Mar 27, 2018

Probably it also means removing ApplicationSchedulingMode which is good to avoid double dispatch to the ThreadPool (e.g. Sockets).

I assume existing implementations can just create the two Pipes similar to how Kestrel does it now, and things will work as before.

@davidfowl
Copy link
Member Author

Probably it also means removing ApplicationSchedulingMode which is good to avoid double dispatch to the ThreadPool (e.g. Sockets).

Not necessarily, the application callback (process request) could still be dispatched by kestrel itself.

I assume existing implementations can just create the two Pipes similar to how Kestrel does it now, and things will work as before.

That's correct.

@tmds
Copy link
Member

tmds commented Mar 27, 2018

Not necessarily, the application callback (process request) could still be dispatched by kestrel itself.

Ah, ok. I see the default is to use the ThreadPool:

https://github.com/aspnet/KestrelHttpServer/blob/af636fc8d4870aeba5b892cdcd3994a5d956c475/src/Kestrel.Core/KestrelServer.cs#L86-L88

So Sockets are doing a double dispatch currently.

@halter73
Copy link
Member

So Sockets are doing a double dispatch currently.

Yep. That's why we were surprised that it was helpful to dispatch in SocketAsyncEventArgs.Completed on Windows.

@tmds
Copy link
Member

tmds commented Mar 29, 2018

@halter73 I didn't realize Windows also did a threadpool dispatch on Windows. When you benchmark Sockets with SchedulingMode.Inline what difference do you see with the default (ThreadPool)?

@davidfowl
Copy link
Member Author

@halter73 I didn't realize Windows also did a threadpool dispatch on Windows

It doesn't, we dispatch and it performs much better than running inline

@tmds
Copy link
Member

tmds commented Mar 29, 2018

It doesn't, we dispatch and it performs much better than running inline

@davidfowl are you sure? In corefx I see the iocp stuff is using ThreadPoolBoundHandle, that sounds as if it is using the ThreadPool.

@halter73
Copy link
Member

I'm sure we dispatch ourselves on Windows in SocketAwaitable.Complete(). ThreadPoolBoundHandle uses the ThreadPool to handle GetQueuedCompletionStatus on completion port threads, but I don't see anywhere it dispatches to worker threads on its own.

@tmds
Copy link
Member

tmds commented Mar 29, 2018

ThreadPoolBoundHandle uses the ThreadPool to handle GetQueuedCompletionStatus on completion port threads

ok, I don't understand iocp and I believe you when you say it doesn't run on the ThreadPool 😄

@muratg
Copy link
Contributor

muratg commented Aug 24, 2018

@davidfowl are you going to be working on this? If not, please punt. Thanks.

@aspnet-hello aspnet-hello transferred this issue from aspnet/KestrelHttpServer Dec 13, 2018
@aspnet-hello aspnet-hello added this to the 3.0.0 milestone Dec 13, 2018
@aspnet-hello aspnet-hello added area-servers 🥌 Bedrock enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-kestrel labels Dec 13, 2018
@muratg muratg modified the milestones: 3.0.0, Backlog Mar 7, 2019
@davidfowl davidfowl modified the milestones: Backlog, 3.0.0-preview6 May 31, 2019
@davidfowl davidfowl self-assigned this May 31, 2019
@davidfowl
Copy link
Member Author

davidfowl commented Jun 3, 2019

Acceptance checklist (check one item)

  • We decided not to take this fix.
  • The fix is tests-only.
  • The fix contains product changes (check all items below).
    • Relevant XML documentation comments for new public APIs are present.
    • Narrative docs (docs.microsoft.com) are updated. (check one item below)
      • The change requires a new article. An issue with an outline has been filed here: [ISSUE LINK]
      • The change requires a change to an existing article. A docs PR with these changes is linked here: [PR LINK]
      • The change requires no docs changes.
    • Verification has been completed. (check one item below)
      • The change is in the shared framework and was verified against the following versions
        • SDK installer: [VERSION]
        • ASP.NET Core Runtime: [VERSION]
        • .NET Core Runtime: [VERSION]
      • The change is in an OOB NuGet/NPM/JAR package and was verified against the following version of that package: [PACKAGE ID] [VERSION]

@davidfowl davidfowl added the accepted This issue has completed "acceptance" testing (including accessibility) label Jun 3, 2019
@davidfowl
Copy link
Member Author

We changed the design such that the pipes are owned by the transport as part of #10308

@ghost ghost locked as resolved and limited conversation to collaborators Dec 4, 2019
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted This issue has completed "acceptance" testing (including accessibility) area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions 🥌 Bedrock enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-kestrel
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants