MySQL 5.7和8.0 MHA架構下sysbench壓測

ywxj_001發表於2019-08-28

sysbench壓測環境:


sysbench server:172.16.7.105

壓測資料庫伺服器:MHA架構,172.16.7.100(主節點)、172.16.7.101、172.16.7.102

MySQL在172.16.7.105(安裝MySQL5.7.26)部署目錄:/opt/mysql/

主要壓測172.16.7.100主節點

172.16.7.100配置:

MySQL5.7.26

CPU:4核

記憶體:8G

innodb_buffer_pool_size = 28G

innodb_log_file_size = 512M

innodb_log_files_in_group = 2

innodb_log_buffer_size=16M

MySQL8.0.17

CPU:4核

記憶體:8G

innodb_buffer_pool_size = 28G

innodb_log_file_size = 512M

innodb_log_files_in_group = 2

innodb_log_buffer_size=16M



前置工作

1.完成MySQL的安裝

2.完成動態庫檔案的安裝

yum install -y openssl libtool 



#可能遇到的報錯

1.在make之前,需要修改lib庫,否則會得到一個報錯:/usr/bin/ld: cannot find -lmysqlclient_r

因為安裝中指向的lib是/opt/mysql/lib

cd /opt/mysql/lib

ln -s libmysqlclient.so.20.3.9 libmysqlclient_r.so

2.make的時候沒有明顯錯誤,執行./sysbench時報錯

./sysbench: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory

ln -s /opt/mysql/lib/libmysqlclient.so.18 /usr/lib64

如果報錯為

/usr/local/sysbench/bin/sysbench: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory

那麼就執行

ln -s /opt/mysql/lib/libmysqlclient.so.20 /usr/lib64



下載sysbench:


wget

部署:

tar -xf sysbench-0.4.12-1.1.tgz

mv sysbench-0.4.12-1.1 sysbench

cp -r sysbench /usr/local/sysbench



cd /usr/local/sysbench

./autogen.sh

#生成configure檔案

./configure --prefix=/usr/local/sysbench/  --with-mysql=/opt/mysql/  --with-mysql-includes=/opt/mysql/include/ --with-mysql-libs=/opt/mysql/lib/



注意此處的includes必須是mysql對應的include目錄,libs也是mysql對應的lib目錄

完成安裝

make&&make install

(確認沒有報錯)



驗證安裝

/usr/local/sysbench/bin/sysbench --help

如果出現下列文字,說明部署成功

[root@GTID01 bin]# /usr/local/sysbench/bin/sysbench --help

Missing required command argument.Usage: sysbench [general-options]... --test= [test-options]... command

General options:

  --num-threads=N            number of threads to use [1]

  --max-requests=N            limit for total number of requests [10000]

...

增加環境變數

echo -e "export PATH=\$PATH:/usr/local/sysbench/bin" >> /etc/profile

source /etc/profile



使用sysbench進行測試

先到被測試的庫裡建庫,建使用者,授權(這裡透過105去測試100庫)

mysql -h 172.16.7.100 -uroot -p

...

create database sbtest; ##因為lua指令碼里面這裡設定的就是sbtest庫,庫名需要與指令碼里的內容保持一致

create user tpcc@'%' identified by 'tpcc';

grant all privileges on sbtest.* to tpcc@'%';

flush privileges;



MySQL8.0需要加:


alter user tpcc@'%' identified with 'mysql_native_password' by 'tpcc';



會產生報錯的操作(將oltp.lua中的mysiam修改成innodb後,會找不到表)

cd /usr/local/sysbench/sysbench/tests/db/

cp oltp.lua oltp_innodb.lua

sed -i 's/myisam/innodb/g' /usr/local/sysbench/sysbench/tests/db/oltp_innodb.lua



測試多表的壓測

執行prepare

sysbench --mysql-host=172.16.7.100 --mysql-port=3306 --mysql-user=tpcc --mysql-password=tpcc --test=/usr/local/sysbench/sysbench/tests/db/oltp.lua --oltp_tables_count=10 --oltp-table-size=100000 --rand-init=on prepare



執行run

