工作上需要用到AWS和Azure的Mysql服務(wù),需要測(cè)試比較一下兩個(gè)云服務(wù)的性能。于是開始百度 + google,查找性能測(cè)試工具。最終決定用sysbench。

sysbench介紹
sysbench是一款開源的多線程性能測(cè)試工具,可以執(zhí)行CPU/內(nèi)存/線程/IO/數(shù)據(jù)庫(kù)等方面的性能測(cè)試。
數(shù)據(jù)庫(kù)目前支持MySQL/Oracle/PostgreSQL。本文只是簡(jiǎn)單演示一下幾種測(cè)試的用法,后續(xù)準(zhǔn)備利用sysbench來(lái)對(duì)MySQL進(jìn)行一系列的測(cè)試。具體的一些參數(shù)設(shè)置,需要根據(jù)不同的測(cè)試要求來(lái)進(jìn)行調(diào)整。
安裝
1. 下載安裝包,地址 https://github.com/akopytov/sysbench
#wget https://github.com/akopytov/sysbench/archive/1.0.zip -O "sysbench-1.0.zip" #unzip sysbench-1.0.zip #cd sysbench-1.02. 安裝依賴庫(kù)
#yum install automake libtool -y3. 開始安裝
#./autogen.sh #./configure #ERROR: cannot find MySQL libraries. If you want to compile with MySQL support 沒找到mysql庫(kù) 需要用參數(shù)指定下 --with-mysql-includes和--with-mysql-libs #./configure --with-mysql-includes=/alidata/server/mysql5.7/include/ --with-mysql-libs=/alidata/server/mysql5.7/lib/4. 由于是yum安裝的mysql,我也不知道路徑在哪里。如何查找mysql的安裝路徑?
安裝mysql-devel,才能使用mysql_config
#yum install -y mysql-devel #mysql_config -help Usage: /usr/bin/mysql_config-64 [OPTIONS] Options: --cflags [-I/usr/include/mysql -g -fstack-protector -m64 -fPIC -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing] --cxxflags [-I/usr/include/mysql -g -fexceptions -fstack-protector -m64 -fPIC -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing] --include [-I/usr/include/mysql] --libs [-L/usr/lib64/mysql -lmysqlclient -lpthread -lm -lrt -ldl] --libs_r [-L/usr/lib64/mysql -lmysqlclient -lpthread -lm -lrt -ldl] --plugindir [/usr/lib64/mysql/plugin] --socket [/var/lib/mysql/mysql.sock] --port [0] --version [5.6.39] --libmysqld-libs [-L/usr/lib64/mysql -lmysqld -lpthread -lm -lrt -lcrypt -ldl -laio -lnuma] --variable=VAR VAR is one of: pkgincludedir [/usr/include/mysql] pkglibdir [/usr/lib64/mysql] plugindir [/usr/lib64/mysql/plugin]5. 再次執(zhí)行config,成功
# ./configure --with-mysql-includes=/usr/include/mysql --with-mysql-libs=/usr/lib64/mysql #make6. 執(zhí)行下命令:
#sysbench --help #sysbench: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory #問題原因:sysbench無(wú)法找到mysql的庫(kù)文件,可能是環(huán)境變量LD_LIBRARY_PATH沒有設(shè)置,設(shè)置后即可解決該問題: #export LD_LIBRARY_PATH=/alidata/server/mysql5.7/lib/lib #sysbench --version sysbench 1.0.12 (using bundled LuaJIT 2.1.0-beta2)準(zhǔn)備測(cè)試表和數(shù)據(jù)
1. 創(chuàng)建測(cè)試數(shù)據(jù)庫(kù):
mysql>create database dbtest;2. 測(cè)試命令
#/home/mysql/sysbench-1.0/src/sysbench --test=/home/mysql/sysbench-1.0/tests/include/oltp_legacy/oltp.lua \ --mysql-host=mysql-host-ip --mysql-port=3306 --mysql-user=envision --mysql-password=password \ --mysql-db=dbtest --oltp-tables-count=10 --oltp-table-size=500000 \ --report-interval=10 --rand-init=on --max-requests=0 \ --oltp-read-only=off --max-time=120 --num-threads=30 \ [ prepare | run | cleanup ]##三選一
prepare 準(zhǔn)備;
run 運(yùn)行;
cleanup 清理數(shù)據(jù)。
注意最后一行,一項(xiàng)測(cè)試開始前需要用prepare來(lái)準(zhǔn)備好表和數(shù)據(jù),run執(zhí)行真正的壓測(cè),cleanup用來(lái)清除數(shù)據(jù)和表。
3. 執(zhí)行sysbench命令參數(shù)解釋:
#-test=/root/sysbench-1.0/tests/include/oltp_legacy/oltp.lua 表示調(diào)用 oltp.lua 腳本進(jìn)行 oltp 模式測(cè)試 #--oltp_tables_count=10 表示會(huì)生成 10 個(gè)測(cè)試表 #--oltp-table-size=500000 表示每個(gè)測(cè)試表填充數(shù)據(jù)量為 500000 #--rand-init=on 表示每個(gè)測(cè)試表都是用隨機(jī)數(shù)據(jù)來(lái)填充的 #-num-threads=8 表示發(fā)起 8個(gè)并發(fā)連接 #--oltp-read-only=off 表示不要進(jìn)行只讀測(cè)試,也就是會(huì)采用讀寫混合模式測(cè)試#--report-interval=10 表示每10秒輸出一次測(cè)試進(jìn)度報(bào)告 #--rand-type=uniform 表示隨機(jī)類型為固定模式,其他幾個(gè)可選隨機(jī)模式:uniform(固定),gaussian(高斯),special(特定的),pareto(帕累托) #--max-time=120 表示大執(zhí)行時(shí)長(zhǎng)為 120秒#--max-requests=0 表示總請(qǐng)求數(shù)為 0,因?yàn)樯厦嬉呀?jīng)定義了總執(zhí)行時(shí)長(zhǎng),所以總請(qǐng)求數(shù)可以設(shè)定為 0;也可以只設(shè)定總請(qǐng)求數(shù),不設(shè)定大執(zhí)行時(shí)長(zhǎng) #--percentile=99 表示設(shè)定采樣比例,默認(rèn)是 95%,即丟棄1%的長(zhǎng)請(qǐng)求,在剩余的99%里取大值4. 測(cè)試準(zhǔn)備: 30個(gè)并發(fā)連接,10張表 每個(gè)表填充50W條數(shù)據(jù) 大請(qǐng)求時(shí)間120s
#/home/mysql/sysbench-1.0/src/sysbench --test=/home/mysql/sysbench-1.0/tests/include/oltp_legacy/oltp.lua \ --mysql-host=mysql-host-ip --mysql-port=3306 --mysql-user=envision --mysql-password=password \ --mysql-db=dbtest --oltp-tables-count=10 --oltp-table-size=500000 \ --report-interval=10 --rand-init=on --max-requests=0 \ --oltp-read-only=off --max-time=120 --num-threads=30 \ prepare 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'... ...... Inserting 100000 records into 'sbtest9' Creating secondary indexes on 'sbtest9'... Creating table 'sbtest10'... Inserting 100000 records into 'sbtest10' Creating secondary indexes on 'sbtest10'...5. 執(zhí)行sysbench測(cè)試,并輸出測(cè)試報(bào)告
#/home/mysql/sysbench-1.0/src/sysbench --test=/home/mysql/sysbench-1.0/tests/include/oltp_legacy/oltp.lua \ --mysql-host=mysql-host-ip --mysql-port=3306 --mysql-user=envision --mysql-password=password \ --mysql-db=dbtest --oltp-tables-count=10 --oltp-table-size=500000 \ --report-interval=10 --rand-init=on --max-requests=0 \ --oltp-read-only=off --max-time=120 --num-threads=128 \ run > /tmp/liang/mysql-report.txt6. 查看測(cè)試報(bào)告
30個(gè)threads
sysbench 1.0.12 (using bundled LuaJIT 2.1.0-beta2) Running the test with following options: Number of threads: 30 Report intermediate results every 10 second(s) Initializing random number generator from current time Initializing worker threads... Threads started! [ 10s ] thds: 30 tps: 188.63 qps: 3795.16 (r/w/o: 2659.89/755.31/379.96) lat (ms,95%): 223.34 err/s: 0.00 reconn/s: 0.00 [ 20s ] thds: 30 tps: 177.80 qps: 3563.97 (r/w/o: 2496.95/711.31/355.71) lat (ms,95%): 248.83 err/s: 0.00 reconn/s: 0.00 [ 30s ] thds: 30 tps: 177.20 qps: 3542.62 (r/w/o: 2479.82/708.30/354.50) lat (ms,95%): 235.74 err/s: 0.00 reconn/s: 0.00 [ 40s ] thds: 30 tps: 189.60 qps: 3797.38 (r/w/o: 2658.99/759.20/379.20) lat (ms,95%): 227.40 err/s: 0.00 reconn/s: 0.00 [ 50s ] thds: 30 tps: 190.40 qps: 3798.09 (r/w/o: 2655.29/762.20/380.60) lat (ms,95%): 211.60 err/s: 0.00 reconn/s: 0.00 [ 60s ] thds: 30 tps: 179.70 qps: 3598.40 (r/w/o: 2520.50/718.40/359.50) lat (ms,95%): 235.74 err/s: 0.00 reconn/s: 0.00 [ 70s ] thds: 30 tps: 187.30 qps: 3740.91 (r/w/o: 2617.61/748.50/374.80) lat (ms,95%): 227.40 err/s: 0.00 reconn/s: 0.00 [ 80s ] thds: 30 tps: 187.40 qps: 3755.29 (r/w/o: 2630.19/750.40/374.70) lat (ms,95%): 211.60 err/s: 0.00 reconn/s: 0.00 [ 90s ] thds: 30 tps: 188.10 qps: 3762.11 (r/w/o: 2632.80/753.10/376.20) lat (ms,95%): 211.60 err/s: 0.00 reconn/s: 0.00 [ 100s ] thds: 30 tps: 183.70 qps: 3676.35 (r/w/o: 2575.16/733.69/367.49) lat (ms,95%): 227.40 err/s: 0.00 reconn/s: 0.00 [ 110s ] thds: 30 tps: 190.80 qps: 3816.33 (r/w/o: 2671.42/763.41/381.50) lat (ms,95%): 211.60 err/s: 0.00 reconn/s: 0.00 [ 120s ] thds: 30 tps: 195.49 qps: 3907.36 (r/w/o: 2733.40/783.17/390.79) lat (ms,95%): 204.11 err/s: 0.00 reconn/s: 0.00 SQL statistics: queries performed: read: 313488 --讀總數(shù) write: 89568 --寫總數(shù) other: 44784 --其他操作(CURD之外的操作,例如COMMIT) total: 447840 --全部總數(shù) transactions: 22392 (186.27 per sec.) --總事務(wù)數(shù)(每秒事務(wù)數(shù)) queries: 447840 (3725.43 per sec.) --總數(shù)(每秒總數(shù)) ignored errors: 0 (0.00 per sec.) --總忽略錯(cuò)誤總數(shù)(每秒忽略錯(cuò)誤次數(shù)) reconnects: 0 (0.00 per sec.) --重連總數(shù)(每秒重連次數(shù)) General statistics: total time: 120.2098s --總耗時(shí) total number of events: 22392 --共發(fā)生多少事務(wù)數(shù) Latency (ms): min: 105.91 --最小耗時(shí) avg: 160.86 --平均耗時(shí) max: 850.77 --最長(zhǎng)耗時(shí) 95th percentile: 223.34 --超過95%平均耗時(shí) sum: 3601892.56 Threads fairness: events (avg/stddev): 746.4000/4.95 --總處理事件數(shù)/標(biāo)準(zhǔn)偏差 execution time (avg/stddev): 120.0631/0.05--總執(zhí)行時(shí)間/標(biāo)準(zhǔn)偏差經(jīng)過測(cè)試,AWS和Azure的mysql性能相差無(wú)幾。sysbench的工具,使用起來(lái)也比較簡(jiǎn)單直觀。適合對(duì)Mysql的簡(jiǎn)單性能測(cè)試。后續(xù)有時(shí)間,再研究一下sysbench對(duì)CPU,IO等性能測(cè)試的情況和使用感受。
參考文檔:
http://blog.csdn.net/oahz4699092zhao/article/details/53332105
http://www.jb51.net/article/93924.htm
https://nsimple.top/archives/mysql-sysbench-tool.html
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
當(dāng)前名稱:Mysql性能測(cè)試工具sysbench的安裝和使用-創(chuàng)新互聯(lián)
標(biāo)題路徑:http://www.chinadenli.net/article20/degdco.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、面包屑導(dǎo)航、品牌網(wǎng)站建設(shè)、建站公司、品牌網(wǎng)站設(shè)計(jì)、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容