Red Hat Training

A Red Hat training course is available for Red Hat Enterprise Linux

Chapter 4. Control Group Application Examples

This chapter provides application examples that take advantage of the cgroup functionality.

4.1. Prioritizing Database I/O

Running each instance of a database server inside its own dedicated virtual guest allows you to allocate resources per database based on their priority. Consider the following example: a system is running two database servers inside two KVM guests. One of the databases is a high priority database and the other one a low priority database. When both database servers are run simultaneously, the I/O throughput is decreased to accommodate requests from both databases equally; Figure 4.1, “I/O throughput without resource allocation” indicates this scenario — once the low priority database is started (around time 45), I/O throughput is the same for both database servers.
I/O throughput without resource allocation

Figure 4.1. I/O throughput without resource allocation

To prioritize the high priority database server, it can be assigned to a cgroup with a high number of reserved I/O operations, whereas the low priority database server can be assigned to a cgroup with a low number of reserved I/O operations. To achieve this, follow the steps in Procedure 4.1, “I/O throughput prioritization”, all of which are performed on the host system.

Procedure 4.1. I/O throughput prioritization

  1. Attach the blkio subsystem to the /cgroup/blkio cgroup:
    ~]# mkdir /cgroup/blkio
    ~]# mount -t cgroup -o blkio blkio /cgroup/blkio
  2. Create a high and low priority cgroup:
    ~]# mkdir /cgroup/blkio/high_prio
    ~]# mkdir /cgroup/blkio/low_prio
  3. Acquire the PIDs of the processes that represent both virtual guests (in which the database servers are running) and move them to their specific cgroup. In our example, VM_high represents a virtual guest running a high priority database server, and VM_low represents a virtual guest running a low priority database server. For example:
    ~]# ps -eLf | grep qemu | grep VM_high | awk '{print $4}' | while read pid; do echo $pid >> /cgroup/blkio/high_prio/tasks; done
    ~]# ps -eLf | grep qemu | grep VM_low | awk '{print $4}' | while read pid; do echo $pid >> /cgroup/blkio/low_prio/tasks; done
  4. Set a ratio of 10:1 for the high_prio and low_prio cgroups. Processes in those cgroups (that is, processes running the virtual guests that have been added to those cgroups in the previous step) will immediately use only the resources made available to them.
    ~]# echo 1000 > /cgroup/blkio/high_prio/blkio.weight
    ~]# echo 100 > /cgroup/blkio/low_prio/blkio.weight
    In our example, the low priority cgroup permits the low priority database server to use only about 10% of the I/O operations, whereas the high priority cgroup permits the high priority database server to use about 90% of the I/O operations.
Figure 4.2, “I/O throughput with resource allocation” illustrates the outcome of limiting the low priority database and prioritizing the high priority database. As soon as the database servers are moved to their appropriate cgroups (around time 75), I/O throughput is divided among both servers with the ratio of 10:1.
I/O throughput with resource allocation

Figure 4.2. I/O throughput with resource allocation

Alternatively, block device I/O throttling can be used for the low priority database to limit its number of read and write operation. For more information on the blkio subsystem, refer to Section 3.1, “blkio”.