Replies: 2 comments 7 replies
-
Surprisingly, actually this is not true at all :) It is very subtle and nuanced, but in most cases the handling of blocking tasks in Cats Effect is near optimal and probably better than Loom. We recently discussed this in #3869 (comment). The tl;dr is that Loom doesn't and cannot fix I/O blocking such as file I/O or DNS and using virtual threads in for those operations instead of the Cats Effect threadpool would create unnecessary thread shifting and contention. Loom does fix blocking-style APIs that use non-blocking I/O (e.g. network sockets) under-the-hood, such as JDBC. Based on the discussion in that issue, we did add a mechanism so that blocking tasks can be run on virtual threads.
Daniel wrote a very nice Reddit post detailing why Loom doesn't matter so much for Cats Effect. tl;dr we will not be replacing the compute pool with virtual threads. https://www.reddit.com/r/scala/comments/sa927v/comment/htsoydn/ Further reading/watching about threads, threadpools, and performance:
Let us know if you have more questions :) |
Beta Was this translation helpful? Give feedback.
-
A couple quick comments on the (excellent!) blog post:
Winning on
This sounds like a bug to me! Would you mind opening an issue for it? |
Beta Was this translation helpful? Give feedback.
-
Dear maintainers,
May I bother you with a question?
I did some research recently
https://jacum.medium.com/running-cats-effect-on-virtual-threads-of-jdk21-7a68ea97fd65
TLDR:
The current way of dealing with occasional blocking contexts in Cats Effect is sub-optimal, when compared to native fiber scheduling implemented on JDK21.
Of course - JDK21 is still fresh, and may not (yet) available for all and every JVM workload, but it is clearly very efficient. It is also next LTS after JDK 17, and likely will be most widely used one in a year or two.
I wonder what is your take on the future of the runtime on JDK21?
Is the whole runtime going to be replaced to thread-per-runnable?
Or just maybe rewrite blockOn() method
cats-effect/core/jvm/src/main/scala/cats/effect/unsafe/WorkerThread.scala
Line 817 in 623178c
to run that 'thunk' on Executors.newVirtualThreadPerTaskExecutor() and leave the rest of non-blocking executor to use the same Thread API?
Beta Was this translation helpful? Give feedback.
All reactions