Starting and joining a lot of threads slower on AMD systems compared to Intel systems
Waishon
waishon009 at gmail.com
Sat May 15 20:15:02 UTC 2021
Hey there!
In a study project we should create 100.000 threads to get a feeling for the time it takes to create a lot of threads and why it's more efficient to use tasks instead.
However we found out, that the same "Create and start 100.000 threads" code runs a lot slower on a modern Ryzen AMD systems compared to some older (even notebook) Intel systems. We did some benchmarking with different JDKs, but all using Java 16 (older versions didn't make a difference). We know that this isn't a good "real world" example, however we would be very interested in the reason, why AMD is a lot slower in this special scenario.
public class ThreadCreator {
public static void main(String[] args) throws InterruptedException {
List<Thread> startedThreads = new ArrayList<>();
long startTime = System.currentTimeMillis();
for (int i = 0; i < 100_000; i++) {
Thread t = new Thread(() -> {});
t.start();
startedThreads.add(t);
}
for (Thread t : startedThreads) {
t.join();
}
System.out.println("Duration: " + (System.currentTimeMillis() - startTime));
}
}
The benchmark results:
AMD Ryzen 7 3700X System (Java 16, Ubuntu 20.04):
Adopt OpenJDK (Hotspot): 13882ms
Adopt OpenJDK (OpenJ9): 7521ms
Intel i7-8550U System (Fedora 34, Java 16):
Adopt OpenJDK (Hotspot): 5321ms
Adopt OpenJDK (OpenJ9): 3089ms
Intel i5-6600k System (Windows 10, Java 16):
Adopt OpenJDK (Hotspot): 29433ms (Maybe realted to low memory of this system)
Adopt OpenJDK (OpenJ9): 5119ms
The OpenJ9 JVM reduces the time on both systems to nearly the half. However the AMD system never reaches the time of the Intel systems. The AMD system only runs at 10% cpu utilisation during this test.
What might be the reason why starting and joining threads is so much slower on AMD systems compared to Intel systems?
(Disclaimer: This question was also posted on Stackoverflow, which referred to this mailing list: https://stackoverflow.com/questions/67550679/creating-threads-is-slower-on-amd-systems-compared-to-intel-systems)
Thank you very much in advance!
More information about the discuss
mailing list