How to limit disk space usage for JFR recording dumps (in a Docker container)?

Viewed 186

I start continous flight regarding for my app like this:

java -XX:StartFlightRecording:filename=jfr-logs/ ...

Everytime the app is stopped, a new file is generated in the jfr-logs directory:

ls -l jfr-logs
-rw-r--r--  1 jumar  staff   2.2M Dec 13 09:28 hotspot-pid-57471-id-1-2021_12_13_09_28_01.jfr
-rw-r--r--  1 jumar  staff   1.0M Dec 13 09:28 hotspot-pid-57923-id-1-2021_12_13_09_28_19.jfr

I'd like to make sure thare are no more than X number of these files and/or that they don't consume more than Y MBs of disk space.

I run this app in a Docker container and the jfr-logs directory is stored on a persistent volume.

1 Answers

You can set the max size of a recording, but it's more of minimum size, because it is the size at which JFR will rotate the file, so it might be exceeded with a few MB.

Example:

 java -XX:StartFlightRecording:maxsize=50MB,filename=jfr-logs/ ...

By default, JFR uses a maxsize of 250 MB.

There is no way to limit the number of files, but it's possible to set the max chunk size, which is the size at which the chunk file will be rotated, possibly exceeded with a few MB.

-XX:FlightRecorderOptions:maxchunksize=20MB

The default size is 12 MB, and it is recommended to keep as is, unless there is an issue.

  • Setting it too low, will increase overhead due to additional rotations and less reuse of reoccurring constants.

  • Setting it too high might result in additional overhead and memory usage when parsing the file.

All testing of JFR has be done with the default max chunk size.

Related