-
Notifications
You must be signed in to change notification settings - Fork 650
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
Document the suggested way to get an EventLoopGroup #2498
Comments
Thanks for opening this issue. This is definitely something we need to provide guidance on. I am a bit worried about this code:
Since it defaults to the ELG depending on the platform; however, we have quite a few use-cases where want to pick POSIX on even Darwin platforms. My current thinking was along the lines of creating a new package (let's call it I haven't fully figured out how this should look but my thinking was something along those lines (all pseudocode):
Then concrete protocol client/server libraries should be able to take this configuration as part of their larger configuration and they just pass that through to the underlying universal bootstrap APIs. This should make it a lot easier for client/server library authors to become Multiplatform by default and easily exposing the configuration to the end-user of their library. They would then just declare their client like this
|
swift-certificates does not solve the problem of TLS configuration, as certificates provided by swift-certificates cannot easily be mapped into a SecIdentity. |
Oh then I misunderstood our last conversation around this. I thought that is possible. |
Here's the AHC PR that implements something along those lines: swift-server/async-http-client#697 |
@FranzBusch An env var override is probably necessary. If the programmer wants to override, that's easy: |
I know that AHC does this dance but it is really a pity that every single server/client implementation has to do the same dance again. I would really love if we can find a single abstraction for this that makes this easier for the ecosystem. |
Yes, it's painful (as we expect everybody to copy https://github.com/apple/swift-nio-examples/tree/main/UniversalBootstrapDemo). I have previously advocated for a Apart from a |
But to be clear: This is a related issue and is not the core that's to be discussed here. Whatever we do, every package will likely want a way to get a "default singleton ELG". Sure, it'd be nice if we didn't have to copy & paste code but that can be fixed at a later point in time. That's not blocking the more urgent issue of getting rid of |
Fair enough. I think overall I would vote for this approach
It avoids baking the default ELG into any API and we can solve the |
Just to be clear, any of the suggestions here avoids this. |
I phrased this a bit badly. I don't see a motivating reason to expose a |
Okay, I'm exactly the other way around. I've seen too many APIs like
where you'd read "ahh, no redirects allowed" and in fact it means "default config" for Using Therefore -- despite it not being dangerously confusing here -- I think we should go for |
Please pardon my barging in. Might the phrasing issue be resolved in the function signature, rather than with an enum? |
In the past, NIO and other libraries carried the flawed (#2142)
*EventLoopGroupProvider
pattern. There were two primary concerns:.createNew
)Now, with the singleton ELGs (#2471) the pattern should evolve into something more useful.
I think @fabianfett and my current thinking looks like this (but this is of course all open for debate): Let's assume we're building
FooClient
, a client library for the Foo service.It might have a top-level
Which gives us all the benefits:
FooClient
never owns theEventLoopGroup
-> shutdown's easyFooClient
is easy to create (FooClient()
, done)EventLoopGroup
you can easily haveFooClient
use it too:FooClient(eventLoopGroup: myBetterELG)
FooClient
can support alternative EventLoopGroups like the ones in NIOTS.FooClient
can start out only supportingNIOPosix
and later add NIOTS without API breaksPossible extension: If
FooClient
still owns non-memory resources (like a connection pool) that cannot be shut down synchronously, it's worth to consider adding a singleton-FooClient
instance too:The biggest risk here is configuration: This will work well if
FooClient
itself takes no configuration, this will be more troublesome ifFooClient
does have configuration: What config should the singleton have?Relevant discussion/information:
HTTPClient.Configuration.browserLike
swift-server/async-http-client#701Alternative: A more lightweight alternative might be
I think I prefer the first suggestion
FooClient(eventLoopGroup: FooClient.defaultEventLoopGroup)
because it this might read like it's not using an ELG:FooClient(eventLoopGroup: .none)
/FooClient(eventLoopGroup: nil)
.Open questions:
defaultEventLoopGroup
really appropriate for "the platform-default globally shared singleton group"?The text was updated successfully, but these errors were encountered: