溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

怎么使用Sysbench對滴滴云MySQL進(jìn)行基準(zhǔn)測試

發(fā)布時間:2021-10-12 11:31:16 來源:億速云 閱讀:140 作者:柒染 欄目:云計(jì)算

這篇文章給大家介紹怎么使用Sysbench對滴滴云MySQL進(jìn)行基準(zhǔn)測試,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。

Sysbench是一款開源的多線程、跨平臺的基準(zhǔn)測試工具,可以執(zhí)行CPU/內(nèi)存/線程/IO/數(shù)據(jù)庫等方面的性能測試。這里使用Sysbench針對滴滴云的MySQL進(jìn)行基準(zhǔn)測試。

使用的MySQL數(shù)據(jù)庫為一臺4G內(nèi)存,50G存儲容量的滴滴云MySQL數(shù)據(jù)庫,由于滴滴云MySQL默認(rèn)不能通過公網(wǎng)訪問,此數(shù)據(jù)庫通過一臺滴滴云虛擬機(jī)(DC2)連接,滴滴云MySQL的使用可以參考以下鏈接,此處不再贅述。

https://help.didiyun.com/hc/kb/article/1143410/

其中關(guān)鍵的一步是為了云主機(jī)可以正常訪問MySQL,需要創(chuàng)建用戶,此處為方便測試,建議創(chuàng)建高權(quán)限賬號。 怎么使用Sysbench對滴滴云MySQL進(jìn)行基準(zhǔn)測試 常用的基準(zhǔn)測試指標(biāo)包括

TPS/QPS:衡量吞吐量。

響應(yīng)時間:包括平均響應(yīng)時間、最小響應(yīng)時間、最大響應(yīng)時間、時間百分比等,其中時間百分比參考意義較大,如前95%的請求的最大響應(yīng)時間。

并發(fā)量:同時處理的查詢請求的數(shù)量。

1.在云主機(jī)上安裝MySQL5.7客戶端:

[root@dc2-user]# wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
[root@dc2-user]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm
[root@dc2-user]# yum install mysql-community-client

2. 在云主機(jī)上安裝sysbench

不同版本的sysbench語法有一定差別,本文使用的版本是sysbench2.0。

下載解壓:

[root@dc2-user]# wget https://github.com/akopytov/sysbench/archive/1.0.zip -O "sysbench-1.0.zip"
[root@dc2-user]# unzip sysbench-1.0.zip
[root@dc2-user]# cd sysbench-1.0

安裝依賴:

[root@dc2-user]# yum install automake libtool mysql-devel –y

安裝,確認(rèn)當(dāng)前目錄為sysbench目錄。

[root@dc2-user]# ./autogen.sh
[root@dc2-user]# ./configure
[root@dc2-user]# make && make install

默認(rèn)sysbench命令在這個路徑下,/usr/local/bin/sysbench,如果未添加/usr/local/bin為環(huán)境變量,為方便使用,可以為sysbench命令添加軟鏈。

[root@dc2-user]# ln -s  /usr/local/bin/sysbench /usr/bin/sysbench

驗(yàn)證命令可用性:

[root@dc2-user]#sysbench --version
sysbench 1.0.20

3. Sysbench命令用法

使用sysbench --help查看sysbench的命令用法,此處只介紹本文用到的一些命令選項(xiàng)和參數(shù)。

[root@dc2-user]# sysbench --help
Usage:
  sysbench [options]... [testname] [command]

