Replies: 4 comments 7 replies
-
It's not, but overriding the runtime in override def runtime = IORuntime.builder().setBlocking(...).build() |
Beta Was this translation helpful? Give feedback.
-
Thanks! This is much simpler than what I copied from
So I just want to make sure there is no other better way to do it. |
Beta Was this translation helpful? Give feedback.
-
@armanbilge I tried to override runtime like this with thread name object FetchServer extends IOApp {
override def runtime: IORuntime = {
val (blocking, blockDown) = createCustomBlockingExecutionContext()
IORuntime.builder().setBlocking(blocking, blockDown).build()
}
private def createCustomBlockingExecutionContext(): (ExecutionContext, () => Unit) = {
val threadCount = new AtomicInteger(0)
val executor = Executors.newFixedThreadPool(16, { (r: Runnable) =>
val t = new Thread(r)
t.setName(s"io-blocking-custom-${threadCount.getAndIncrement()}")
t.setDaemon(true)
t
})
(ExecutionContext.fromExecutor(executor), { () => executor.shutdown() })
}
override def run(args: List[String]): IO[ExitCode] = {
BaseServer().evalMap { baseServer =>
MetricServer.start() >> baseServer.fetcher.run()
}.useForever
}
} But I still see blocking threads named |
Beta Was this translation helpful? Give feedback.
-
@armanbilge Thanks for the info! If that's the case, I think maybe I will just use unlimited blocking threads for now. But I think it's a useful use case to limit the thread size, since if some code (unintentionally) generates lots of slow blocking operations, it may blow up the threads and make the whole system unresponsive. It's better to limit the thread size so that developer has a working system to debug what is going on. I see there is a Additionally, maybe we should update the doc at https://typelevel.org/cats-effect/docs/thread-model#blocking? Since there is no mentioning of such a behavior for WTSP. It only says "CE3 has a builtin blocking which will shift execution to an internal blocking threadpool and shift it back afterwards using Async." |
Beta Was this translation helpful? Give feedback.
-
Is there anyway to override blocking thread pool in
IOApp
without overrideIORuntime
? I want the blocking thread pool to have a limited size and larger caching time.Beta Was this translation helpful? Give feedback.
All reactions