Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blog Post: Understanding Garbage Collector Performance #4244

Merged
merged 12 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions blog/modules/ROOT/attachments/GC-bench.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
val liveSets = Seq(400, 800, 1600, 3200, 6400)
val heapSizes = Seq(800, 1600, 3200, 6400, 12800)
val lists = for (liveSet <- liveSets) yield {
for (heapSize <- heapSizes) yield {
if (liveSet >= heapSize) ("", "")
else {
println(s"Benchmarking liveSet=$liveSet heapSize=$heapSize")
val javaBin = os.Path(sys.env("JAVA_HOME")) / "bin"/"java"
val res = os.proc(javaBin, s"-Xmx${heapSize}m", "-XX:+UseZGC", "GC.java", liveSet, 10000, 5)
.call(check = false)

res.out.lines().collectFirst { case s"longest-gc: $n, throughput: $m" => (n, m) }
.getOrElse(sys.error(res.err.text()))
}
}
}

def renderTable(lists: Seq[Seq[String]]) = {
def printRow(x: Seq[String]) = println(x.map(s => s"| $s ").mkString)
printRow(Seq("live-set\\heap-size") ++ heapSizes.map(_ + " mb"))
for ((liveSet, list) <- liveSets.zip(lists)) printRow(Seq(liveSet + " mb") ++ list)
}

renderTable(lists.map(_.map(_._1)))
renderTable(lists.map(_.map(_._2)))
52 changes: 52 additions & 0 deletions blog/modules/ROOT/attachments/GC.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
public class GC {
public static void main(String[] args) throws Exception{
final long liveSetByteSize = Integer.parseInt(args[0]) * 1000000L;
final int benchMillis = Integer.parseInt(args[1]);
final int benchCount = Integer.parseInt(args[2]);
// 0-490 array entries per object, * 4-bytes per entry,
// + 20 byte array header = average 1000 bytes per entry
final int maxObjectSize = 490;
final int averageObjectSize = (maxObjectSize / 2) * 4 + 20;

final int liveSetSize = (int)(liveSetByteSize / averageObjectSize);

long maxPauseTotal = 0;
long throughputTotal = 0;

for(int i = 0; i < benchCount + 1; i++) {
int chunkSize = 256;
Object[] liveSet = new Object[liveSetSize];
for(int j = 0; j < liveSetSize; j++) liveSet[j] = new int[j % maxObjectSize];
System.gc();
long maxPause = 0;
long startTime = System.currentTimeMillis();

long loopCount = 0;
java.util.Random random = new java.util.Random(1337);
int liveSetIndex = 0;

while (startTime + benchMillis > System.currentTimeMillis()) {
if (loopCount % liveSetSize == 0) Thread.sleep(1);
long loopStartTime = System.currentTimeMillis();
liveSetIndex = random.nextInt(liveSetSize);
liveSet[liveSetIndex] = new int[liveSetIndex % maxObjectSize];
long loopTime = System.currentTimeMillis() - loopStartTime;
if (loopTime > maxPause) maxPause = loopTime;
loopCount++;
}
if (i != 0) {
long benchEndTime = System.currentTimeMillis();
long bytesPerLoop = maxObjectSize / 2 * 4 + 20;
throughputTotal += (long) (1.0 * loopCount * bytesPerLoop / 1000000 / (benchEndTime - startTime) * averageObjectSize);
maxPauseTotal += maxPause;
}

System.out.println(liveSet[random.nextInt(liveSet.length)]);
}

long maxPause = maxPauseTotal / benchCount;
long throughput = throughputTotal / benchCount;

System.out.println("longest-gc: " + maxPause + " ms, throughput: " + throughput + " mb/s");
}
}
Binary file added blog/modules/ROOT/images/G1GC.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blog/modules/ROOT/images/ParallelGC.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blog/modules/ROOT/images/ParallelGC12800.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blog/modules/ROOT/images/ParallelGC200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blog/modules/ROOT/images/ParallelGC3200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blog/modules/ROOT/images/ParallelGC800.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions blog/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

* xref:6-garbage-collector-perf.adoc[]
* xref:5-executable-jars.adoc[]
* xref:4-flaky-tests.adoc[]
* xref:3-selective-testing.adoc[]
Expand Down
Loading
Loading