本例中用到的[options]參數(shù)如下: --mysql-host:MySQL服務(wù)器主機(jī)名,默認(rèn)localhost;如果在本機(jī)上使用localhost報(bào)錯,提示無法連接MySQL服務(wù)器,改成本機(jī)的IP地址應(yīng)該就可以了。 --mysql-port:MySQL服務(wù)器端口,默認(rèn)3306 --mysql-user:用戶名 --mysql-password:MySQL服務(wù)器密碼 --oltp-test-mode:執(zhí)行模式,包括simple、nontrx和complex,默認(rèn)是complex。simple模式下只測試簡單的查詢;nontrx不僅測試查詢,還測試插入更新等,但是不使用事務(wù);complex模式下測試最全面,會測試增刪改查,而且會使用事務(wù),本例使用complex。 --oltp-tables-count:測試的表數(shù)量,本例選擇10張表。 --oltp-table-size:測試的表的大小,本例選擇100000條數(shù)據(jù)。 --threads:客戶端的并發(fā)連接數(shù),本例選用10。 --time:測試執(zhí)行的時間,單位是秒,本例選擇120秒。 --report-interval:生成報(bào)告的時間間隔,單位是秒,本例選擇10秒。

[testname]指定用什么lua腳本進(jìn)行測試,可以是自己編寫的,也可以用sysbench自帶的,自帶腳本位于解壓后的sysbench目錄中tests/include/oltp_legacy下,本例使用oltp.lua腳本,可以模擬并發(fā)、建表、插入數(shù)據(jù)、刪除數(shù)據(jù)等常規(guī)OLTP操作。 [command]選項(xiàng)包括prepare、run和cleanup,即數(shù)據(jù)準(zhǔn)備、測試執(zhí)行和測試后數(shù)據(jù)清理。

4. 測試舉例

首先在滴滴云頁面創(chuàng)建sbtest數(shù)據(jù)庫。

怎么使用Sysbench對滴滴云MySQL進(jìn)行基準(zhǔn)測試

(1)準(zhǔn)備數(shù)據(jù)

[root@dc2-user]# sysbench /home/dc2-user/sysbench-1.0/tests/include/oltp_legacy/oltp.lua --mysql-host=10.254.170.17 --mysql-port=3306 --mysql-user=root --mysql-password=123456 --oltp-test-mode=complex --oltp-tables-count=10 --oltp-table-size=100000 --threads=10 --time=120 --report-interval=10 prepare

sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)

Creating table 'sbtest1'...
Inserting 100000 records into 'sbtest1'
Creating secondary indexes on 'sbtest1'...
Creating table 'sbtest2'...
Inserting 100000 records into 'sbtest2'
Creating secondary indexes on 'sbtest2'...
Creating table 'sbtest3'...
Inserting 100000 records into 'sbtest3'
Creating secondary indexes on 'sbtest3'...
Creating table 'sbtest4'...
Inserting 100000 records into 'sbtest4'
Creating secondary indexes on 'sbtest4'...
Creating table 'sbtest5'...
Inserting 100000 records into 'sbtest5'
Creating secondary indexes on 'sbtest5'...
Creating table 'sbtest6'...
Inserting 100000 records into 'sbtest6'
Creating secondary indexes on 'sbtest6'...
Creating table 'sbtest7'...
Inserting 100000 records into 'sbtest7'
Creating secondary indexes on 'sbtest7'...
Creating table 'sbtest8'...
Inserting 100000 records into 'sbtest8'
Creating secondary indexes on 'sbtest8'...
Creating table 'sbtest9'...
Inserting 100000 records into 'sbtest9'
Creating secondary indexes on 'sbtest9'...
Creating table 'sbtest10'...
Inserting 100000 records into 'sbtest10'
Creating secondary indexes on 'sbtest10'...

(2)執(zhí)行測試 可以將執(zhí)行結(jié)果保存在文件中便于后續(xù)分析。

[root@dc2-user]# sysbench ./sysbench-1.0/tests/include/oltp_legacy/oltp.lua --mysql-host=10.254.170.17 --mysql-port=3306 --mysql-user=root --mysql-password=123456 --oltp-test-mode=complex --oltp-tables-count=10 --oltp-table-size=100000 --threads=10 --time=120 --report-interval=10 run >> /home/dc2-user/mysysbench.log

(3)清理數(shù)據(jù)

[root@dc2-user]# sysbench ./sysbench-1.0/tests/include/oltp_legacy/oltp.lua --mysql-host=10.254.170.17 --mysql-port=3306 --mysql-user=root --mysql-password=123456  cleanup

sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)

Dropping table 'sbtest1'...

