Video in progress
When running a JVM with a big heap on a multi-socket (NUMA) server, what do you pay attention to, and what does -XX:+UseNUMA give you?
In NUMA each processor socket has its own memory, and accessing another socket's memory is slower. With -XX:+UseNUMA the JVM allocates objects close to the socket of the thread that created them. Parallel, G1 (JDK 14+) and ZGC support it. Often a simpler solution is a separate, smaller JVM per socket.
📖 Answer
Take a two-socket server with, say, 512 GB of memory, 256 GB on each socket. If a core on socket 0 reads socket 1's memory, the latency is roughly 1.5-2 times higher and bandwidth is limited. If the JVM doesn't know about this, the heap is spread randomly over both sides and threads constantly go to "far" memory.
To check:
numactl --hardware # how many nodes, how much memory on each
numastat -p <pid> # the process's memory per node
perf stat -e node-load-misses ...
The options:
-
-XX:+UseNUMA. Eden is split across NUMA nodes, and a thread allocates from the part on its own node. Young objects are usually the ones that thread uses, so locality improves. It is most mature in Parallel GC, in G1 from JDK 14 (JEP 345), and ZGC takes NUMA into account on its own. The benefit depends on the load: from a few percent up to 20-30% in memory-heavy applications. -
One JVM per socket.
numactl --cpunodebind=0 --membind=0 java -Xmx200g ... &
numactl --cpunodebind=1 --membind=1 java -Xmx200g ... &
Everything is local, and the GC also works with a smaller heap. But the application has to be splittable (stateless or sharded).
- In Kubernetes, use the kubelet's Topology Manager and CPU Manager (
staticpolicy) to place the pod on a single NUMA node. This is a node-level setting, to be done with the platform team.
When you don't need it at all: on ordinary cloud VMs (often a single NUMA node) and in services with 4-8 GB heaps. This is an issue for big in-memory systems on bare metal or large instances. As always, first show with numastat that there is a problem.
Sign up to mark studied questions and save your progress.