Skip to content

Commit

Permalink
demonstrate jdk cgroup bug - incl mem
Browse files Browse the repository at this point in the history
  • Loading branch information
s50600822 committed Feb 29, 2024
1 parent 4cf98f8 commit e9f0ba9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions vs/java/cgroup/CgroupConfigPrinter.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import java.lang.management.ManagementFactory;
import com.sun.management.OperatingSystemMXBean;

public class CgroupConfigPrinter {
public static void main(String[] args) {
int availableProcessors = Runtime.getRuntime().availableProcessors();
Expand All @@ -14,5 +17,13 @@ public static void main(String[] args) {
System.out.println("Available Memory (Total): " + totalMemoryMB + " MB");
System.out.println("Available Memory (Free): " + freeMemoryMB + " MB");
System.out.println("Maximum Memory (Allocated): " + maxMemoryMB + " MB");

OperatingSystemMXBean osBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();

// deprecated in favor of getTotalMemorySize(), however new method is not avail on JDK8
// keeps this so we can test against 8 and above
long totalSystemMemoryBytes = osBean.getTotalPhysicalMemorySize();
long totalSystemMemoryMB = totalSystemMemoryBytes / (1024 * 1024);
System.out.println("Total System Memory: " + totalSystemMemoryMB + " MB");
}
}
Binary file modified vs/java/cgroup/application.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion vs/java/cgroup/runWithDocker.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
docker run --rm --cpus=2 --memory=256m --name jvm_cgroup_demo_openjdk21 -v .:/app openjdk:21 java -Xmx256m -Xms256m -jar /app/application.jar
docker run --rm --cpus=2 --memory=512m --name jvm_cgroup_demo_openjdk21 -v .:/app openjdk:21 java -Xmx256m -Xms256m -jar /app/application.jar
2 changes: 1 addition & 1 deletion vs/java/cgroup/runWithDockerJ8.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
## show that cgroup for CPU lim isn't respected
docker run --rm --cpus=2 --memory=256m --name jvm_cgroup_demo_openjdk8 -v .:/app openjdk:8 java -Xmx256m -Xms256m -jar /app/application.jar
docker run --rm --cpus=2 --memory=512m --name jvm_cgroup_demo_openjdk8 -v .:/app openjdk:8 java -Xmx256m -Xms256m -jar /app/application.jar

0 comments on commit e9f0ba9

Please sign in to comment.