Sysbench

Sysbench的搭建與使用

對于從事數(shù)據(jù)庫開發(fā)或者數(shù)據(jù)庫運(yùn)維的同學(xué)來說,benchmark這個(gè)工具是不可缺少的。好的benchmark可以模擬出我們想測試到的各種場景以及不同的負(fù)載壓力,通過對系統(tǒng)進(jìn)行bench可以得到系統(tǒng)當(dāng)前的性能指標(biāo),并進(jìn)一步分析系統(tǒng)可以改進(jìn)的方向。

sysbench簡介

sysbensh是一個(gè)非常通用的benchmark工具,其提供多種方面的測試:

  1. cpu :提供一個(gè)簡單的cpu benchmark測試
  2. fileio:文件磁盤io的benchmark測試
  3. memory:內(nèi)存訪問 benchmark測試
  4. thread:線程調(diào)度 benchmark測試
  5. mutex:POSIX的鎖 benchmark測試
  6. OLTP:數(shù)據(jù)庫 benchmark測試,支持MySQL,Pgsql

sysbench安裝

sysbench的安裝非常簡單,其支持各類操作系統(tǒng)。安裝的主要過程見github

因?yàn)槲疫@里使用的是ubuntu系統(tǒng),所以直接使用:

curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.deb.sh | sudo bash
sudo apt -y install sysbench

進(jìn)行安裝。

sysbench使用

為了更加熟悉使用sysbench,我們需要熟悉一些通用的 options參數(shù)

--threads=N  線程數(shù)目,默認(rèn)使用1
--events=N   默認(rèn)為0
--time=N     默認(rèn)為0
--forced-shutdown=STRING  默認(rèn)為‘off’,另一個(gè)選項(xiàng)為‘on’
--thread-stack-size=SIZE  默認(rèn)為64K
--rate=N     平均transactions率,默認(rèn)為0,不限制
--report-interval=N  周期性(periodically)匯報(bào)統(tǒng)計(jì)信息,單位seconds,默認(rèn)為0,表示disable interval report
--debug[=on|off]  print debug 信息,默認(rèn)為off

還有一些其他的參數(shù),因?yàn)楹苌偈褂盟芯筒唤榻B了。

語法表達(dá)式

sysbench [options]... [testname] [command] 

其中testname,可以是fileio,memory等,或者是一個(gè)lua script或者是lua script的path。

command表示prepare,run,cleanup或者h(yuǎn)elp

具體詳細(xì)的每一個(gè)options參數(shù)的含義,參考github。

bench file/io

fileio 有一些獨(dú)有的參數(shù),可以直接使用sysbench fileio help查看。
主要使用的參數(shù)為

--file-num=N 默認(rèn)為128
--file-block-size=N  默認(rèn)為16384bytes
--file-total-size=SIZE 默認(rèn)為2G
--file-test-mode=STRING       test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw}
--file-io-mode=STRING         file operations mode {sync,async,mmap} [sync]
等參數(shù)

在設(shè)置file-total-size的時(shí)候應(yīng)該比內(nèi)存的大小大,來確保內(nèi)存的cache不會(huì)影響workload太多。
這里主要說明一下file-test-mode中幾個(gè)參數(shù)的含義:

  • seqwr:順序?qū)?/li>
  • seqrewr:順序重寫
  • seqrd:順序讀
  • rndrd:隨機(jī)讀
  • rndwr:隨機(jī)寫
  • rndrw:混合隨機(jī)讀、寫

bench cpu

cpu 參數(shù)比較簡單,只有一個(gè)就是:

--cpu-max-prime=N upper limit for primes generator [10000]

表示需要計(jì)算的prime的數(shù)量;還有一些參數(shù)就是general options,比如線程數(shù)等。

bench memory

memory的訪問參數(shù):

  --memory-block-size=SIZE    size of memory block for test [1K]
  --memory-total-size=SIZE    total size of data to transfer [100G]
  --memory-scope=STRING       memory access scope {global,local} [global]
  --memory-hugetlb[=on|off]   allocate memory from HugeTLB pool [off]
  --memory-oper=STRING        type of memory operations {read, write, none} [write]
  --memory-access-mode=STRING memory access mode {seq,rnd} [seq]

bench threads

參數(shù)有:

  --thread-yields=N number of yields to do per request [1000]
  --thread-locks=N  number of locks per thread [8]

bench mutex

參數(shù)有:

  --mutex-num=N   total size of mutex array [4096]
  --mutex-locks=N number of mutex locks to do per thread [50000]
  --mutex-loops=N number of empty loops to do outside mutex lock [10000]

OLTP workload

后續(xù)補(bǔ)充

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容