Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2190,6 +2190,15 @@ public static boolean isAclEnabled(Configuration conf) {
public static final boolean DEFAULT_NM_LINUX_CONTAINER_CGROUPS_STRICT_RESOURCE_USAGE =
false;

/**
* In case of strict resource usage provide capability to capped cpu resource
* usage by <code>DEFAULT_NM_LINUX_CONTAINER_CGROUPS_CAPPED_MULTIPLIER</code>
* times the requested one
*/
public static final String NM_LINUX_CONTAINER_CGROUPS_CAPPED_MULTIPLIER =
NM_PREFIX + "linux-container-executor.cgroups.capped-multiplier";
public static final float DEFAULT_NM_LINUX_CONTAINER_CGROUPS_CAPPED_MULTIPLIER =
1.0f;

// Configurations for applicaiton life time monitor feature
public static final String RM_APPLICATION_MONITOR_INTERVAL_MS =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,16 @@
<value>false</value>
</property>

<property>
<description>If yarn.nodemanager.linux-container-executor.cgroups.strict-resource-usage
is set to true this flag determines how many times their share of CPU they can use. For
example setting it to 1.0f will restrict apps to use only their share of CPU but setting it to 2.0f
will authorize apps to use up to 2 times their share of CPU.
</description>
<name>yarn.nodemanager.linux-container-executor.cgroups.capped-multiplier</name>
<value>1.0f</value>
</property>

<property>
<description>Comma separated list of runtimes that are allowed when using
LinuxContainerExecutor. The allowed values are default, docker, and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public class CgroupsLCEResourcesHandler implements LCEResourcesHandler {

private float yarnProcessors;
private int nodeVCores;
private float cappedMultiplier;

public CgroupsLCEResourcesHandler() {
this.controllerPaths = new HashMap<String, String>();
Expand Down Expand Up @@ -138,13 +139,16 @@ void initConfig() throws IOException {
.NM_LINUX_CONTAINER_CGROUPS_STRICT_RESOURCE_USAGE,
YarnConfiguration
.DEFAULT_NM_LINUX_CONTAINER_CGROUPS_STRICT_RESOURCE_USAGE);
this.cappedMultiplier = conf.getFloat(
YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_CAPPED_MULTIPLIER,
YarnConfiguration.DEFAULT_NM_LINUX_CONTAINER_CGROUPS_CAPPED_MULTIPLIER);

int len = cgroupPrefix.length();
if (cgroupPrefix.charAt(len - 1) == '/') {
cgroupPrefix = cgroupPrefix.substring(0, len - 1);
}
}

public void init(LinuxContainerExecutor lce) throws IOException {
this.init(lce,
ResourceCalculatorPlugin.getResourceCalculatorPlugin(null, conf));
Expand Down Expand Up @@ -334,8 +338,8 @@ private void setupLimits(ContainerId containerId,
String.valueOf(cpuShares));
if (strictResourceUsageMode) {
if (nodeVCores != containerVCores) {
float containerCPU =
(containerVCores * yarnProcessors) / (float) nodeVCores;
float containerVCoresCapped = Math.min(containerVCores * cappedMultiplier, nodeVCores);
float containerCPU = (containerVCoresCapped * yarnProcessors) / (float) nodeVCores;
int[] limits = getOverallLimits(containerCPU);
updateCgroup(CONTROLLER_CPU, containerName, CPU_PERIOD_US,
String.valueOf(limits[0]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,29 @@ public void testContainerLimits() throws IOException {
Assert.assertEquals(500 * 1000, readIntFromFile(periodFile));
Assert.assertEquals(1000 * 1000, readIntFromFile(quotaFile));

// 1/8 of CPU with multiplier set at 2
FileUtils.deleteQuietly(containerCpuDir);
conf.setBoolean(
YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_STRICT_RESOURCE_USAGE,
true);
conf.setFloat(
YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_CAPPED_MULTIPLIER,
2.0f);
handler.initConfig();
handler.preExecute(id,
Resource.newInstance(1024, YarnConfiguration.DEFAULT_NM_VCORES / 8));
Assert.assertTrue(containerCpuDir.exists());
Assert.assertTrue(containerCpuDir.isDirectory());
periodFile = new File(containerCpuDir, "cpu.cfs_period_us");
quotaFile = new File(containerCpuDir, "cpu.cfs_quota_us");
Assert.assertTrue(periodFile.exists());
Assert.assertTrue(quotaFile.exists());
Assert.assertEquals(1000 * 1000, readIntFromFile(periodFile));
Assert.assertEquals(1000 * 1000, readIntFromFile(quotaFile));

// CGroups set to 50% of CPU, container set to 50% of YARN CPU
FileUtils.deleteQuietly(containerCpuDir);
conf.unset(YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_CAPPED_MULTIPLIER);
conf.setBoolean(
YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_STRICT_RESOURCE_USAGE,
true);
Expand Down