public class Example {
public static void main(String[] args) {
// print statement at the start of the program
System.out.println("Start...");
System.out.print("Number of available processors are: ");
System.out.println( Runtime.getRuntime().availableProcessors());
}
}
Ref: https://www.tutorialspoint.com/get-number-of-available-processors-in-java
When I compile and run this code on AWS ECS Fargate getting "1" as the output even though I have specified more than 1 cpu in task def(4098 for 4 vCPU).
Tested Java versions:
- Corretto-17.0.0.35.1
- Corretto-8.275.01.1
But when I do the same on AWS EC2 inside docker by allocating CPU with --cpus for "docker run" I get the exact number what I pass to --cpus. Same results with AWS EC2 with Containerd as well.
Also tested this in EKS 1.18 by setting CPU limit. It returns the number of CPUs specified in the CPU limit.
So, wondering why "1" only in AWS ECS.