blkio limits the iops of the container

principle

To limit the IOPS (Input/Output Operations Per Second) of a container, you can use the blkio control group (cgroup) in the Linux kernel. blkio cgroups allow you to allocate a certain amount of I/O resources per cgroup.

Here are the steps to limit the IOPS of a container:

  1. Create a cgroup to limit the I/O resources of the container. You can cgcreatecreate cgroups with commands such as:
sudo cgcreate -g blkio:/cgroup/blkio_limit
  1. Set the IOPS limit. In the /cgroup/blkio_limit/blkio.throttle.read_iops_deviceand /cgroup/blkio_limit/blkio.throttle.write_iops_devicefile, you can specify read and write IOPS limits for each device. For example, if you want to limit a device /dev/sdato 100 IOPS for read operations and 50 IOPS for write operations, you can execute the following command:
echo "8:0 100" | sudo tee /cgroup/blkio_limit/blkio.throttle.read_iops_device
echo "8:0 50" | sudo tee /cgroup/blkio_limit/blkio.throttle.write_iops_device

Here, "8:0" indicates the major and minor numbers of the device.

  1. Add the container to the cgroup. Use cgclassifythe command to add the container's process to the previously created cgroup. For example:
sudo cgclassify -g blkio:/cgroup/blkio_limit <容器PID>

where <容器PID>is the process ID of the container.

With these steps, you can successfully limit the IOPS of the container. Note that these restrictions only apply to container processes that use cgroups for classification.

exceed the limit

When a container's IOPS exceeds the limit, the specific behavior depends on the container management tool and operating system you use. Generally, when the IOPS of a container exceeds the limit, one of the following situations may occur:

  1. I/O requests are delayed: If the container's IOPS exceeds the limit, the operating system may queue the container's I/O requests for execution. This causes the I/O operations of the container to become slower and the response time increases.

  2. I/O requests are dropped: In some cases, the operating system may choose to drop a portion of a container's I/O requests to ensure the normal operation of other processes or containers. This may result in data loss or execution failure.

  3. Container process being terminated: Some container management tools may monitor a container's resource usage and terminate the container process if the IOPS limit is exceeded to prevent adverse impact on other containers or the system.

Note that exact behavior may vary across different operating systems, container management tools, and configurations. Therefore, it is recommended to consult the relevant documentation or refer to the specific documentation of the operating system and container management tool for more details.

Guess you like

Origin blog.csdn.net/hezuijiudexiaobai/article/details/131620232