2

As we can limit the CPU resources for the containers on Docker (--cpus cmd) as well as Kubernetes (-cpulimit) platform.

Is there any way to limit the CPU for application running on PCF?

sush
  • 95
  • 2
  • 8

1 Answers1

4

This happens automatically on Cloud Foundry.

Applications that run on Cloud Foundry are limited based on CPU shares (same as docker's --cpu-shares option). The number of CPU shares assigned to an application is propotionate to the size of the memory limit given to the application. More memory means more CPU shares.

The exact number of shares doesn't really matter, its just the proportions that matter. If your app has a larger number of shares than other apps running on the Cell, it'll get more CPU time. If it has a smaller number of shares, it'll get less time. You can use the memory limits to gauge if an app is smaller, the same or larger than other apps running on the Cell.

The tricky part is that there's no easy way to tell what else is running on the Cell, short of being an operator and looking at the Cells. Hopefully, CPU share information and throttling metrics will be exposed through Loggregator in the future, as this would make it easier to understand how your app is utilizing the CPU time it gets.

If you want to see the exact formula used to determine CPU shares, you can check out this documentation link. It goes into more depth explaining how the platform makes these calculations.

https://docs.cloudfoundry.org/concepts/container-security.html#cpu

It's not currently possible to limit CPU usage based on the number of CPU cores, like Docker's --cpus argument.

Daniel Mikusa
  • 13,716
  • 1
  • 22
  • 28
  • Thanks Daniel for very clear answer. Just wanted to ask one more question as per the documentation I can see CPU% is calculated based on the memory and CPU shares. But where i get to know how many shares are allocated for my container? Accordingly I can pedict the CPU% allocated for my container. – sush Apr 12 '18 at 10:05
  • That information, the exact number of shares, isn't exposed to end users/developers, at least not at the moment. If you wanted to see this now, you'd need operator level access and you'd need to SSH to the Diego Cell where your app is running. Hopefully, more CPU metrics are exposed in the future, including this one. – Daniel Mikusa Apr 13 '18 at 10:36
  • is it also possible to limit I/O? – Sybil Apr 15 '18 at 15:06
  • There's a limit on the number of files you can write (i.e. disk quota), but not the speed at which you can write them (as of me writing this). – Daniel Mikusa Apr 17 '18 at 11:36