Virtual threads and File IO
Alan Bateman
Alan.Bateman at oracle.com
Sat Jun 1 08:33:02 UTC 2024
On 31/05/2024 20:38, Robert Engels wrote:
> Hi,
>
> An interesting question came up on the Go support channels. One of the principle engineers stated that for local file IO, the Go routine (similar to virtual thread) won’t release the carrier thread.
>
> Is this the same with Java virtual threads? Yes, local IO is typically fast - but it is still order of magnitudes slower than memory computations - which the virtual thread could be doing while waiting for the IO request to be serviced.
>
As things stand, file I/O operation do capture the carrier. For local
files and most where it is almost always buffered I/O then it shouldn't
be much of an issue. If files are opened for direct I/O, or with the
synchronized I/O options (think O_SYNC), the target parallelism is
increased for the duration of the I/O operation so there is a spare
carrier available for other virtual threads to make progress.
There has been exploration into using asynchronous I/O, and io_uring,
for the implementations but there isn't a conclusion at this time. Main
thing is the bookkeeping and overhead when doing file I/O ops that may
take only a few microseconds.
-Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20240601/5b4c846b/attachment-0001.htm>
More information about the loom-dev
mailing list