天天看點

sysbench性能壓測以及mysql性能壓測

                sysbench性能壓測以及mysql性能壓測

一、Sysbench是一個子產品化的、跨平台、多線程基準測試工具,主要用于各種不同系統的參數下的資料庫負載情況。

主要測試方式
cpu性能 磁盤io性能 排程程式性能 記憶體配置設定及傳輸速度 posix線程性能 資料庫性能(OLTP基準測試)
找範圍内最大素數{時間越短越好} 不同場景下iops{越大越好} 線程并發執行,循環響應信号量花費的時間{越少越好} 以不同塊大小傳輸一定的數量的資料吞吐量大小{越大越好} 并發線程同時申請互斥鎖循環一定次數花費的時間{越少越好} qps、tps越高越好

目前sysbench主要支援MYSQL,pgsql,oracle 這3種資料庫

二、安裝測試環境:centos6.8   mysql5.7.19

三、安裝sysbench-0.5

源碼位址https://github.com/BoobooWei/sysbench/archive/master.zip

下載下傳到電腦桌面,然後xshell連接配接伺服器,下載下傳上傳軟體工具

#cd /usr/local/src/

#yum install lrzsz -y

#rz      #選中下載下傳的軟體進行上傳

#unzip sysbench-master.zip

#cd sysbench-master

#yum install -y automake libtool -y

#./autogen.sh

報錯:autom4te: /usr/bin/m4 failed with exit status: 63

      aclocal: autom4te failed with exit status: 63

顯示版本太低了

#檢視版本資訊 :yum info autoconf

#檢視路徑:which autoconf

#移除低版本的:rpm -qf /usr/bin/autoconf  rpm -e --nodeps autoconf-2.63

#cd /usr/local/src

#下載下傳新版本軟體:wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz

#tar -xzf autoconf-2.69.tar.gz

#cd autoconf-2.69

#./configure

#make && make install

#檢查版本是否正确   autoconf -V   #顯示路徑還是錯的

#如果報錯重新安裝如果沒有跳過  make uninstall   make clean

#./configure --prefix=/usr

#autoconf -V   顯示正常

#cd /usr/local/src/sysbench-master

#./autogen.sh  顯示正常

#./configure    

報錯:cannot find MySQL libraries. If you want to compile with MySQL support,缺少mysql依賴

# yum install mysql-devel -y

#./configure      顯示正常

四、安裝mysql5.7.19

#wget https://dev.mysql.com/get/mysql57-community-release-el6-9.noarch.rpm

#rpm -Uvh mysql57-community-release-el6-9.noarch.rpm

#yum install mysql-community-server

#service mysqld start

#grep 'temporary password' /var/log/mysqld.log

#mysql -uroot -p

#輸入過濾出來的密碼

#set global validate_password_policy=0;      #設定密碼複雜度

#set global validate_password_length=6;      #設定密碼長度

#ALTER USER 'root'@'localhost' IDENTIFIED BY 'abc123';   #更改密碼

#create database sbtest;

#quit

五、測試

Mysql資料庫測試

sysbench 0.5通過一系列LUA腳本來替換之前的oltp,來模拟更接近真實的基準測試環境。這些測試腳本包含:insert.lua、oltp.lua、parallel_prepare.lua、select_random_points.lua、update_index.lua、delete.luaoltp_simple.lua、select.lua、select_random_ranges.lua、update_non_index.lua,腳本使用方式基本類似。

sysbench 0.5預設使用sbtest庫,但是需要自己手工先建立好,也可以使用--mysql-db指定,其他非預設項指定選項:

--mysql-host

--mysql-port

--mysql-socket

--mysql-user

--mysql-password

--mysql-db

--mysql-ssl

prepare

生成表并插入資料,可使用parallel_prepare.lua腳本來并行準備資料。

-–db-driver 伺服器類型mysql | drizzle,預設為mysql

-–mysql-table-engine 表存數引擎

-–myisam-max-rows MyISAM表MAX_ROWS選項(用于大表)

–-oltp-table-count 生成表數量[sbtest1、sbtest2...]

-–oltp-table-size 生成表的行數

-–oltp-secondary ID列生成二級索引而不是主鍵

