Java 飞行记录器 - 异步 I/O 支持

Java Flight Recorder - Async I/O support

JFR 是否支持异步 I/O?

我正在使用 Java Flight Recorder(在 HotSpot 1.8 上。0_144)+ Mission Control 来分析应用程序。

在 Mission Control 的 File IO 选项卡上,我看到的“activity”数量级比我预期的要少几个数量级,而且我知道这是实际发生的。
我实际看到的IO“activity”似乎对应于同步文件IO,但我不确定这只是巧合,还是我的JFR配置错误

我确实在一个较小的例子上尝试过这个(见下文),感觉好像没有报告文件异步事件。

已报告同步文件 IO 事件

val inputStream = new FileInputStream("/home/cmhteixeira/Desktop/output.txt")
val outputStream = new FileOutputStream("/home/cmhteixeira/Desktop/output-copy.txt")

inputStream.transferTo(outputStream)

不报告异步文件 IO 事件

RxIo(下面使用)是一个声称使用文件异步 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 */)

在上述两种情况下,File IO Threshold 在午餐时通过 Java 任务控制设置为 0 ns

问题

Is file async IO not supported?

没有文件异步事件 I/O。

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.

这是一个 known issue for many years, but it has been tricky to implement. JFR does support Virtual Threads,它有望减少直接使用异步 API 的需要。它仍然是一个预览功能(2022 年 4 月)

查看来自 FOSDEM 的演示文稿,33:00 分钟。 https://archive.fosdem.org/2020/schedule/event/state_openjdk/