sysbench --mysql-host=172.16.7.100 --mysql-port=3306 --mysql-user=tpcc --mysql-password=tpcc --test=/usr/local/sysbench/sysbench/tests/db/oltp.lua --oltp_tables_count=10 --oltp-table-size=100000 --num-threads=4 --oltp-read---report-interval=5 --rand-type=uniform --max-time=30 --max-requests=0 --percentile=99 run

--num-threads=4    //執行緒數為4

--max-time=30      //測試時間為30s

--report-interval=5    //報告列印週期為5s

--oltp-read->

--max-requests=0                //最大執行次數這裡不做限制,只由max-time進行限制



MySQL8.0我是用的30001埠




MySQL5.7用32執行緒壓測結果:


sysbench 0.5:  multi-threaded system evaluation benchmark




Running the test with following options:


Number of threads: 32


Report intermediate results every 5 second(s)


Random number generator seed is 0 and will be ignored






Threads started!




[   5s] threads: 32, tps: 842.19, reads/s: 11867.59, writes/s: 3376.34, response time: 172.23ms (99%)


[  10s] threads: 32, tps: 1013.21, reads/s: 14187.90, writes/s: 4053.03, response time: 96.36ms (99%)


[  15s] threads: 32, tps: 1195.60, reads/s: 16709.15, writes/s: 4778.79, response time: 63.71ms (99%)


[  20s] threads: 32, tps: 1095.19, reads/s: 15341.21, writes/s: 4383.35, response time: 87.04ms (99%)


[  25s] threads: 32, tps: 1111.01, reads/s: 15567.40, writes/s: 4446.26, response time: 78.19ms (99%)


[  30s] threads: 32, tps: 1045.20, reads/s: 14628.00, writes/s: 4174.40, response time: 85.90ms (99%)


OLTP test statistics:


    queries performed:


        read:                            441616


        write:                           126176


        other:                           63088


        total:                           630880


    transactions:                        31544  (1050.71 per sec.)


    deadlocks:                           0      (0.00 per sec.)


    read/write requests:                 567792 (18912.78 per sec.)


    other operations:                    63088  (2101.42 per sec.)




General statistics:


    total time:                          30.0216s


    total number of events:              31544


    total time taken by event execution: 954.2759s


    response time:


         min:                                  9.17ms


         avg:                                 30.25ms


         max:                                389.96ms


         approx.  99 percentile:              94.36ms




Threads fairness:


    events (avg/stddev):           985.7500/40.24


    execution time (avg/stddev):   29.8211/0.03






read: 441616     //讀總數,select語句


write: 126176    //寫總數,insert、delete、update語句


other: 63088    //其它語句,如commit等


total: 630880           //總的執行語句數


transactions: 31544 (1050.71 per sec.)  //總的事物數(★每秒處理事物數:TPS★)


read/write requests: 567792 (18912.78 per sec.)  //讀寫請求次數(★每秒的讀寫次數:QPS★)


other operations: 63088 (2101.42 per sec.)    //其它操作的每秒執行數


General statistics:


total time: 30.0216s        //總時間


total number of events: 

31544    //★事物總數★


total time taken by event execution: 954.2759s   //所有事務耗時相加(不考慮並行因素)


response time:    //應答時間


min: 9.17ms    //最小


avg: 30.25ms    //平均


max: 389.96ms    //最大


approx. 99 percentile: 94.36ms  //99%語句執行時間


Threads fairness:  //執行緒公平性


events (avg/stddev): 985.7500/40.24


execution time (avg/stddev): 29.8211/0.03



需要重點關注的幾個測試結果

★總的事物數,每秒事務數TPS,QPS,時間統計資訊(最大、最小、平均、99%以上語句響應時間)★

透過sysbench結果來判定資料庫的能力主要還是透過TPS




執行清除

sysbench --mysql-host=172.16.7.100 --mysql-port=3306 --mysql-user=tpcc --mysql-password=tpcc --mysql-db=sbtest --oltp-tables-count=10 --oltp-table-size=100000 --num-threads=16 --max-requests=0 --max-time=30 --report-interval=1 --test=/usr/local/sysbench/sysbench/tests/db/oltp.lua cleanup

sysbench 0.5: multi-threaded system evaluation benchmark

Dropping table 'sbtest1'...

Dropping table 'sbtest2'...

Dropping table 'sbtest3'...






來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22996654/viewspace-2655331/,如需轉載,請註明出處,否則將追究法律責任。

相關文章