–-oltp-auto-inc設定ID列是否自增 on | off,預設為on --oltp-read-only=on

--test=sysbench-0.5/sysbench/tests目錄下測試腳本

sysbench \

--test=/root/sysbench-master/sysbench/tests/db/oltp.lua  \

--mysql-host=localhost  \

--mysql-port=3306  \

--mysql-user=root  \

--mysql-password=abc123 \

--oltp-table-size=100000 \

--num-threads=8 \

--max-time=10 \

--mysql-db=sbtest \

--max-requests=0 \

--oltp-test-mode=complex \

--report-interval=1 \

--mysql-table-engine=innodb  \

[prepare|run|cleanup]準備/測試/清除

六、#測試8個線程,我的測試伺服器是單核1個cpu,準備

#[root@localhost sysbench-master]# sysbench --test=/usr/local/src/sysbench-master/sysbench/tests/db/oltp.lua   --mysql-host=localhost  --mysql-port=3306  --mysql-user=root --mysql-password=abc123   --oltp-table-size=100000  --num-threads=8  --max-time=10  --mysql-db=sbtest --max-requests=0 --oltp-test-mode=complex  --report-interval=1  --mysql-table-engine=innodb prepare

#測試

#[root@localhost sysbench-master]# sysbench --test=/usr/local/src/sysbench-master/sysbench/tests/db/oltp.lua   --mysql-host=localhost  --mysql-port=3306  --mysql-user=root --mysql-password=abc123   --oltp-table-size=100000  --num-threads=8  --max-time=10  --mysql-db=sbtest --max-requests=0 --oltp-test-mode=complex  --report-interval=1  --mysql-table-engine=innodb run

sysbench 1.0 (using bundled LuaJIT 2.1.0-beta2)

Running the test with following options:

Number of threads: 8

Report intermediate results every 1 second(s)

Initializing random number generator from current time

Initializing worker threads...

Threads started!

[   1s] threads: 8, tps: 149.71, reads: 2204.79, writes: 613.41, response time: 164.45ms (95%), errors: 0.00, reconnects:  0.00

[   2s] threads: 8, tps: 253.17, reads: 3543.39, writes: 1019.89, response time: 164.45ms (95%), errors: 0.00, reconnects:  0.00

[   3s] threads: 8, tps: 270.37, reads: 3784.14, writes: 1082.47, response time: 170.48ms (95%), errors: 0.00, reconnects:  0.00

[   4s] threads: 8, tps: 314.77, reads: 4402.71, writes: 1248.04, response time: 94.10ms (95%), errors: 0.00, reconnects:  0.00

[   5s] threads: 8, tps: 251.90, reads: 3528.67, writes: 1008.62, response time: 137.35ms (95%), errors: 0.00, reconnects:  0.00

[   6s] threads: 8, tps: 261.96, reads: 3670.37, writes: 1053.82, response time: 142.39ms (95%), errors: 0.00, reconnects:  0.00

[   7s] threads: 8, tps: 309.18, reads: 4328.47, writes: 1243.71, response time: 95.81ms (95%), errors: 0.00, reconnects:  0.00

[   8s] threads: 8, tps: 264.82, reads: 3701.52, writes: 1054.29, response time: 193.38ms (95%), errors: 0.00, reconnects:  0.00

[   9s] threads: 8, tps: 227.02, reads: 3185.27, writes: 919.08, response time: 179.94ms (95%), errors: 0.00, reconnects:  0.00

[  10s] threads: 8, tps: 248.11, reads: 3457.55, writes: 973.44, response time: 144.97ms (95%), errors: 0.00, reconnects:  0.00

OLTP test statistics:

    queries performed:

        read:                            35784

        write:                           10224

        other:                           5112

        total:                           51120

    transactions:                        2556   (255.33 per sec.)

    read/write requests:                 46008  (4595.97 per sec.)

    other operations:                    5112   (510.66 per sec.)

    ignored errors:                      0      (0.00 per sec.)

    reconnects:                          0      (0.00 per sec.)

General statistics:

    total time:                          10.1611s

    total number of events:              2556

    total time taken by event execution: 80.0554s

