Configuring Cgroups

** CGroups are currently not supported when using Docker, we are aware this feature may be of interest and will add soon ** A node within a cluster is the location where tasks are run. The tasks are launched with help of a daemon which resides inside the node. This daemon, in the case of Mesos, is Mesos Slave, and in case of YARN, is NodeManager.

The Cgroups Linux kernel feature allows aggregating or partitioning a set of tasks and their future children into hierarchical groups with respect to one or more subsystems. For example, when Cgroups is enabled for the CPU subsystem, and a task is launched by Mesos Slave, it goes under the following hierarchy:

/sys/fs/cgroup/cpu/mesos/<parent-task-id>

During the lifecycle of this task, if it launches one or more children, they get mounted under the parent task’s hierarchy and can be configured to only use as much resources as the parent task is allowed to:

/sys/fs/cgroup/cpu/mesos/<parent-mesos-id>/hadoop-yarn/<child-yarn-id-1>
/sys/fs/cgroup/cpu/mesos/<parent-mesos-id>/hadoop-yarn/<child-yarn-id-2>

cgroups hierarchy

Enabling Cgroups for mesos-slave

To enable cgroups for mesos-slave, start the slave with following flag:

--isolation=cgroups/cpu,cgroups/mem

Enabling Cgroups for YARN NodeManager

Enabling Cgroups for YARN NodeManager involves:

  • Modifying the $YARN_HOME/etc/hadoop/myriad-config-default.yml file.
  • Modifying the $YARN_HOME/etc/hadoop/yarn-site.xml file.

Modify container-executor.cfg

yarn.nodemanager.linux-container-executor.group=yarn #should match yarn.nodemanager.linux-container-executor.group in yarn-site.xml
banned.users=
min.user.id=1000

Verify Permissions

The paths to container-executor.cfg and container-executor must be owned and writable only by root. The container-executor should have user-ownership by root and group ownership by the user running YARN (often yarn or hduser), which should match the yarn.nodemanager.linux-container-executor.group in yarn-site.xml and yarn.nodemanager.linux-container-executor.group in container-executor.cfg. Further the permission of container-executor should be r-Sr-s---.

chmod 6050 container-executor

If using remote distribution be sure to use the -p option of tar (as root) to perserve the suid bit.

Modify Myriad-Config-default.yml

Modify the $YARN_HOME/etc/hadoop/myriad-config-default.yml file by adding the following content:

...
frameworkSuperUser: root  # Must be root or have passwordless sudo.
nodemanager:
  cgroupPath: /path/to/cgroup # default is /sys/fs/cgroup
...

Modify yarn-site.yml

Modify the $YARN_HOME/etc/hadoop/yarn-site.xml file by adding the following content:

<!-- Cgroups configuration -->
<property>
<description>who will execute(launch) the containers.</description>
<name>yarn.nodemanager.container-executor.class</name>
<value>org.apache.hadoop.yarn.server.nodemanager.LinuxContainerExecutor</value>
</property>
<property>
<description>The class which should help the LCE handle resources.</description>
<name>yarn.nodemanager.linux-container-executor.resources-handler.class</name>
<value>org.apache.hadoop.yarn.server.nodemanager.util.CgroupsLCEResourcesHandler</value>
</property>
<property>
<name>yarn.nodemanager.linux-container-executor.group</name>
<value>yarn</value>
</property>
<property>
<name>yarn.nodemanager.linux-container-executor.path</name>
<value>${yarn.home}/bin/container-executor</value>
</property>

<!-- Optional parameters, usually unnecessary
<property>
<name>yarn.nodemanager.linux-container-executor.cgroups.mount</name>
<value>true</value>
</property>
<property>
<name>yarn.nodemanager.linux-container-executor.cgroups.mount-path</name>
<value>/sys/fs/cgroup</value>
<description>/sys/fs/cgroup and /cgroup are most common values</description>
</property>
-->