背景

当前项目的私有云环境中,采用Ceph作为统一的后端存储。由于业务的种类繁多,经常会有部分虚机在某个时间段将宿主网卡吃满的情况。比如用户在VM内做大文件的拷贝,或者环境更新等。所以有必要对VM的I/O进行一定的资源限制,防止单宿主上VM间的网络I/O争抢。

Ceph RBD QoS

Qemu与KVM均提供对网络资源的限制支持,使用libvirt封装的接口可以更方便的实现对rbd设备的资源限制。 libvirt提供如下选项:

  • total_bytes_sec: 混合模式下的带宽限制
  • read_bytes_sec: 顺序读带宽
  • write_bytes_sec: 顺序写带宽
  • total_iops_sec: 混合模式下的IOPS限制
  • read_iops_sec: 随机读IOPS
  • write_iops_sec: 随机写IOPS

使用方法很简单:

1
2
3
4
5
6
7
8
9
10
11
12
13
  
    <disk type='network' device='disk'>
      <driver name='qemu' type='raw' cache='writethrough'/>
      ...
      <source protocol='rbd' name='[pool_name]/[image_name]'>
      ...
      </source>
      <iotune>
        <read_iops_sec>20</read_iops_sec>
        <write_iops_sec>10</write_iops_sec>
      </iotune>

    ...

在XML文件中添加<iotune>标签,并设置相应的限制值即可

Test

针对上述例子,在VM内部使用FIO测试对IOPS的限制

随机读

> fio -filename=/dev/vdc1 -direct=1 -iodepth 1 -thread -rw=randread -ioengine=psync -bs=4k -size=200M -numjobs=30 -runtime=10 -group_reporting -name=randread_test

随机读IOPS

随机写

> fio -filename=/dev/vdc1 -direct=1 -iodepth 1 -thread -rw=randwrite -ioengine=psync -bs=4k -size=200M -numjobs=30 -runtime=10 -group_reporting -name=randwrite_test

随机写IOPS

从测试可以看出,libvirt的接口可以很好地提供对RBD资源的限制

References

[1] OpenStack, Ceph RBD and QoS

[2] Amazon EBS Volume Types

[3] linux 使用FIO测试磁盘iops