MySQL壓力測試工具

工具名稱:mysqlha_sysbench.sh

工具用途:用於MySQL壓力測試  (2種功能:填充數據&&測試數據)

工具參數:

options:

-P 需要測試的端口
-D 需要測試的db名字
-H 需要測試的host
-S 填充&&測試 表的數據量,default 100w
-C 填充&&測試 表的數量, default 1
-T prepare and run ,prepare is 製造數據 run is 開始測試 ,default run
-O on and off, on 是讀寫混合模式 off是隻讀模式 ,default on
-B 併發數 default 1
-Y 測試時間 ,填充時不用填寫 default 1800#半小時 
-N test number 測試的數量 例如 128線程跑3次

 

工具示例: 

Example: Usage make(填充數據) data:mysqlha_sysbench.sh -P 端口 -D db -H ip -T prepare 
Example: Usage test (測試數據)data:mysqlha_sysbench.sh -P 端口 -D db -H ip -B 併發數  -Y 測試時間 -N 次數


注意事項:

1)權限問題  ,注意授權

2)本地必須安裝sysbench 路徑在/usr/local/xywy/sysbench/bin/ 

工具執行結果:

p_w_picpath2016-9-2%2011%3A0%3A3.png?version=1




#!/bin/bash

# Author: [email protected]

# Date: 2016-09-02



# helpfunc shows the help info

function helpfunc(){

        echo 

         echo "Please check your input!!!!"

         echo "options:"

         echo " -P      test port"

         echo " -D      databases name"

         echo " -H      test host"

         echo " -S      table size   ,default 100w"

         echo " -C      test table number ,  default 1"

         echo " -T      prepare and run ,prepare is 製造數據 run is 開始測試  ,default run"

         echo " -O      on and off, on 是讀寫混合模式 off是隻讀模式  ,default on"

         echo " -B      併發數 default 1"

         echo " -Y       Test time in seconds  default 1800#半小時 "

         echo " -N       test number "


         echo "  Example:  Usage make data:mysqlha_sysbench.sh -P  -D  -H  -T  "

         echo "  Example:  Usage test data:mysqlha_sysbench.sh -P  -D  -H  -B  -Y  "


}

############################################

. /etc/dbbin/sh_lib/config.sh "/etc/dbbin/conf/mysql.cfg"

user="myadmin";

password=`getConfig "mysql" $user`


bfs=1

option="on"

time=1800

number=1

if [ $# -lt 1 ] ;

    then

        helpfunc

         exit 1

else

                        P) port=$OPTARG;;

                        D) db=$OPTARG;;

                        H) host=$OPTARG;;

                        S) size=$OPTARG;;

                        C) count=$OPTARG;;

                        T) type=$OPTARG;;

                        O) option=$OPTARG;;

                        B) bfs=$OPTARG;;

                        Y) time=$OPTARG;;

                        N) number=$OPTARG;;

                         *) helpfunc; exit 1; ;;

                esac

        done


fi


date=`date "+%Y-%m-%d"`

function test_data(){

        if [ "$type" == "prepare" ];then

                /usr/local/xywy/sysbench/bin/sysbench --test=/usr/local/xywy/sysbench/db/oltp.lua --oltp-table-size="$size" --oltp-table-name=tt --mysql-db=$db --mysql-port=$port  --mysql-host=$host  --mysql-user=$user --mysql-password=$password  --oltp_tables_count=$count --oltp-test-mode=complex --rand-type=uniform --rand-init=on --report-interval=10 --percentile=99 prepare >> /data/logs/sysbench_oltp$date.log

                if [ $? -ne 0 ] ; then

                        echo "insert data failure!"

                        exit -1

                else

                        echo "insert $count data is sucess"

                fi

        elif [ "$type" == "run" ];then

                for i in $(seq 1 $number)

                do

                        /usr/local/xywy/sysbench/bin/sysbench --test=/usr/local/xywy/sysbench/db/oltp.lua --oltp-table-size=$size   --mysql-db=$db --mysql-port=$port  --mysql-host=$host  --mysql-user=$user --mysql-password=$password  --oltp_tables_count=$count --oltp-read-only=$option --oltp-test-mode=complex --rand-type=uniform --rand-init=on --num-threads=$bfs --max-time=$time --max-requests=0 --report-interval=10 --percentile=99 run >> /data/logs/sysbench_oltp$date.log

                        if [ $? -ne 0 ] ; then

                                echo " Test failure!"

                                exit -1

                        else

                                log=`cat /data/logs/sysbench_oltp$date.log|grep transactions: -B 10|grep $bfs -A10`

                                echo " Concurrent for $bfs of the results is $log "

                        fi

                done

        else

                helpfunc

        fi

}


test_data


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章