sysbench目前已经有0.5的版本,不过最普遍使用的依旧是0.4.12,所以接下来我们会以0.4.12这个版本作为测试
Step1:下载安装sysbench
wget http://pkgs.fedoraproject.org/repo/pkgs/sysbench/sysbench-0.4.12.tar.gz/3a6d54fdd3fe002328e4458206392b9d/sysbench-0.4.12.tar.gztar zxvf sysbench-0.4.12.tar.gzyum install libtool.x86_64 openssl-devel.x86_64 openssl-static.x86_64cd sysbench-0.4.12/libtoolize --force --copy./autogen.sh./configure --prefix=/usr/local/sysbenchmakemake install
Step2: 执行测试脚本(请不要直接粘贴此脚本到你机器上运行,除非你知道它在做什么):
[root@DBServer data]# cat sysbench_all.sh #!/bin/bashresult_dir='/data/result'io_file_dir='/data/iotest'if [ ! -d $result_dir ];then mkdir $result_dirfi#------------------------------fileio test-----------------------------------###RAND WRITE 1 - 16 threadif [ ! -d $io_file_dir ];then mkdir $io_file_dirficd $io_file_dir#sysbench --test=fileio --file-total-size=256G --file-num=64 prepare#sleep 10for rwtype in seqwr seqrewr seqrd rndrd rndwr rndrw;do for numthread in 1 2 4 8 10 16 20 32 40; do sysbench --test=fileio --file-total-size=256G --file-test-mode=$rwtype --max-time=600 --max-requests=0 --file-block-size=4K --file-num=64 --num-threads=$numthread run >> $result_dir/io_${rwtype}_thread${numthread}.txt ; sleep 10; donedone#-----------------------------cpu test-------------------------------- for each in 1 `seq 2 2 40`; do sysbench --test=cpu --cpu-max-prime=40000 --num-threads=$each run >> $result_dir/CPU_thread$each.txt ; sleep 10done#------------------------------ram test--------------------------------# for readfor each in 1 `seq 2 4 40`; do sysbench --test=memory --memory-block-size=4K --memory-scope=global --memory-total-size=256G --memory-oper=read --num-threads=$each run >> $result_dir/RamRead_thread$each.txt ; sleep 10 ; done#for writefor each in 1 `seq 2 4 40`; do sysbench --test=memory --memory-block-size=4K --memory-scope=global --memory-total-size=256G --memory-oper=write --num-threads=$each run >> $result_dir/RamWrite_thread$each.txt ; sleep 10; done#--------------------------mysql test------------------------------# start mysqlmysqld_safe --defaults-file=/data/mysql/my3306.cnf &#wait mysql startup completelysleep 20#prepare 10000000 is 2G#sysbench --test=oltp --db-driver=mysql --mysql-host=127.0.0.1 --mysql-user=root --mysql-password=123 --mysql-db=t_sysbench --oltp-table-size=10000000 --num-threads=40 prepare# only readfor each in 1 4 8 16 20 32 40;do sysbench --test=oltp --oltp-table-size=10000000 --db-driver=mysql --mysql-host=127.0.0.1 --mysql-db=t_sysbench --mysql-user=root --mysql-password=123 --max-time=900 --oltp-read-only=on --max-requests=0 --num-threads=$each run >> $result_dir/mysql_read_thread$each.txt sleep 20done#read and writefor each in 1 4 8 16 20 32 40;do sysbench --test=oltp --oltp-table-size=10000000 --db-driver=mysql --mysql-host=127.0.0.1 --mysql-db=t_sysbench --mysql-user=root --mysql-password=123 --max-time=900 --max-requests=0 --num-threads=$each run >> $result_dir/mysql_rw_thread$each.txt sleep 20donemysqldadmin -uroot -p123 -h127.0.0.1 shutdown
Step3:分析处理,需要用到类似如下的处理分析脚本(以分析mysql为例)
[root@DBServer result]# awk -F '[():]' '/Number of threads:/{printf $2 "\t"} /transactions:/{printf $3 "\t"} /deadlocks:/{printf $2 "\t"} /read\/write requests:/{printf $3 "\t"} /approx. 95 percentile:/{printf $2 "\n"}' mysql_rw_thread* | sort -k 1 -n 1 403.66 per sec. 0 7669.51 per sec. 2.83ms 4 1409.01 per sec. 0 26771.12 per sec. 3.20ms 8 2704.40 per sec. 3 51383.70 per sec. 3.30ms 16 4032.52 per sec. 8 76618.00 per sec. 4.51ms 20 4504.20 per sec. 12 85580.07 per sec. 5.29ms 32 5549.82 per sec. 48 105447.54 per sec. 8.58ms 40 5920.90 per sec. 108 112499.04 per sec. 11.54ms
参考资源:
https://wiki.mikejung.biz/Sysbench