4 ms·
The Java tests (Loom in particular), and possibly other langauge runtimes too in this benchmark, can't be compared without looking at the runtime settings. JVM
by brunoborges 3y ago
The Java tests (Loom in particular), and possibly other langauge runtimes too in this benchmark, can't be compared without looking at the runtime settings.
JVM for example has a default heap size of 25% to 50%, depending on how much memory is available in the system. Given that the code is using ArrayList, there will be more need for bigger heap, due to array expansion. To eliminate that noise, the code should be changed to a pure Thread[] array with a fixed size based on numTasks.
Once that is done, you may as well run up to 10_000 tasks (virtual threads) within a JVM that consumes no more than 32 MB of RAM (compared to 78MB as originally reported by OP).
These were the best results I could find after playing a bit:
# Run single task
docker run --memory 26m --rm java-virtual-threads 1
# Run 10 tasks
docker run --memory 26m --rm java-virtual-threads 10
# Run 100 tasks
docker run --memory 26m --rm java-virtual-threads 100
# Run 1_000 tasks
docker run --memory 28m --rm java-virtual-threads 1000
# Run 10_000 tasks
docker run --memory 32m -e JAVA_TOOL_OPTIONS=-Xmx25m --rm java-virtual-threads 10000
# Run 100_000 tasks
docker run --memory 200m -e JAVA_TOOL_OPTIONS=-Xmx175m --rm java-virtual-threads 100000
# Run 1_000_000 tasks
docker run --memory 950m -e JAVA_TOOL_OPTIONS=-Xmx750m --rm java-virtual-threads 1000000