Garbage Collector Log (Loggc) File Rotation with Logrotate Does Not Work Properly

Garbage collector log (loggc) file rotation with logrotate does not work properly

We had the same problem at our place running Jboss7 and Java6, we were getting NULLs in the GC file and they just kept growing.

Solution was to just log GC to stdout and then append stdout to a file:

Simple example:

java -verbose:gc >> console.log

Apparently using append (>>) gets rid of the Java "pointer" to a position in the file. With the added bonus of not having the GC logs reset per server restart so we can have some stats over time.

At least the IBM PMAT tool has no problem parsing the sysout with GC output.

The simplest solution is sometimes the best :)

Though I wish Java would support rotating of GC logs, as I see someone's been discussing before:
http://mail.openjdk.java.net/pipermail/hotspot-runtime-dev/2011-April/002061.html

JVM gc log not rotating

It seems you've already figured that out yourself. GCLogFileSize has the minimum value of 8KB in JDK, even if you try to set less. Here is the relevant fragment from HotSpot sources:

  if (UseGCLogFileRotation && (GCLogFileSize != 0) && (GCLogFileSize < 8*K)) {
FLAG_SET_CMDLINE(uintx, GCLogFileSize, 8*K);
jio_fprintf(defaultStream::output_stream(),
"GCLogFileSize changed to minimum 8K\n");
}

Rolling garbage collector logs in java

Built-in support for GC log rotation has been added to the HotSpot JVM.
It is described in the RFE 6941923 and is available in:

  • Java 6 Update 34
  • Java 7 Update 2 (but there is no reference to it in these release notes)

There are three new JVM flags that can be used to enable and configure it:

  • -XX:+UseGCLogFileRotation
    must be used with -Xloggc:<filename>;
  • -XX:NumberOfGCLogFiles=<number of files>
    must be >=1, default is one;
  • -XX:GCLogFileSize=<number>M (or K)
    default will be set to 512K.

GC log rotation data lose on application restart

You can also use java own timestamps for that:

java -Xloggc:gc-%t.log ...(rest of your line)...

%t will be replaced with a timestamp by java (see https://bugs.openjdk.java.net/browse/JDK-6950794 for information and other formats supported by -Xloggc



Related Topics



Leave a reply



Submit