sysbench的實現原理

myownstars發表於2015-01-29

1  簡介

SysBench是一個模組化的、跨平臺、多執行緒基準測試工具,主要用於評估測試各種不同系統引數下的資料庫負載情況。它主要包括以下幾種方式的測試:

       1cpu效能

       2、磁碟io效能

       3、排程程式效能

       4、記憶體分配及傳輸速度

       5POSIX執行緒效能

       6、資料庫效能(OLTP基準測試)     

目前sysbench主要支援 MySQL,pgsql,oracle 3種資料庫。

 

測試mysql時,sysbench按照指定的數量開啟執行緒,每個執行緒與MySQL建立一個連線,每個執行緒不停地進行事務操作,開啟事務,然後進行一些查詢、更新、插入操作,提交事務,再開始新的事務;所有的SQL只訪問一個表-sbtest,是由sysbenchprepare命令建好的。其中的記錄數,也是在prepare時指定好並建立的。測試結束,會有一個統計結果,包括例如每秒事務數、平均響應時間等等。

 

 

 

2  安裝

1.下載sysbench

2.解壓安裝包:sysbench-0.4.12.tar.gz出現sysbench-0.4.12檔案

tar zxvf sysbench-0.4.12.tar.gz

3.安裝:

A.cd  sysbench-0.4.12

B.執行autogen.sh

./autogen.sh

C.安裝

./configure –prefix=/home/mysql/sysbench –with-mysql-includes=/u01/mysql/include/mysql –with-mysql-libs=/u01/mysql/lib/mysql –with-mysql

D.make

E.make install

說明:

prefix=/home/mysql/sysbench :指定sysbenchbin目錄;

with-mysql-includes=/u01/mysql/include/mysql :指定安裝mysql時候的includes目錄;

with-mysql-libs=/u01/mysql/lib/mysql:指定裝mysql時候的lib目錄;

with-mysqlsysbench預設支援mysql,如果需要測試oracle或者pgsql則需要制定–with-oracle或者–with-pgsql

 

 

 

3  實現

1 cpu

常用選項—cpu-max-prime=N,用於計算素數;--test=cpu

 

2 io

模擬了很多innodb特性;--test=fileio

分為prepareruncleanup,分別為生成資料,執行測試和清理資料;

--file-test-mode,分為seqrd/rndrd/seqwr/seqrewr/rndwr/rndrw,可進行順序讀寫,隨機讀寫以及混合隨機讀寫;

輸出結果顯示呼叫fsync()頻率以及使用sync或者async IO模式;

 

3 oltp

測試mysql,也分為三步:

3.1 prepare建立表並填充資料(資料庫需要手工建立),表名預設sbtest

CREATE TABLE `sbtest` (

  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,

  `k` int(10) unsigned NOT NULL DEFAULT '0',

  `c` char(120) NOT NULL DEFAULT '',

  `pad` char(60) NOT NULL DEFAULT '',

  PRIMARY KEY (`id`),

  KEY `k` (`k`));

3.2  run進行測試;

3種模式:

Simple:每個執行緒只執行SELECT c FROM sbtest WHERE id=N

Advanced transactional:執行事務,包含查詢和DML(保證資料記錄不變)

Non-transactional:可自主選擇要執行的queryDML會影響表記錄,多次測試需要相應的cleanup/prepare--oltp-nontrx-mode可指定測試用的sql型別


3.3 cleanup
  清空建立的表和資料

 

重要選項

  --oltp-test-mode=STRING         test type to use {simple,complex,nontrx,sp} [complex]

  --oltp-reconnect-mode=STRING    reconnect mode {session,transaction,query,random} [session]

  --oltp-sp-name=STRING           name of store procedure to call in SP test mode []

  --oltp-read-only=[on|off]       generate only 'read' queries (do not modify database) [off]

  --oltp-skip-trx=[on|off]        skip BEGIN/COMMIT statements [off]

  --oltp-range-size=N             range size for range queries [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       mode for non-transactional test {select, update_key, update_nokey, insert, delete} [select]

  --oltp-auto-inc=[on|off]        whether AUTO_INCREMENT (or equivalent) should be used on id column [on]

  --oltp-connect-delay=N          time in microseconds to sleep after connection to database [10000]

  --oltp-user-delay-min=N         minimum time in microseconds to sleep after each request [0]

  --oltp-user-delay-max=N         maximum time in microseconds to sleep after each request [0]

  --oltp-table-name=STRING        name of test table [sbtest]

  --oltp-table-size=N             number of records in test table [10000]

  --oltp-dist-type=STRING         random numbers distribution {uniform,gaussian,special} [special]

  --oltp-dist-iter=N              number of iterations used for numbers generation [12]

  --oltp-dist-pct=N               percentage of values to be treated as 'special' (for special distribution) [1]

  --oltp-dist-res=N               percentage of 'special' values to use (for special distribution) [75]

 

 

 

附錄

1 高階事務模式下執行的query列表

Point queries:

SELECT c FROM sbtest WHERE id=N

Range queries:

SELECT c FROM sbtest WHERE id BETWEEN N AND M

Range SUM() queries:

SELECT SUM(K) FROM sbtest WHERE id BETWEEN N and M

Range ORDER BY queries:

SELECT c FROM sbtest WHERE id between N and M ORDER BY c

Range DISTINCT queries:

SELECT DISTINCT c FROM sbtest WHERE id BETWEEN N and M ORDER BY c

UPDATEs on index column:

UPDATE sbtest SET k=k+1 WHERE id=N

UPDATEs on non-index column:

UPDATE sbtest SET c=N WHERE id=M

DELETE queries:

DELETE FROM sbtest WHERE id=N

INSERT queries:

INSERT INTO sbtest VALUES (...)

 

2 非事務模式下執行的query列表

Point queries:

SELECT pad FROM sbtest WHERE id=N

UPDATEs on index column:

UPDATE sbtest SET k=k+1 WHERE id=N

UPDATEs on non-index column:

UPDATE sbtest SET c=N WHERE id=M

DELETE queries:

DELETE FROM sbtest WHERE id=N

The generated row IDs are unique over each test run, so no row is deleted twice.

INSERT queries:

INSERT INTO sbtest (k, c, pad) VALUES(N, M, S)

 

 

http://www.cnblogs.com/minglog/archive/2011/05/10/2042143.html

http://blog.csdn.net/mchdba/article/details/8970056

~sysbench-developers/sysbench/0.5/files

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15480802/viewspace-1419923/,如需轉載,請註明出處,否則將追究法律責任。

相關文章