YARN currently lets you define an NM's pcore count, and a pcore:vcore ratio. Containers are then allowed to request vcores between the minimum and maximum defined in the yarn-site.xml.
In the case where a single-threaded container requests 1 vcore, with a pcore:vcore ratio of 1:4, the container is still allowed to use up to 100% of the core it's using, provided that no other container is also using it. This happens, even though the only guarantee that YARN/CGroups is making is that the container will get "at least" 1/4th of the core.
If a second container then comes along, the second container can take resources from the first, provided that the first container is still getting at least its fair share (1/4th).
There are certain cases where this is desirable. There are also certain cases where it might be desirable to have a hard limit on CPU usage, and not allow the process to go above the specified resource requirement, even if it's available.
Here's an RFC that describes the problem in more detail:
As it happens, when CFS is used in combination with CGroups, you can enforce a ceiling using two files in cgroups:
The usage of these two files is documented in more detail here:
I have tested YARN CGroups using the 2.0.5-alpha implementation. By default, it behaves as described above (it is a soft cap, and allows containers to use more than they asked for). I then tested CFS CPU quotas manually with YARN.
First, you can see that CFS is in use in the CGroup, based on the file names:
Oddly, it appears that the cfs_period_us is set to .1s, not 1s.
We can place processes in hard limits. I have process 4370 running YARN container container_1371141151815_0003_01_000003 on a host. By default, it's running at ~300% cpu usage.
When I set the CFS quote:
It drops to 1% usage, and you can see the box has room to spare:
Turning the quota back to -1:
Burns the cores again:
On my dev box, I was testing CGroups by running a python process eight times, to burn through all the cores, since it was doing as described above (giving extra CPU to the process, even with a cpu.shares limit). Toggling the cfs_quota_us seems to enforce a hard limit.
What do you guys think about introducing a variable to YarnConfiguration:
The default would be false. Setting to true, would cause YARN's LCE to set:
For example, if a container asks for 2 vcores, and the vcore:pcore ratio is 4, you'd get:
This would cause CFS to cap the process at 50% of clock cycles.
What do you guys think?
1. Does this seem like a reasonable request? We have some use-cases for it.
2. It's unclear to me how cpu.shares interacts with cpu.cfs_*. I think the ceiling is hard, no matter what shares is set to. I assume shares only comes into play if the CFS quota has not been reached, and the process begins competing with others for CPU resources.
3. Should this be an LCE config (yarn.nodemanager.linux-container-executor), or should it be a generic scheduler config (yarn.scheduler.enforce-ceiling-vcores).