Java飞行记录器 - 连续滚动记录

发布于 2025-01-17 18:49:30 字数 890 浏览 3 评论 0原文

问题

如何将滚动记录到磁盘中,并以最大年龄录制?

上下文

当我的服务器中有些不良情况时,我希望能够在几个小时之前转移分析信息并进行分析,以了解出了什么问题。

  1. 由于我不知道什么时候会发生不好,JDK应该不断将事件保存到磁盘上。
  2. 由于不经常重新启动服务器,以避免文件生长无限,因此我需要设置某种限制(年龄或大小)。

因此,换句话说,我希望JDK将记录连续保存到磁盘,但要删除较旧的文件/记录,以使总金额保持在一定的阈值(年龄或大小)之下。

为此,这些是我对版本Oracle JDK 1.8.0_144

-XX:+UnlockCommercialFeatures
-XX:+FlightRecorder
-XX:StartFlightRecording
   name=<foo-bar>
-XX:FlightRecorderOptions
   defaultrecording=true   // what does this do even?
   disk=true
   maxage=1h // this is what I thought would solve my problem! 
   repository=<path-to-where-I-want-the-recording>
   maxchunksize=5M

选项在磁盘上。但是不!它已经过去1天了,文件没有被封顶。

同时,maxchunksize似乎有效。各种.jfr文件约为5m。其中有许多这样的文件,因为年龄没有执行。

我在做什么错?

Question

How to get a rolling recording into disk, with a maximum age?

Context

When something goes bad in my server, I want to be able to dump the profiling information of the hours prior and analyse it, to know what went wrong.

  1. As I don't know when things will go bad, the JDK should be continuously saving the events to disk.
  2. As the server is not rebooted often, to avoid the files growing unbounded, I need to set some sort of cap (either age, or size).

So, in other words, I wanted the JDK to save the recordings continuously to disk, but remove the older files/recordings such that the total amount remains under a certain threshold (age or size).

To that end, these are the options I have for version Oracle JDK 1.8.0_144:

-XX:+UnlockCommercialFeatures
-XX:+FlightRecorder
-XX:StartFlightRecording
   name=<foo-bar>
-XX:FlightRecorderOptions
   defaultrecording=true   // what does this do even?
   disk=true
   maxage=1h // this is what I thought would solve my problem! 
   repository=<path-to-where-I-want-the-recording>
   maxchunksize=5M

I would have thought that setting maxage=1h would only keep the last 1 hour of recording on disk. But no! Its been past 1 day, and the files are not being capped.

At the same time the maxchunksize appears to work. The various .jfr files have approximately 5M. Of which there are many such files, since the the age capped is not being enforced.

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

护你周全 2025-01-24 18:49:30

我认为问题在于您正在开始两份录音,一份使用-XX:StartFlightRecording,另一份使用-XX:FlightRecorderOptions=defaultrecording=true

带有 -XX:StartFlightRecording 的则为无界。我认为以下选项适合 Oracle JDK 1.8.0_144 和您的用例:

-XX:+UnlockCommercialFeatures
-XX:FlightRecorderOptions=repository=<path>
-XX:StartFlightRecording=maxage=1h,name=<name>

需要 -XX:+UnlockCommercialFeatures 因为 JFR 是 Oracle JDK 8 中的商业功能。从 JDK 11 开始,它不再是更需要。

对于 JDK 8u40 或更高版本,-XX:+FlightRecorder 不需要与 -XX:StartFlightRecoding 一起使用。现在,JFR 缓冲区是在第一次记录开始时设置的,而不是在 JVM 启动时设置的。如果使用 defaultrecording=true 开始录制,仍需要 -XX:+FlightRecorder

-XX:FlightRecorderOptions=defaultrecording=true 做了很多事情,主要是出于历史原因,但仅在进行内存记录时才需要。从 JDK 9 开始,该选项不再需要并且已被删除。

如果使用 -XX:StartFlightRecording,则不需要 -XX:FlightRecorderOptions=disk=true,maxage=1h,这是启动 JFR 的推荐方式。

除非您遇到问题,否则我会将 maxchunksize 保留为默认值 (12 MB)。这是 JFR 已针对其进行优化和测试的块文件大小。

The problem, I think, is that you are starting two recordings, one with-XX:StartFlightRecording and one with -XX:FlightRecorderOptions=defaultrecording=true.

The one with -XX:StartFlightRecording is unbounded. I think the following would be appropriate option for Oracle JDK 1.8.0_144 and your use case:

-XX:+UnlockCommercialFeatures
-XX:FlightRecorderOptions=repository=<path>
-XX:StartFlightRecording=maxage=1h,name=<name>

-XX:+UnlockCommercialFeatures is needed because JFR is a commercial feature in Oracle JDK 8. From JDK 11, it's no longer needed.

-XX:+FlightRecorder is not needed with -XX:StartFlightRecoding for JDK 8u40 or later. The JFR buffers are now setup when the first recording is started, not when the JVM starts. If a recording is started with defaultrecording=true, -XX:+FlightRecorder is still needed.

-XX:FlightRecorderOptions=defaultrecording=true does a lot of things, mostly for historical reasons, but only needed when doing in-memory recordings. From JDK 9, the option is never needed and has been removed.

-XX:FlightRecorderOptions=disk=true,maxage=1h isn't needed if -XX:StartFlightRecording is used, which is the recommended way to start JFR.

Unless you have an issue, I would keep the maxchunksize at the default (12 MB). It's the chunk files size JFR has been optimized for and tested against.

再见回来 2025-01-24 18:49:30

我接受Kire Haglin的答案。

为我在此JDK上有用的内容添加更多的值:

-XX:+UnlockCommercialFeatures
-XX:StartFlightRecording
  name=<foo-bar>
  maxage=12h
  dumponexit=true
-XX:FlightRecorderOptions
  dumponexitpath=<path-to-file>.jfr
  disk=true
  repository=<some-folder-path>

请注意额外的参数doldsonexitdollcoNexitpath,我的原始问题上不存在。我最终也需要那些。
经过反复试验后,xx中必须存在dollcoNexit必须存在于dompandexitpath flightrecorderoptions 争论。似乎没有其他安排可以起作用。

还要注意,删除-XX:+Flightrecorderdefaultrecording = true(如Kire所建议的) still 工作。话虽这么说,我认为defaultrecording = true的存在是触发了双重录音。
我之所以这样说,是因为发出命令jcmd&lt; pid&gt; jfr.check&lt; name&gt;我只有一个条目。

I am accepting Kire Haglin's answer.

Adding a bit more value for what worked for me on this JDK:

-XX:+UnlockCommercialFeatures
-XX:StartFlightRecording
  name=<foo-bar>
  maxage=12h
  dumponexit=true
-XX:FlightRecorderOptions
  dumponexitpath=<path-to-file>.jfr
  disk=true
  repository=<some-folder-path>

Notice the extra parameters dumponexit and dumponexitpath, not present on my original question. I ended up also needing those.
After trial and error, it appears dumponexit must exist within the XX:StartFlightRecording argument, and dumponexitpath on the FlightRecorderOptions argument. No other arrangement seems to work.

Notice also that removing -XX:+FlightRecorder and defaultrecording=true (as Kire suggested) still worked. That being said, I don't think the presence of defaultrecording=true was triggering a double recording.
I am saying this because when issuing command jcmd <PID> JFR.check <name> I only got one entry.

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