Cloud Foundry CPU Core

1.2k Views Asked by At

In pivotal cloud foundry I am running a Java app with 2GB memory having 1 instance . The below code in Java prints 16 on runtime. Should I assume 16 CPU Cores available to process or this is CPU share of overall machine and each app getting share as explained here https://docs.cloudfoundry.org/concepts/container-security.html#cpu

int processors = Runtime.getRuntime().availableProcessors();
System.out.println("Available processor::"+ processors); //16

Also , What does below specifies

 cat /sys/fs/cgroup/cpu/cpu.shares
 2080
1

There are 1 best solutions below

2
On BEST ANSWER

this is CPU share of overall machine and each app getting share as explained here https://docs.cloudfoundry.org/concepts/container-security.html#cpu

Yes. It means the Diego Cell on which your app is running has 16 cores. If that Cell is completely void of any other work, you could, in theory, have access to all 16 Cells, however, that's not usually the case and when there is contention you will be throttled based on the number of CPU shares you have allocated.

cat /sys/fs/cgroup/cpu/cpu.shares 2080

This is the number of shares that you've been assigned. It is not a very meaningful number to look at because it is relative to the other applications running on the same Diego Cell as your application.

In general...

  1. The more shares you have the more CPU time you'll get.
  2. You are assigned shares based on your memory allocation, so more memory means more CPU shares.
  3. An app with more CPU shares will get more time than an app with less CPU shares.
  4. The ratio between shares is maintained, so if your app has double the shares of another app than it'll get double the amount of CPU time.

You can try using this cf cli plugin if you want to see more usable numbers. It will do some math based on your app's current usage and your CPU shares and give you the percentage of your allocation that you're being used. Including if you are bursting over your CPU usage.

It's OK to be temporarily over your CPU allocation, but you don't want to consistently be over your allocation or your application performance could suffer if some other application is scheduled onto the same Diego Cell as your application (ie. if/when contention occurs).