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

发布于 2025-01-23 16:28:39 字数 1319 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怎言笑 2025-01-30 16:28:40

file async io不支持?

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

ASYNC插座IO(我尚未测试)呢?

也不插座。

如果答案是否定的,那么使用JFR的社区认为这有多糟糕?感觉就像是一个很大的缺点,但我缺乏上下文来理解实践中是否很重要。

它已经已知问题多年来,实施一直很棘手。 JFR确实支持虚拟线程,这将减少直接使用async apis的需求。这仍然是一个预览功能(2022年4月),

请参见Fosdem的此演示文稿,33:00分钟。
https://archive.fosdem.fosdem.org/2020/2020/schedule/schedule/schedule/event/state_openjdk/state_openjdk/ << /a>

Is file async IO not supported?

There are no events for file async I/O.

What about async socket IO (which I have not tested)?

Not socket either.

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.

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文