Latency statistics:

         min:                                  2.88ms

         avg:                                 31.32ms

         max:                                330.98ms

         approx.  95th percentile:           137.35ms

Threads fairness:

    events (avg/stddev):           319.5000/6.71

execution time (avg/stddev):   10.0069/0.00

#單核,超多線程碾壓的時候試一試64和128個線程

[root@localhost sysbench-master]# sysbench --test=/usr/local/src/sysbench-master/sysbench/tests/db/oltp.lua  --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password=abc123 --oltp-table-size=10000 --num-threads=64 --max-time=30 --mysql-db=sbtest --max-requests=0 --oltp-test-mode=complex --report-interval=1 --mysql-table-engine=innodb run

[root@localhost sysbench-master]# sysbench --test=/usr/local/src/sysbench-master/sysbench/tests/db/oltp.lua  --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password=abc123 --oltp-table-size=10000 --num-threads=128 --max-time=60 --mysql-db=sbtest --max-requests=0 --oltp-test-mode=complex --report-interval=1 --mysql-table-engine=innodb run

#清除

#[root@localhost sysbench-master]# sysbench --test=/usr/local/src/sysbench-master/sysbench/tests/db/oltp.lua   --mysql-host=localhost  --mysql-port=3306  --mysql-user=root --mysql-password=abc123   --oltp-table-size=100000  --num-threads=8  --max-time=10  --mysql-db=sbtest --max-requests=0 --oltp-test-mode=complex  --report-interval=1  --mysql-table-engine=innodb  cleanup

Dropping table 'sbtest1'...

如果是多表呢并增加表的大小,情況又會如何呢?

 [root@localhost sysbench-master]# sysbench --test=/usr/local/src/sysbench-master/sysbench/tests/db/oltp.lua --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password=abc123 --oltp-tables-count=10 --oltp-table-size=100000 --num-threads=128 --max-time=60 --mysql-db=sbtest --max-requests=0 --oltp-test-mode=complex --report-interval=1 --mysql-table-engine=innodb prepare

[root@localhost sysbench-master]# sysbench --test=/usr/local/src/sysbench-master/sysbench/tests/db/oltp.lua --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password=abc123 --oltp-tables-count=10 --oltp-table-size=100000 --num-threads=130 --max-time=20 --mysql-db=sbtest --max-requests=0 --oltp-test-mode=complex --report-interval=1 --mysql-table-engine=innodb run

CPU測試

使用64位整數,測試計算素數直到某個最大值所需要的時間

sysbench --test=cpu --cpu-max-prime=2000 run

檢視CPU資訊方法,檢視實體cpu個數

grep "physical id" /proc/cpuinfo | sort -u | wc -l 檢視核心數量

grep "core id" /proc/cpuinfo | sort -u | wc -l 檢視線程數量

grep "processor" /proc/cpuinfo | sort -u | wc -l

在sysbench的測試中,--num-threads取值為"線程數量"即可

線程(thread)測試

測試線程排程器的性能。對于高負載情況下測試線程排程器的行為非常有用

sysbench --test=threads --num-threads=64 --thread-yields=100 --thread-locks=2 run

檔案IO性能測試

生成需要的測試檔案,檔案總大小5G,16個并發線程。執行完後會在目前目錄下生成一堆小檔案

sysbench --test=fileio --num-threads=16 --file-total-size=5G prepare

執行測試,指定随機讀寫模式:

seqwr順序寫入

seqrewr順序重寫

seqrd順序讀取

rndrd随機讀取

rndwr随機寫入

rndrw混合随機讀/寫

sysbench --test=fileio --num-threads=16 --init-rng=on --file-total-size=5G --file-test-mode=rndrw run

除測試檔案

sysbench --test=fileio --num-threads=16 --file-total-size=5G cleanup

記憶體測試

記憶體測試測試了記憶體的連續讀寫性能。

sysbench --test=memory --num-threads=16 --memory-block-size=8192 --memory-total-size=1G run

互斥鎖(Mutex)測試

測試互斥鎖的性能,方式是模拟所有線程在同一時刻并發運作,并都短暫請求互斥鎖X。

繼續閱讀