-
Notifications
You must be signed in to change notification settings - Fork 419
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
Client cleanup is slow #2403
Comments
Yes I can confirm that. Its really too slow to be usable. |
Looks like it boils down to the event loop group layer: object Main extends ZIOAppDefault:
override def run: ZIO[Environment & ZIOAppArgs & Scope, Any, Any] =
(ZIO.service[EventLoopGroup] *> Console.printLine("Hello world!"))
.provideSome[Scope](ZLayer(zio.http.netty.EventLoopGroups.default)) it can be simplified further to: object Main extends ZIOAppDefault:
override def run: ZIO[Environment & ZIOAppArgs & Scope, Any, Any] =
EventLoopGroups.make(ZIO.succeed(DefaultEventLoopGroup())) *> Console.printLine("Hello world!") If |
This means the graceful shutdown of the netty |
Right. Looks like zio-http is using Future<?> shutdownGracefully(long quietPeriod,
long timeout,
TimeUnit unit)
I don't have a good sense of the importance of this measure more generally. My guess is this default makes sense for servers but the default client should have a short |
Sounds good to me! |
Opened #2410 |
Fixed by #2410 However, if you need this feature right now without waiting for other libraries to adapt to the big changes to import java.util.concurrent.TimeUnit
import zio.*
import zio.http.*
import zio.http.netty.NettyFutureExecutor
import zio.http.netty.client.NettyClientDriver
import io.netty.channel.{DefaultEventLoopGroup, EventLoopGroup}
object CustomClient:
private val group: ZIO[Scope, Nothing, EventLoopGroup] =
ZIO.acquireRelease(ZIO.succeed(DefaultEventLoopGroup()))(ev =>
NettyFutureExecutor
.executed(ev.shutdownGracefully(0, 100, TimeUnit.MILLISECONDS))
.orDie,
)
val default: ZLayer[Any, Throwable, Client] = ZLayer.scoped {
group.flatMap { elg =>
ZIO.service[zio.http.Client]
.provideLayer(
zio.http.Client.default.map { env =>
env.getDynamic[ClientDriver] match
case Some(NettyClientDriver(channelFactory, _, nettyRuntime, clientConfig)) =>
env.add[ClientDriver](NettyClientDriver(channelFactory, elg, nettyRuntime, clientConfig))
case _ => env
},
)
}
} Note that this hard-wires the event-loop group to a default version. If you have a custom netty config, you'll have to update this to reflect that configuration. (You could just copy over |
@johnhungerford , issue looks closable (260cc73 merged) |
Describe the bug
When the default zio-http layer is included in an application, it takes a surprising amount of time for the application to terminate after completing (~2 seconds).
To Reproduce
Steps to reproduce the behaviour:
build.sbt:
Main.scala:
sbt run
Expected behaviour
It should not take a noticeably longer time than if the program was just
Console.printLine("Hello world")
(which sbt reports as1 s
on my machine).Actual behavior
It takes
3 s
on my machine.Desktop (please complete the following information):
Additional context
This is an issue when using zio-http with a CLI app (built as a graal native image). I'd like to use it as a client but the program hangs after running. sttp with a zio backend doesn't have the same issue so I've been using that, but I'd like to migrate to straight zio.
The text was updated successfully, but these errors were encountered: