http://www.mysqlsky.com/201202/howto_exhaust_os_resource
在数据库压测中,对于容灾场景有时需要模拟linux系统资源耗尽的情况,以得出DB在极端场景下的生存情况和恢复速率;本文提供了针对CPU,IO,Mem三大资源的耗尽方法
1.CPU
方法一:shell脚本
#! /bin/sh# filename killcpu.shif [ $# != 1 ] ; then echo "USAGE: $0 " exit 1;fifor i in `seq $1`do echo -ne "i=0;while truedoi=i+1;done" | /bin/sh & pid_array[$i]=$! ;done for i in "${pid_array[@]}"; do echo 'kill ' $i ';';done
方法二:sysbench CPU
./sysbench --test=cpu --cpu-max-prime=2000000 --num-threads=60 run & renice -5 $(ps -ef|grep sysbench|gawk '$0 !~/grep/ {print $2}' |tr -s '\n' ' ')
2.IO
使用无敌的fio压测工具进行,采用指定的filename,randread&randwrite分两个fio进程打开,规避文件系统瓶颈
fio -filename=/u01/killread.rm -direct=1 -iodepth=1 -rw=randread -ioengine=psync -bs=16k -size=4G -numjobs=64 -runtime=3000 -group_reporting -name=killIOreadfio -filename=/u01/killwrite.rm -direct=1 -iodepth=1 -rw=randwrite -ioengine=psync
在数据库压测中,对于容灾场景有时需要模拟linux系统资源耗尽的情况,以得出DB在极端场景下的生存情况和恢复速率;本文提供了针对CPU,IO,Mem三大资源的耗尽方法
1.CPU
方法一:shell脚本
#! /bin/sh# filename killcpu.shif [ $# != 1 ] ; then echo "USAGE: $0 " exit 1;fifor i in `seq $1`do echo -ne "i=0;while truedoi=i+1;done" | /bin/sh & pid_array[$i]=$! ;done for i in "${pid_array[@]}"; do echo 'kill ' $i ';';done
方法二:sysbench CPU
./sysbench --test=cpu --cpu-max-prime=2000000 --num-threads=60 run & renice -5 $(ps -ef|grep sysbench|gawk '$0 !~/grep/ {print $2}' |tr -s '\n' ' ')
2.IO
使用无敌的fio压测工具进行,采用指定的filename,randread&randwrite分两个fio进程打开,规避文件系统瓶颈
fio -filename=/u01/killread.rm -direct=1 -iodepth=1 -rw=randread -ioengine=psync -bs=16k -size=4G -numjobs=64 -runtime=3000 -group_reporting -name=killIOreadfio -filename=/u01/killwrite.rm -direct=1 -iodepth=1 -rw=randwrite -ioengine=psync