使用cgroup限制磁碟io讀寫速率

2022-07-09 06:45:10 字數 1876 閱讀 6078

在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讀寫的限制測試

【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命令檢視

io_read_limit=1048576

io_write_limit=1024

#比如我測試的讀寫檔案都發生在/data檔案系統裡

filesystem_mounted='/data'

lsblk -d -n | awk '' >all_disks

while read line

doaaa=$(df -h | grep -w $ | grep $line)

if [[ ! -z aaa ]];then

disk_name=$line

fidone < all_disks

#echo $disk_name

說明:以上主要是為了獲取到裸盤的碟符,而非分割槽後的碟符,例如/data 檔案系統對應的碟符是vdb1,這裡獲取的是vdb

cgcreate -g blkio:test_read

cgcreate -g blkio:test_write

disk_id=$(ls -l $ | awk '' | sed 's/ //g' | tr ',' ':')

cgset -r blkio.throttle.read_bps_device="$ $" test_read

cgset -r blkio.throttle.write_bps_device="$ $" test_write

cgget -r blkio.throttle.read_bps_device test_read

cgget -r blkio.throttle.write_bps_device test_write

dd if=/dev/vdb of=/dev/null

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

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

#比如正在執行的dd命令對應的pid是5306

cgclassify -g blkio:test_write 5306

cgroup使用 memory資源限制

同樣,cgroup也可以對memory資源進行限制。下面以乙個例子來驗證cgroup對記憶體限制的使用。1.編寫程式,迴圈分配600m記憶體。include include include define chunk size 1024 1024 100 intmain memset p,0 chun...

使用CGROUP限制mongd的disk io

使用cgroup做磁碟io的資源隔離,用到blkio子系統 先測試blkio限制dd的情況,很重要的一點是只能限制direct io,dd if dev zero of mongodb dd1 bs 4k count 10240 oflag direct 在測試mongod的時候,直接限制mongo...

使用cgroup限制某個程式對記憶體的使用

線上的mongodb是複製集模式的。為了便於監控mongodb的慢查詢等狀態,在3臺機器上都部署了packetbeat,通過抓取27017埠的流量傳送到es集群。但是第二天發現zabbix告警,顯示某一台機器a 從節點 上的mongod程序宕了。日誌顯示是oom導致的。再一想到,我們每天的mongo...