• 使用cgroup限制磁盘io读写速率


    在MySQL innobackupex全备期间,磁盘io基本被打满,设置过 --throttle效果不明显,

      --throttle=#        This option specifies a number of I/O operations (pairs
                          of read+write) per second.  It accepts an integer
                          argument.  It is passed directly to xtrabackup's
                          --throttle option.
    

    以下是使用cgroup方式进行io读写的限制测试

    1. 安装和启动cgroup

    【centos6】
    yum install libcgroup
    service cgconfig start
    
    【centos7】
    yum install -y libcgroup-tools.x86_64
    systemctl start cgconfig

     

    说明:

    centos6的cgroup挂载在/cgroup对应的路径下

    centos7的cgroup挂载在/sys/fs/cgroup对应的路径下

    可使用lssubsys -M 或者lssubsys -am命令查看

    2. 设置测试的磁盘盘符和读写速率限制

    io_read_limit=1048576
    io_write_limit=1024
    #比如我测试的读写文件都发生在/data文件系统里
    
    filesystem_mounted='/data'
    
    lsblk -d -n | awk '{print $1}' >all_disks
    
    while read line
    do
    aaa=$(df -h | grep -w ${filesystem_mounted} | grep $line)
    if [[ ! -z aaa ]];then
        disk_name=$line
    fi
    done < all_disks
    
    #echo $disk_name
    

     说明:以上主要是为了获取到裸盘的盘符,而非分区后的盘符,例如/data 文件系统对应的盘符是vdb1,这里获取的是vdb

    3. 创建读写控制组

    cgcreate -g blkio:test_read
    cgcreate -g blkio:test_write
    

    4.  将io读写限制策略绑定在指定的磁盘驱动号上

    disk_id=$(ls -l ${disk_name} | awk '{print $5,$6}' | sed 's/ //g' | tr ',' ':')
    cgset -r blkio.throttle.read_bps_device="${disk_id} ${io_read_limit}" test_read
    cgset -r blkio.throttle.write_bps_device="${disk_id} ${io_write_limit}" test_write
    

    5. 确认配置的限制策略

    cgget -r blkio.throttle.read_bps_device test_read
    cgget -r blkio.throttle.write_bps_device test_write
    

    6. 读测试对比

    dd if=/dev/vdb of=/dev/null
    cgexec -g blkio:test_read dd if=/dev/vdb of=/dev/null
    

      

    7. 写测试对比

    dd if=/dev/zero of=/data/testfile bs=512 count=100000 oflag=dsync
    cgexec -g blkio:test_write dd if=/dev/zero of=/data/testfile bs=1024 count=1000 oflag=dsync
    

    8. 将正在执行的进程添加到限制策略里

    #比如正在执行的dd命令对应的pid是5306
    cgclassify -g blkio:test_write 5306
    

     

  • 相关阅读:
    webpack的基本使用2
    js调用本地exe程序,并获取exe运行结果
    BLE技术简介(转)
    在线编解码转换工具
    json字符转数组
    PPT图标
    在线IP地址与数字互转工具
    C# Combobox
    C# 设置本机日期格式
    sql server删除字段约束
  • 原文地址:https://www.cnblogs.com/imdba/p/14010458.html
Copyright © 2020-2023  润新知