Conversation
3e01a27 to
aa9da20
Compare
Virtual threads from Project Loom allow spinning up many more fibers than when using native threads. This is an early patch to add vthread support to JRuby's fibers when the vthread API is available (starting as a preview feature in JDK19). Pass --enable-preview to the JVM to enable vthreads on JDK19.
aa9da20 to
da656aa
Compare
|
Going to land this to start letting folks preview virtual threads once 9.3.8.0 is out. A more elaborate implementation, possibly using executors to schedule fibers within a given thread, can come in 9.4 or after. |
|
I've been thinking about this. My concern is AFAIK VirtualThreads automatically switch on blocking IO and blocking synchronization calls. Also if the current Fiber's VirtualThread gets blocked on some IO, and the same happens for the current Fiber of another RubyThread they might switch carrier threads I suppose. Not a problem from the Thread.currentThread() POV, but if there is anything native (e.g. a pthread_mutex via FFI) it could matter. And of course there is the question of how much overhead it is to use locks/queues to make VirtualThread behave like coroutine vs using JDK Continuation (which might not be accessible though) and switching explicitly. |
Virtual threads from Project Loom allow spinning up many more fibers than when using native threads. This is an early patch to add vthread support to JRuby's fibers when the vthread API is available (starting as a preview feature in JDK19).
Enable the feature when running on JDK 19:
--enable-previewto the JVM-J--enable-previewto JRuby--enable-previewinJAVA_OPTSenvTested with 100k fibers spun up, and then later resumed, using the following script:
Without vthreads, this script runs for a few seconds and then blows up, either raising memory errors or crashing the JVM. With vthreads it can complete multiple iterations, warming up to around 0.7s per loop on my system.