Java: Limit the number of cores a JVM can use

javamulti-corethreads

Multiple users are running java applications on a 60-core compute server (Linux/Ubuntu-based). There are different applications and most of them are not developed in-house.

While the sysadmin thinks it is okay for a given user's Java process to use 10 cores at any given moment, she would like them not to use more than 10.

Is there any Java or OS configuration which can be used to prevent the process from just grabbing compute resource in an unlimited way?

Best Answer

On the OS front:

  • I would say the the classical method is to set CPU affinity with taskset.

  • A better alternative is to use cgroups.

  • And the buzz-word solution is to run your applications in Docker containers. However, prior to Java 8, the JVM is not able to understand the limitations imposed by Docker (only available after 8u131+ backported, not sure if it is available as experimental in Java9 for the CPU part but it is for memory, and fully available in Java10)

Related Topic