##解讀測試結(jié)果## 打開所保存的測試結(jié)果。

[root@dc2-user]# cat mysysbench.log 
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)

Running the test with following options:
Number of threads: 10
Report intermediate results every 10 second(s)
Initializing random number generator from current time


Initializing worker threads...

Threads started!

[ 10s ] thds: 10 tps: 358.81 qps: 7186.31 (r/w/o: 5032.37/1435.32/718.61) lat (ms,95%): 39.65 err/s: 0.00 reconn/s: 0.00
[ 20s ] thds: 10 tps: 342.69 qps: 6850.20 (r/w/o: 4794.16/1370.66/685.38) lat (ms,95%): 44.98 err/s: 0.00 reconn/s: 0.00
[ 30s ] thds: 10 tps: 364.58 qps: 7296.91 (r/w/o: 5108.46/1459.40/729.05) lat (ms,95%): 38.25 err/s: 0.00 reconn/s: 0.00
[ 40s ] thds: 10 tps: 371.62 qps: 7428.24 (r/w/o: 5199.11/1485.79/743.34) lat (ms,95%): 38.94 err/s: 0.00 reconn/s: 0.00
[ 50s ] thds: 10 tps: 355.44 qps: 7112.96 (r/w/o: 4980.30/1421.77/710.89) lat (ms,95%): 43.39 err/s: 0.00 reconn/s: 0.00
[ 60s ] thds: 10 tps: 377.68 qps: 7551.83 (r/w/o: 5285.47/1511.01/755.35) lat (ms,95%): 36.89 err/s: 0.00 reconn/s: 0.00
[ 70s ] thds: 10 tps: 378.59 qps: 7572.99 (r/w/o: 5301.26/1514.56/757.18) lat (ms,95%): 38.25 err/s: 0.00 reconn/s: 0.00
[ 80s ] thds: 10 tps: 365.19 qps: 7303.79 (r/w/o: 5113.05/1460.46/730.28) lat (ms,95%): 41.10 err/s: 0.00 reconn/s: 0.00
[ 90s ] thds: 10 tps: 354.24 qps: 7084.59 (r/w/o: 4959.65/1416.36/708.58) lat (ms,95%): 40.37 err/s: 0.00 reconn/s: 0.00
[ 100s ] thds: 10 tps: 372.75 qps: 7453.38 (r/w/o: 5216.16/1491.82/745.41) lat (ms,95%): 38.94 err/s: 0.00 reconn/s: 0.00
[ 110s ] thds: 10 tps: 349.95 qps: 7002.81 (r/w/o: 4902.60/1400.20/700.00) lat (ms,95%): 43.39 err/s: 0.00 reconn/s: 0.00
[ 120s ] thds: 10 tps: 371.82 qps: 7432.30 (r/w/o: 5202.68/1486.08/743.54) lat (ms,95%): 37.56 err/s: 0.00 reconn/s: 0.00
SQL statistics:
    queries performed:
        read:                            611030
        write:                           174580
        other:                           87290
        total:                           872900
    transactions:                        43645  (363.59 per sec.)
    queries:                             872900 (7271.87 per sec.)
    ignored errors:                      0      (0.00 per sec.)
    reconnects:                          0      (0.00 per sec.)

General statistics:
    total time:                          120.0362s
    total number of events:              43645

Latency (ms):
         min:                                   18.29
         avg:                                   27.49
         max:                                  677.90
         95th percentile:                       40.37
         sum:                              1199972.75

Threads fairness:
    events (avg/stddev):           4364.5000/72.30
    execution time (avg/stddev):   119.9973/0.01

這里一般我們關(guān)注這兩個指標(biāo)。

queries:                             872900 (7271.87 per sec.)

95th percentile:                       40.37

我們可以看到QPS為7271.87,95%請求的最大延遲為40.37毫秒,對于當(dāng)前配置的mysql來說,測試結(jié)果比較理想。

關(guān)于怎么使用Sysbench對滴滴云MySQL進(jìn)行基準(zhǔn)測試就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI