概述
sysbensh是一個(gè)非常通用的benchmark工具,其提供多種方面的測(cè)試:
- cpu :提供一個(gè)簡(jiǎn)單的cpu benchmark測(cè)試
- fileio:文件磁盤(pán)io的benchmark測(cè)試
- memory:內(nèi)存訪問(wèn) benchmark測(cè)試
- thread:線程調(diào)度 benchmark測(cè)試
- mutex:POSIX的鎖 benchmark測(cè)試
- OLTP:數(shù)據(jù)庫(kù) benchmark測(cè)試,支持MySQL,Pgsql
安裝
默認(rèn)支持MySQL,如果需要測(cè)試Oracle/PostgreSQL,則在configure時(shí)需要加上–with-oracle或者–with-pgsql參數(shù).
1.安裝環(huán)境
CentOS release 6.3 (Final)
MySQL 5.6.13
MySQL_HOME=/usr/local/mysql/
Sysbench 0.4.12
2.下載安裝包
# wget http://sourceforge.net/projects/sysbench/sysbench-0.4.12.tar.gz
3.編譯安裝
# tar –zxvf sysbench-0.4.12.tar.gz
進(jìn)入解壓縮包sysbench-0.4.12,并執(zhí)行腳本autogen.sh
# cd sysbench-0.4.12
# ./autogen.sh
關(guān)鍵的三步:configure && make && make install
首先是./configure命令,sysbench默認(rèn)是支持MySQL的benchmarking的,如果不加任何選項(xiàng)則要求保證MySQL的安裝路徑都是默認(rèn)的標(biāo)準(zhǔn)路徑,headfile位于/usr/include目錄下,libraries位于/usr/lib/目錄下。因?yàn)槲业腗ySQL是源碼編譯安裝的,安裝路徑是放在/usr/local/mysql下,所以這里要添加相應(yīng)的選項(xiàng)命令:
# ./configure --prefix=/usr/local/sysbench --with-mysql=/usr/local/mysql \
--with-mysql-includes=/usr/local/mysql/include/mysql/ \
--with-mysql-libs=/usr/local/mysql/lib/mysql/
注意:這里在編譯時(shí)要將路徑寫(xiě)到最后的include/mysql及l(fā)ib/mysql,如下所示:
–with-mysql-includes=/usr/local/mysql/include/mysql/
--with-mysql-libs=/usr/local/mysql/lib/mysql/
因?yàn)榫W(wǎng)上好多資料都沒(méi)有提到這一層,在編譯時(shí)總是編譯不過(guò)去,這里浪費(fèi)了好多精力。
接下來(lái)執(zhí)行如下命令:
# make && make install
4.yum安裝
如果覺(jué)得源碼安裝麻煩,也可以采用yum安裝,操作如下:
# yum install -y 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了。
語(yǔ)法表達(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。
測(cè)試 fileio
sysbench --test=fileio help
參數(shù)詳解:
--file-num=N 代表生成測(cè)試文件的數(shù)量,默認(rèn)為128。
--file-block-size=N 測(cè)試時(shí)所使用文件塊的大小,如果想磁盤(pán)針對(duì)innodb存儲(chǔ)引擎進(jìn)行測(cè)試,可以將其設(shè)置為16384,即innodb存儲(chǔ)引擎頁(yè)的大小。默認(rèn)為16384。
--file-total-size=SIZE 創(chuàng)建測(cè)試文件的總大小,默認(rèn)為2G大小。
--file-test-mode=STRING 文件測(cè)試模式,包含:seqwr(順序?qū)?span id="n5n3t3z" class="token punctuation">), seqrewr(順序讀寫(xiě)), seqrd(順序讀), rndrd(隨機(jī)讀), rndwr(隨機(jī)寫(xiě)), rndrw(隨機(jī)讀寫(xiě))。
--file-io-mode=STRING 文件操作的模式,sync(同步),async(異步),fastmmap(快速mmap),slowmmap(慢速mmap),默認(rèn)為sync同步模式。
--file-async-backlog=N 對(duì)應(yīng)每個(gè)線程隊(duì)列的異步操作數(shù),默認(rèn)為128。
--file-extra-flags=STRING 打開(kāi)文件時(shí)的選項(xiàng),這是與API相關(guān)的參數(shù)。
--file-fsync-freq=N 執(zhí)行fsync()函數(shù)的頻率。fsync主要是同步磁盤(pán)文件,因?yàn)榭赡苡邢到y(tǒng)和磁盤(pán)緩沖的關(guān)系。 0代表不使用fsync函數(shù)。默認(rèn)值為100。
--file-fsync-all=[on|off] 每執(zhí)行完一次寫(xiě)操作,就執(zhí)行一次fsync。默認(rèn)為off。
--file-fsync-end=[on|off] 在測(cè)試結(jié)束時(shí)執(zhí)行fsync函數(shù)。默認(rèn)為on。
--file-fsync-mode=STRING文件同步函數(shù)的選擇,同樣是和API相關(guān)的參數(shù),由于多個(gè)操作系統(tǒng)對(duì)于fdatasync支持不同,因此不建議使用fdatasync。默認(rèn)為fsync。
--file-merged-requests=N 大多情況下,合并可能的IO的請(qǐng)求數(shù),默認(rèn)為0。
--file-rw-ratio=N 測(cè)試時(shí)的讀寫(xiě)比例,默認(rèn)時(shí)為1.5,即可3:2
測(cè)試 CPU
sysbench --test=cpu help
參數(shù)詳解:
--cpu-max-prime=N 用來(lái)選項(xiàng)指定最大的素?cái)?shù),具體參數(shù)可以根據(jù)CPU的性能來(lái)設(shè)置,默認(rèn)為10000
測(cè)試 memory
sysbench --test=memory help
參數(shù)詳解:
--memory-block-size=SIZE 測(cè)試內(nèi)存塊的大小,默認(rèn)為1K
--memory-total-size=SIZE 數(shù)據(jù)傳輸?shù)目偞笮?,默認(rèn)為100G
--memory-scope=STRING 內(nèi)存訪問(wèn)的范圍,包括全局和本地范圍,默認(rèn)為global
--memory-hugetlb=[on|off] 是否從HugeTLB池分配內(nèi)存的開(kāi)關(guān),默認(rèn)為off
--memory-oper=STRING 內(nèi)存操作的類型,包括read, write, none,默認(rèn)為write
--memory-access-mode=STRING 內(nèi)存訪問(wèn)模式,包括seq,rnd兩種模式,默認(rèn)為seq
測(cè)試 threads
sysbench --test-threads help
參數(shù)詳解:
--thread-yields=N 指定每個(gè)請(qǐng)求的壓力,默認(rèn)為1000
--thread-locks=N 指定每個(gè)線程的鎖數(shù)量,默認(rèn)為8
測(cè)試 mutex
sysbench --test=mutex help
參數(shù)詳解:
--mutex-num=N 數(shù)組互斥的總大小。默認(rèn)是4096
--mutex-locks=N 每個(gè)線程互斥鎖的數(shù)量。默認(rèn)是50000
--mutex-loops=N 內(nèi)部互斥鎖的空循環(huán)數(shù)量。默認(rèn)是10000
測(cè)試 otlp
sysbench --test=otlp help
參數(shù)詳解:
--oltp-test-mode=STRING 執(zhí)行模式{simple,complex(advanced transactional),nontrx(non-transactional),sp}。默認(rèn)是complex
--oltp-reconnect-mode=STRING 重新連接模式{session(不使用重新連接。每個(gè)線程斷開(kāi)只在測(cè)試結(jié)束),transaction(在每次事務(wù)結(jié)束后重新連接),query(在每個(gè)SQL語(yǔ)句執(zhí)行完重新連接),random(對(duì)于每個(gè)事務(wù)隨機(jī)選擇以上重新連接模式)}。默認(rèn)是session
--oltp-sp-name=STRING 存儲(chǔ)過(guò)程的名稱。默認(rèn)為空
--oltp-read-only=[on|off] 只讀模式。Update,delete,insert語(yǔ)句不可執(zhí)行。默認(rèn)是off
--oltp-skip-trx=[on|off] 省略begin/commit語(yǔ)句。默認(rèn)是off
--oltp-range-size=N 查詢范圍。默認(rèn)是100
--oltp-point-selects=N number of point selects [10]
--oltp-simple-ranges=N number of simple ranges [1]
--oltp-sum-ranges=N number of sum ranges [1]
--oltp-order-ranges=N number of ordered ranges [1]
--oltp-distinct-ranges=N number of distinct ranges [1]
--oltp-index-updates=N number of index update [1]
--oltp-non-index-updates=N number of non-index updates [1]
--oltp-nontrx-mode=STRING 查詢類型對(duì)于非事務(wù)執(zhí)行模式{select, update_key, update_nokey, insert, delete} [select]
--oltp-auto-inc=[on|off] AUTO_INCREMENT是否開(kāi)啟。默認(rèn)是on
--oltp-connect-delay=N 在多少微秒后連接數(shù)據(jù)庫(kù)。默認(rèn)是10000
--oltp-user-delay-min=N 每個(gè)請(qǐng)求最短等待時(shí)間。單位是ms。默認(rèn)是0
--oltp-user-delay-max=N 每個(gè)請(qǐng)求最長(zhǎng)等待時(shí)間。單位是ms。默認(rèn)是0
--oltp-table-name=STRING 測(cè)試時(shí)使用到的表名。默認(rèn)是sbtest
--oltp-table-size=N 測(cè)試表的記錄數(shù)。默認(rèn)是10000
--oltp-dist-type=STRING 分布的隨機(jī)數(shù){uniform(均勻分布),Gaussian(高斯分布),special(空間分布)}。默認(rèn)是special
--oltp-dist-iter=N 產(chǎn)生數(shù)的迭代次數(shù)。默認(rèn)是12
--oltp-dist-pct=N 值的百分比被視為'special' (for special distribution)。默認(rèn)是1
--oltp-dist-res=N ‘special’的百分比值。默認(rèn)是75
對(duì) MySQL 事務(wù)型 OLTP 的測(cè)試:
對(duì)于 MySQL 的 OLTP 測(cè)試,和 File 一樣,同樣需要經(jīng)歷 prepare,run,cleanup 三個(gè)階段。
prepare 準(zhǔn)備階段
prepare階段會(huì)在數(shù)據(jù)庫(kù)中產(chǎn)生一張指定行數(shù)的表,默認(rèn)表在sbtest架構(gòu)下,表名為sbtest(sysbench默認(rèn)生成表的存儲(chǔ)引擎為innodb),如創(chuàng)建一張8000萬(wàn)條記錄的表:
[root@db-master sysbench]# sysbench --test=oltp --oltp-table-size=80000000 --db-driver=mysql --mysql-socket=/data/mysqlsoft3307/mysql.sock --mysql-user=dba_manager --mysql-password='111111' --mysql-db=test prepare
sysbench 0.4.12: multi-threaded system evaluation benchmark
Creating table 'sbtest'...
Creating 10 records in table 'sbtest'...
run運(yùn)行測(cè)試文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-650930.html
接下來(lái)對(duì)上面產(chǎn)生的表進(jìn)行 oltp 的測(cè)試:
[root@db-master sysbench]# sysbench --test=oltp --oltp-table-size=80000000 --oltp-read-only=off --init-rng=on --num-threads=16
--max-requests=0 --oltp-dist-type=uniform --max-time=3600 --mysql-user=dba_manager --mysql-password='111111' --db-driver=mysql
--mysql-socket=/data/mysqlsoft3307/mysql.sock run > result.log
參數(shù)說(shuō)明:
--max-time=3600 指定測(cè)試時(shí)長(zhǎng)為1小時(shí)
--mysql-db=test 指定測(cè)試的數(shù)據(jù)庫(kù)名
[root@db-master sysbench]# cat result.log
sysbench 0.4.12: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 16
Initializing random number generator from timer.
Doing OLTP test.
Running mixed OLTP test
Using Uniform distribution
Using "BEGIN" for starting transactions
Using auto_inc on the id column
Threads started!
Time limit exceeded, exiting...
(last message repeated 15 times)
Done.
OLTP test statistics:
queries performed:
read: 137346874
write: 49052449
other: 19620980
total: 206020303
transactions: 9810489 (2725.13 per sec.)
deadlocks: 2 (0.00 per sec.)
read/write requests: 186399323 (51777.50 per sec.)
other operations: 19620980 (5450.26 per sec.)
Test execution summary:
total time: 3600.0060s
total number of events: 9810489
total time taken by event execution: 57542.1464
per-request statistics:
min: 3.00ms
avg: 5.87ms
max: 212.09ms
approx. 95 percentile: 8.44ms
Threads fairness:
events (avg/stddev): 613155.5625/1486.47
execution time (avg/stddev): 3596.3842/0.01
transactions代表測(cè)試結(jié)果的評(píng)判標(biāo)準(zhǔn)即TPS.
上述測(cè)試結(jié)果是 2725.13 per sec.
來(lái)源
Sysbench
sysbench基礎(chǔ)介紹
sysbench壓力測(cè)試工具簡(jiǎn)介文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-650930.html
到了這里,關(guān)于【工具/性能】開(kāi)源的性能測(cè)試工具sysbench的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!