Java飞行记录器 - 异步I/O支持
JFR支持异步I/O吗?
我正在使用Java飞行记录器(在Hotspot 1.8.0_144上) +任务控件来配置一个应用程序。
在文件io
任务控制的选项卡上,我看到的“活动”比我预期的要少,而且我知道实际上正在发生。
我实际上看到的IO“活动”似乎与同步文件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 (下面使用)是库声称是一个库声称使用文件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 */)
在上面的两种情况下,文件IO阈值
通过Java任务控制午餐时,将设置为0 ns
。
问题
- 是否不支持file async io?
- ASYNC插座IO(我尚未测试)呢?
- 如果答案是否定的,那么使用JFR的社区认为这有多糟糕?
- 感觉就像是一个很大的缺点,但是我缺乏上下文来理解实践中是否很重要。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
文件异步I/O没有事件。
也不插座。
它已经已知问题多年来,实施一直很棘手。 JFR确实支持虚拟线程,这将减少直接使用async apis的需求。这仍然是一个预览功能(2022年4月),
请参见Fosdem的此演示文稿,33:00分钟。
https://archive.fosdem.fosdem.org/2020/2020/schedule/schedule/schedule/event/state_openjdk/state_openjdk/ << /a>
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/