Does JFR support Async I/O?
I am using Java Flight Recorder (on HotSpot 1.8.0_144) + Mission Control to profile an app.
On the File IO
tabs of Mission Control, I see orders of magnitude less "activity" than I expected and that I know to be actually happening.
The IO "activity" that I am actually seeing seems to correspond to synchronous file IO, but I am not sure if this is just a coincidence, or a misconfiguration of the JFR on my part.
I did try this on a smaller example (see below), and it feels like the file async events are not being reported.
Sync File IO events are reported
val inputStream = new FileInputStream("/home/cmhteixeira/Desktop/output.txt")
val outputStream = new FileOutputStream("/home/cmhteixeira/Desktop/output-copy.txt")
inputStream.transferTo(outputStream)
Async File IO events are not reported
RxIo(used below) is a library claiming to use file async IO.
import org.javaync.io.AsyncFiles
import java.nio.file.Paths
val inputStream = Paths.get("/home/cmhteixeira/Desktop/output.txt")
val outputStream = Paths.get("/home/cmhteixeira/Desktop/output-copy.txt")
AsyncFiles
.readAllBytes(inputStream)
.thenCompose(bytes => AsyncFiles.writeBytes(outputStream, bytes))
.thenAcceptAsync(index => println("done")/* invoked on completion */)
on both the cases above, the File IO Threshold
is set to 0 ns
when lunching via Java Mission Control.
Questions
- Is file async IO not supported?
- What about async socket IO (which I have not tested)?
- If the answer is no, how bad is this considered by the community that uses JFR?
- It feels like its a big drawback, but I lack context to understand if in practise this matters much.
There are no events for file async I/O.
Not socket either.
It's been a known issue for many years, but it has been tricky to implement. JFR does support Virtual Threads, which will hopefully reduce the need for using async APIs directly. It's still a preview feature (April 2022)
See this presentation from FOSDEM, 33:00 minutes in. https://archive.fosdem.org/2020/schedule/event/state_openjdk/