Scott Skiles
Scott Skiles

Reputation: 3847

How to get zGC allocation stall times from the JVM?

How can I get the total allocation stall time due to zGC Garbage Collection in my Java application from the JVM (not the gc.log)?

I saw this interesting answer: https://stackoverflow.com/a/13915440/992432, but looking at the the docs for GarbageCollectorMXBean there are only two methods, neither of which seems to differentiate between general time spent and time the Java application had to stop to GC:

Method Summary

long getCollectionCount() - Returns the total number of collections that have occurred.

long getCollectionTime() - Returns the approximate accumulated collection elapsed time in milliseconds.

What I really want to know is the time spent as full allocation stalls due to GCs (note I do not care about safepointed times). As this article says in Java Magazine:

Many garbage collection algorithms have been tried and tested over the years, iteratively improving their performance. There are two common areas of performance for such algorithms The first is garbage collection throughput: How much of your application’s CPU time is spent performing garbage collection work rather than running application code? The second is the delay created—that is, the latency of individual pauses.

Any assistance would be greatly appreciated.

Upvotes: 4

Views: 771

Answers (1)

ddaa
ddaa

Reputation: 49

I'm not sure if there is an interface in java that can do this. After all, the logic of ZGC is that when a java thread fails to apply for more memory, the java thread will send an async request to GC to ask for a collection and it will wait until the heap space is sufficient for the allocation request. So technically it's not the typical stop-the-world time of a GC.

However, if you want to get such values through GC logs, you can use

-Xlog:gc*=info:gc.log:time:filecount=0

in your java options.

In this way, you can get logs like:

[2024-07-28T11:59:57.277+0000] Allocation Stall (Thread-3) 57.889ms
[2024-07-28T11:59:57.277+0000] Allocation Stall (Thread-19) 57.719ms
[2024-07-28T11:59:57.277+0000] Allocation Stall (Thread-7) 57.601ms
[2024-07-28T11:59:57.277+0000] Allocation Stall (Thread-6) 57.815ms
[2024-07-28T11:59:57.277+0000] Allocation Stall (Thread-18) 57.848ms

Such statistics can be used for analysis.

Upvotes: 0

Related Questions