Skip to content

Java 21 on Google Cloud for Overly Enthusiastic Developers

Michael O'Brien edited this page Oct 10, 2023 · 3 revisions

21 is out....https://www.oracle.com/java/technologies/downloads/#jdk21-windows see https://github.com/ObrienlabsDev/blog/issues/16

Java 21 performance for BigInteger is 1.5x Java 17

The following code computes distributed collatz (3n+1) using ForkJoin using a queue of decreasing threads across all 12 vCores in this example. The sweet spot is 2x cores or 16 threads. Single core performance is at the end 11 to 2.5% faster depending on parallelization. This example was on a Xeon W-10855 2.8 to 4.5 GhZ

Longer times are worse performance

Java 17 full parallelization 6/12 cores = 14.2 sec Java 17 single core = 44.8 sec Java 21 full parallelization 6/12 cores = 12.7 sec Java 21 single core = 43.7 sec Java 21 multi core is 11% faster than Java 17 or (~5x single core improvement on a 6 core CPU) Java 21 single core is 2.5% faster than Java 17

JDK 17
PS C:\_dev> java -cp org.obrienscience.collatz.server.ForkJoinCollatzServer.jar org.obrienscience.collatz.server.ForkJoinCollatzServer 5 6 1
ForkJoinCollatzServer forkJoinPool-power-start end runs (v 20161009)
availableProc   : 12
fjps threads    : 5,6
freeMemory()    : 2141443600
maxMemory()     : 32178700288
totalMemory()   : 2147483648
Range: bits     : 25
14219,5,22,1422,8
17290,5,21,1721,16
14359,5,20,1420,32
14266,5,19,1419,64
14266,5,18,1418,128
14279,5,17,1417,256
14265,5,16,1416,512
14321,5,15,1415,1024
14297,5,14,1414,2048
14360,5,13,1413,4096
14331,5,12,1412,8192
14294,5,11,1411,16384
14314,5,10,1410,32768
14315,5,9,149,65536
14402,5,8,148,131072
14331,5,7,147,262144
14470,5,6,146,524288
14329,5,5,145,1048576
14911,5,4,144,2097152
15093,5,3,153,4194304
19489,5,2,192,8388608
33272,5,1,331,16777216
44794,5,0,440,33554432

JDK 21
PS C:\_dev> c:\jdk21\bin\java -cp org.obrienscience.collatz.server.ForkJoinCollatzServer.jar org.obrienscience.collatz.server.ForkJoinCollatzServer 5 6 1
ForkJoinCollatzServer forkJoinPool-power-start end runs (v 20161009)

17281,5,22,1722,8
20398,5,21,2021,16
12774,5,20,1220,32
12773,5,19,1219,64
12725,5,18,1218,128
12803,5,17,1217,256
12760,5,16,1216,512
12726,5,15,1215,1024
12743,5,14,1214,2048
12710,5,13,1213,4096
12741,5,12,1212,8192
12727,5,11,1211,16384
12808,5,10,1210,32768
12771,5,9,129,65536
12761,5,8,128,131072
12819,5,7,127,262144
12899,5,6,126,524288
12823,5,5,125,1048576
12916,5,4,124,2097152
12754,5,3,123,4194304
14129,5,2,142,8388608
25227,5,1,251,16777216
43744,5,0,430,33554432
Clone this wiki locally