1. 程式人生 > >sysbench使用及自定義oltp測試lua指令碼

sysbench使用及自定義oltp測試lua指令碼

一、sysbench介紹

sysbench是一個模組化的、跨平臺、多執行緒基準測試工具,主要用於評估測試各種不同系統引數下的資料庫負載情況。
目前sysbench程式碼託管在launchpad上,專案地址:https://launchpad.net/sysbench(原來的官網 http://sysbench.sourceforge.net 已經不可用),原始碼採用bazaar管理。
注:本文所有的測試都是基於linux作業系統和mysql資料庫的。

二、sysbench安裝

1、依賴包:

  • autoconf
  • automake
  • cdbs
  • debhelper (>= 9)
  • docbook-xml
  • docbook-xsl
  • libmysqlclient15-dev
  • libtool
  • xsltproc

2、編譯安裝:

#./autogen.sh
#./configure
#make

注意事項:./configure命令,sysbench預設是支援MySQL的benchmarking的,如果不加任何選項則要求保證MySQL的安裝路徑都是預設的標準路徑,headfile位於/usr/include目錄下,libraries位於/usr/lib/目錄下。因為我的MySQL是原始碼編譯安裝的,安裝路徑是放在/usr/local/mysql下,所以這裡要新增相應的選項命令:
./configure --prefix=/usr/local/sysbench --with-mysql=/usr/local/mysql \
--with-mysql-includes=/usr/local/mysql/include/ \
--with-mysql-libs=/usr/local/mysql/lib/

這樣就可以看到/usr/local/sysbench下有一個可執行檔案sysbench,這就是sysbench的主程式。

3、功能簡介

sysbench目前可以進行如下幾個方面的效能測試:
- fileio - File I/O test #磁碟io效能
- cpu - CPU performance test #CUP效能
- memory - Memory functions speed test #記憶體效能
- threads - Threads subsystem performance test #POSIX執行緒效能
- mutex - Mutex performance test #排程程式效能
- oltp - OLTP test #資料庫效能(OLTP基準測試)

注:在0.4版本的--test選項中是可以直接選用oltp模式,但是在0.4.12.1.1以後oltp測試就轉換成呼叫lua指令碼來進行測試了,指令碼主要存放在tests/db目錄下。這樣使用者就可以根據自己的系統定製lua指令碼,這樣的測試就能更精確的測試業務的效能。

三、開始進行測試

通用配置

接下來我們來分別看一下各個模式的相關引數、測試方法和結果分析。
sysbench的基本命令格式為:
sysbench –test=< test-name> [options]… < command>
主要分為三個部分:

1、–test=< test-name>

這部分是指定測試型別,基本型別有fileio,cpu,memory,threads,mutex,oltp(或者指定lua指令碼)

2、[options]…

這部分包括測試需要的各種選項,有全域性的也有每個測試模式自由的選項
(每個測試模式的選項可以用./sysbench –test=< test-name> help來獲取)

3、< command>

控制命令,總共有五個
prepare #準備測試,主要是生成測試資料
run #執行測試,根據選項限制來執行測試
cleanup #清除準備階段生成的測試資料
help #獲取幫助文件
version #獲取版本資訊

幾個重要的全域性引數:

–num-threads=N number of threads to use [1] #測試時使用的執行緒數
–max-requests=N limit for total number of requests [10000] #測試過程最多執行多少次請求
–max-time=N limit for total execution time in seconds [0] #測試過程總共執行多長時間(和–max-requests效果同樣,但是兩個同時限定的時候誰優先還沒有測試)
–report-interval=N periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0] #每隔多少秒輸出測試概況(這個過程你可以觀察到mysql redolog的切換情況)
–db-driver=STRING specifies database driver to use (‘help’ to get list of available drivers) #指定需求測試的資料庫型別,預設是mysql
#mysql連結選項
–mysql-host=[LIST,…] MySQL server host [localhost] #mysql主機地址
–mysql-port=N MySQL server port [3306] #mysql埠
–mysql-socket=[LIST,…] MySQL socket #mysql socket檔案位置,指定這個之後 其他的連結選項均可以不指定
–mysql-user=STRING MySQL user [sbtest] #用來測試的mysql使用者名稱
–mysql-password=STRING MySQL password [] #密碼
–mysql-db=STRING MySQL database name [sbtest] #測試資料庫名 預設sbtest

接下來進入各個測試模式的測試方法

fileio-磁碟io效能

1、主要引數

[[email protected] sysbench]# ./sysbench --test=fileio help
sysbench 0.5:  multi-threaded system evaluation benchmark

fileio options:
  --file-num=N                  number of files to create [128]
  --file-block-size=N           block size to use in all IO operations [16384]
  --file-total-size=SIZE        total size of files to create [2G]
  --file-test-mode=STRING       test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw}
  --file-io-mode=STRING         file operations mode {sync,async,mmap} [sync]
  --file-extra-flags=STRING     additional flags to use on opening files {sync,dsync,direct} []
  --file-fsync-freq=N           do fsync() after this number of requests (0 - don't use fsync()) [100]
  --file-fsync-all=[on|off]     do fsync() after each write operation [off]
  --file-fsync-end=[on|off]     do fsync() at the end of test [on]
  --file-fsync-mode=STRING      which method to use for synchronization {fsync, fdatasync} [fsync]
  --file-merged-requests=N      merge at most this number of IO requests if possible (0 - don't merge) [0]
  --file-rw-ratio=N             reads/writes ratio for combined test [1.5]

No help available for test 'fileio'.

引數詳解:
–file-num=N 代表生成測試檔案的數量,預設為128。
–file-block-size=N 測試時所使用檔案塊的大小,如果想磁碟針對innodb儲存引擎進行測試,可以將其設定為16384,即innodb儲存引擎頁的大小。預設為16384。
–file-total-size=SIZE 建立測試檔案的總大小,預設為2G大小。
–file-test-mode=STRING 檔案測試模式,包含:seqwr(順序寫), seqrewr(順序讀寫), seqrd(順序讀), rndrd(隨機讀), rndwr(隨機寫), rndrw(隨機讀寫)。
–file-io-mode=STRING 檔案操作的模式,sync(同步),async(非同步),fastmmap(快速mmap),slowmmap(慢速mmap),預設為sync同步模式。
–file-async-backlog=N 對應每個執行緒佇列的非同步運算元,預設為128。
–file-extra-flags=STRING 開啟檔案時的選項,這是與API相關的引數。
–file-fsync-freq=N 執行fsync()函式的頻率。fsync主要是同步磁碟檔案,因為可能有系統和磁碟緩衝的關係。 0代表不使用fsync函式。預設值為100。
–file-fsync-all=[on|off] 每執行完一次寫操作,就執行一次fsync。預設為off。
–file-fsync-end=[on|off] 在測試結束時執行fsync函式。預設為on。
–file-fsync-mode=STRING檔案同步函式的選擇,同樣是和API相關的引數,由於多個作業系統對於fdatasync支援不同,因此不建議使用fdatasync。預設為fsync。
–file-merged-requests=N 大多情況下,合併可能的IO的請求數,預設為0。
–file-rw-ratio=N 測試時的讀寫比例,預設時為1.5,即可3:2。

2、測試例項

測試總大小為5G的10個檔案的隨機讀寫效能:

1>先生成測試檔案
sysbench --test=fileio --file-num=10 --file-total-size=5G prepare
2>開始測試
sysbench --test=fileio --file-total-size=5G --file-test-mode=rndrw --max-time=180 --max-requests=100000000 --num-threads=16 --init-rng=on --file-num=10 --file-extra-flags=direct --file-fsync-freq=0 --file-block-size=16384 run
3>結果分析
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.

Random number generator seed is 0 and will be ignored


Extra file open flags: 4000
10 files, 512Mb each
5Gb total file size
Block size 16Kb
Number of random requests for random IO: 100000000
Read/Write ratio for combined random IO test: 1.50
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing random r/w test
Threads started!
Time limit exceeded, exiting...
(last message repeated 15 times)
Done.

Operations performed:  89247 reads, 59488 writes, 0 Other = 148735 Total
Read 1.3618Gb  Written 929.5Mb  Total transferred 2.2695Gb  (12.888Mb/sec)
  824.84 Requests/sec executed

General statistics:
    total time:                          180.3188s
    total number of events:              148735
    total time taken by event execution: 2882.8395
    response time:
         min:                                  0.08ms
         avg:                                 19.38ms
         max:                                953.75ms
         approx.  95 percentile:             158.81ms

Threads fairness:
    events (avg/stddev):           9295.9375/371.20
    execution time (avg/stddev):   180.1775/0.07

主要看這行輸出的資訊:

Read 1.3618Gb  Written 929.5Mb  Total transferred 2.2695Gb  (12.888Mb/sec)
  824.84 Requests/sec executed

這行資訊表示:在180秒時間裡面總共完成隨機讀取1.3618G資料,寫入929.5Mb資料,平均每秒隨機讀寫的效率為12.888Mb/秒,IOPS為824.84 Requests/sec
因為是虛擬機器,所有磁碟的表現還是比較差的。

4>清除測試資料
[root@centostest sysbench]# sysbench --test=fileio --file-num=10 --file-total-size=5G cleanup
sysbench 0.4.12:  multi-threaded system evaluation benchmark

Removing test files...

cpu-cpu效能測試

1、主要引數

[root@centostest sysbench]# sysbench --test=cpu help
sysbench 0.4.12:  multi-threaded system evaluation benchmark

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

引數詳解:
–cpu-max-prime=N 用來選項指定最大的素數,具體引數可以根據CPU的效能來設定,預設為10000

2、測試例項

根據官網的介紹可知:CPU測試使用64位整數,測試計算素數直到某個最大值所需要的時間。

sysbench --test=cpu --cpu-max-prime=20000 run

輸出如下:

[[email protected] sysbench]# sysbench --test=cpu --cpu-max-prime=20000 run
sysbench 0.4.12:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 1
Random number generator seed is 0 and will be ignored


Doing CPU performance benchmark

Primer numbers limit: 20000

Threads started!
Done.


General statistics:
    total time:                          28.9293s
    total number of events:              10000
    total time taken by event execution: 28.8916
    response time:
         min:                                  2.51ms
         avg:                                  2.89ms
         max:                                  7.46ms
         approx.  95 percentile:               3.49ms

Threads fairness:
    events (avg/stddev):           10000.0000/0.00
    execution time (avg/stddev):   28.8916/0.00

我們只需要關心測試的總時間(total time)即可(越小越憂)。
CPU效能測試有一個需要注意的地方,上面的測試只使用了一個執行緒,如果在兩個cpu processor不同的電腦上做比較,這是不公平的。公平的做法是指定合理的執行緒數,如下所示:

sysbench --test=cpu --num-threads=`grep "processor" /proc/cpuinfo | wc -l` --cpu-max-prime=20000 run

補充知識:
檢視CPU核數的方法
檢視物理cpu個數

grep "physical id" /proc/cpuinfo | sort -u | wc -l

檢視核心數量

grep "core id" /proc/cpuinfo | sort -u | wc -l

檢視執行緒數量

grep "processor" /proc/cpuinfo | sort -u | wc -l

在sysbench的測試中,–num-threads取值為”執行緒數量”即可,再大的值沒有什麼意義,對測試結果也沒有什麼影響。

memory-記憶體分配及傳輸速度

1、主要引數

[root@centostest sysbench]# ./sysbench --test=memory help
sysbench 0.5:  multi-threaded system evaluation benchmark

memory options:
  --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]

No help available for test 'memory'.

引數詳解:
–memory-block-size=SIZE 測試記憶體塊的大小,預設為1K
–memory-total-size=SIZE 資料傳輸的總大小,預設為100G
–memory-scope=STRING 記憶體訪問的範圍,包括全域性和本地範圍,預設為global
–memory-hugetlb=[on|off] 是否從HugeTLB池分配記憶體的開關,預設為off
–memory-oper=STRING 記憶體操作的型別,包括read, write, none,預設為write
–memory-access-mode=STRING 記憶體訪問模式,包括seq,rnd兩種模式,預設為seq

2、測試例項

記憶體測試測試了記憶體的連續讀寫效能。

./sysbench --test=memory --memory-block-size=8K --memory-total-size=1G  --num-threads=16 run

3、結果分析

輸出結果如下:

[[email protected] sysbench]# ./sysbench --test=memory --memory-block-size=8K --memory-total-size=1G  --num-threads=16 run
sysbench 0.5:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 16
Random number generator seed is 0 and will be ignored


Initializing worker threads...

Threads started!

Operations performed: 131072 (626689.49 ops/sec)

1024.00 MB transferred (4896.01 MB/sec)


General statistics:
    total time:                          0.2091s
    total number of events:              131072
    total time taken by event execution: 2.3239s
    response time:
         min:                                  0.00ms
         avg:                                  0.02ms
         max:                                 50.38ms
         approx.  95 percentile:               0.00ms

Threads fairness:
    events (avg/stddev):           8192.0000/937.69
    execution time (avg/stddev):   0.1452/0.03

threads-POSIX執行緒效能

1、主要引數

[[email protected] sysbench]# ./sysbench --test=threads help
sysbench 0.5:  multi-threaded system evaluation benchmark

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

No help available for test 'threads'.

引數詳解:
–thread-yields=N 指定每個請求的壓力,預設為1000
–thread-locks=N 指定每個執行緒的鎖數量,預設為8

2、測試例項

測試執行緒排程器的效能。對於高負載情況下測試執行緒排程器的行為非常有用。

sysbench --test=threads --num-threads=64 run

3、結果分析

下面是輸出結果:

[[email protected] sysbench]# sysbench --test=threads --num-threads=64 run
sysbench 0.4.12:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 64
Random number generator seed is 0 and will be ignored


Doing thread subsystem performance test
Thread yields per test: 1000 Locks used: 8
Threads started!
Done.


General statistics:
    total time:                          9.4415s
    total number of events:              10000
    total time taken by event execution: 602.1637
    response time:
         min:                                  0.35ms
         avg:                                 60.22ms
         max:                                479.03ms
         approx.  95 percentile:             126.27ms

Threads fairness:
    events (avg/stddev):           156.2500/4.82
    execution time (avg/stddev):   9.4088/0.02

關注的效能指標也是total time越小越憂。

mutex-排程程式效能

1、主要引數

[[email protected] sysbench]# ./sysbench --test=mutex help
sysbench 0.5:  multi-threaded system evaluation benchmark

mutex options:
  --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 inside mutex lock [10000]

No help available for test 'mutex'.

引數詳解:
–mutex-num=N 陣列互斥的總大小。預設是4096
–mutex-locks=N 每個執行緒互斥鎖的數量。預設是50000
–mutex-loops=N 內部互斥鎖的空迴圈數量。預設是10000

2、測試例項

測試互斥鎖的效能,方式是模擬所有執行緒在同一時刻併發執行,並都短暫請求互斥鎖。

./sysbench --test=mutex --num-threads=16 --mutex-num=2048 --mutex-locks=1000000 --mutex-loops=5000 run

3、結果分析

結果輸出如下:

[[email protected] sysbench]# ./sysbench --test=mutex --num-threads=16 --mutex-num=2048 --mutex-locks=1000000 --mutex-loops=5000 run
sysbench 0.5:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 16
Random number generator seed is 0 and will be ignored


Initializing worker threads...

Threads started!


General statistics:
    total time:                          0.8856s
    total number of events:              16
    total time taken by event execution: 13.7792s
    response time:
         min:                                832.79ms
         avg:                                861.20ms
         max:                                880.81ms
         approx.  95 percentile:             878.94ms

Threads fairness:
    events (avg/stddev):           1.0000/0.00
    execution time (avg/stddev):   0.8612/0.01

oltp-資料庫效能測試

1、主要引數

由於sysbench0.5中已經不存在oltp測試模式了,所以使用命令./sysbench --test=oltp help無法獲取好幫助資訊,還好0.4和0.5的引數都是相容的,所以我們這裡用0.4的幫助資訊來說明:

[root@centostest sysbench]# ./sysbench --help=oltp help
Usage:
  sysbench [general-options]... --test=<test-name> [test-options]... command

General options:
  --num-threads=N             number of threads to use [1]
  --max-requests=N            limit for total number of requests [10000]
  --max-time=N                limit for total execution time in seconds [0]
  --forced-shutdown=STRING    amount of time to wait after --max-time before forcing shutdown [off]
  --thread-stack-size=SIZE    size of stack per thread [32K]
  --init-rng=[on|off]         initialize random number generator [off]
  --seed-rng=N                seed for random number generator, ignored when 0 [0]
  --tx-rate=N                 target transaction rate (tps) [0]
  --tx-jitter=N               target transaction variation, in microseconds [0]
  --report-interval=N         periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0]
  --report-checkpoints=[LIST,...]dump full statistics and reset all counters at specified points in time. The argument is a list of comma-separated values representing the amount of time in seconds elapsed from start of test when report checkpoint(s) must be performed. Report checkpoints are off by default. []
  --test=STRING               test to run
  --debug=[on|off]            print more debugging info [off]
  --validate=[on|off]         perform validation checks where possible [off]
  --help=[on|off]             print help and exit
  --version=[on|off]          print version and exit

Log options:
  --verbosity=N      verbosity level {5 - debug, 0 - only critical messages} [4]

  --percentile=N      percentile rank of query response times to count [95]

Compiled-in tests:
  fileio - File I/O test
  cpu - CPU performance test
  memory - Memory functions speed test
  threads - Threads subsystem performance test
  mutex - Mutex performance test
  oltp - OLTP test

Commands: prepare run cleanup help version

See 'sysbench --test=<name> help' for a list of options for each test.

引數詳解:
–oltp-test-mode=STRING 執行模式{simple,complex(advanced transactional),nontrx(non-transactional),sp}。預設是complex
–oltp-reconnect-mode=STRING 重新連線模式{session(不使用重新連線。每個執行緒斷開只在測試結束),transaction(在每次事務結束後重新連線),query(在每個SQL語句執行完重新連線),random(對於每個事務隨機選擇以上重新連線模式)}。預設是session
–oltp-sp-name=STRING 儲存過程的名稱。預設為空
–oltp-read-only=[on|off] 只讀模式。Update,delete,insert語句不可執行。預設是off
–oltp-skip-trx=[on|off] 省略begin/commit語句。預設是off
–oltp-range-size=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 查詢型別對於非事務執行模式{select, update_key, update_nokey, insert, delete} [select]
–oltp-auto-inc=[on|off] AUTO_INCREMENT是否開啟。預設是on
–oltp-connect-delay=N 在多少微秒後連線資料庫。預設是10000
–oltp-user-delay-min=N 每個請求最短等待時間。單位是ms。預設是0
–oltp-user-delay-max=N 每個請求最長等待時間。單位是ms。預設是0
–oltp-table-name=STRING 測試時使用到的表名。預設是sbtest
–oltp-table-size=N 測試表的記錄數。預設是10000
–oltp-dist-type=STRING 分佈的隨機數{uniform(均勻分佈),Gaussian(高斯分佈),special(空間分佈)}。預設是special
–oltp-dist-iter=N 產生數的迭代次數。預設是12
–oltp-dist-pct=N 值的百分比被視為’special’ (for special distribution)。預設是1
–oltp-dist-res=N ‘special’的百分比值。預設是75

2、測試例項

1>生成測試資料,1個表,每個表100000資料
[[email protected] sysbench]# ./sysbench --mysql-host=127.0.0.1 --mysql-port=3166 --mysql-user=root --mysql-password=123456  --test=tests/db/oltp.lua --oltp_tables_count=1 --oltp-table-size=1000000 --rand-init=on prepare
sysbench 0.5:  multi-threaded system evaluation benchmark

Creating table 'sbtest1'...
Inserting 1000000 records into 'sbtest1'
……………………
2>開始測試

使用128執行緒(–num-threads=128)測試60秒(–max-time=60)每10秒輸出一次測試資訊(–report-interval=10)

./sysbench --mysql-host=127.0.0.1 --mysql-port=3166 --mysql-user=root --mysql-password=123456 --test=tests/db/oltp.lua --oltp_tables_count=1 --oltp-table-size=1000000 --num-threads=128 --oltp-read-only=off --report-interval=10 --rand-type=uniform --max-time=60 --max-requests=0 run
3>結果分析

測試結果輸出如下:

[[email protected] sysbench]# ./sysbench --mysql-host=127.0.0.1 --mysql-port=3166 --mysql-user=root --mysql-password=123456 --test=tests/db/oltp.lua --oltp_tables_count=1 --oltp-table-size=1000000 --num-threads=128 --oltp-read-only=off --report-interval=10 --rand-type=uniform --max-time=60 --max-requests=0 run
sysbench 0.5:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 128
Report intermediate results every 10 second(s)
Random number generator seed is 0 and will be ignored


Initializing worker threads...

Threads started!

[  10s] threads: 128, tps: 63.17, reads: 957.71, writes: 253.70, response time: 6659.14ms (95%), errors: 0.00, reconnects:  0.00
[  20s] threads: 128, tps: 38.10, reads: 615.56, writes: 169.59, response time: 4702.80ms (95%), errors: 0.00, reconnects:  0.00
[  30s] threads: 128, tps: 43.10, reads: 627.16, writes: 154.61, response time: 7544.47ms (95%), errors: 0.00, reconnects:  0.00
[  40s] threads: 128, tps: 27.70, reads: 364.70, writes: 119.80, response time: 7278.28ms (95%), errors: 0.00, reconnects:  0.00
[  50s] threads: 128, tps: 36.10, reads: 399.28, writes: 135.69, response time: 8400.39ms (95%), errors: 0.00, reconnects:  0.00
[  60s] threads: 128, tps: 21.80, reads: 434.42, writes: 90.30, response time: 11977.08ms (95%), errors: 0.00, reconnects:  0.00
OLTP test statistics:
    queries performed:
        read:                            33992
        write:                           9712
        other:                           4856
        total:                           48560
    transactions:                        2428   (39.27 per sec.)
    read/write requests:                 43704  (706.81 per sec.)
    other operations:                    4856   (78.53 per sec.)
    ignored errors:                      0      (0.00 per sec.)
    reconnects:                          0      (0.00 per sec.)

General statistics:
    total time:                          61.8331s
    total number of events:              2428
    total time taken by event execution: 7830.4825s
    response time:
         min:                                210.50ms
         avg:                               3225.08ms
         max:                              11983.87ms
         approx.  95 percentile:            8024.33ms

Threads fairness:
    events (avg/stddev):           18.9688/2.14
    execution time (avg/stddev):   61.1756/0.40

主要關注如下幾個值:

    transactions:                        2428   (39.27 per sec.)
    read/write requests:                 43704  (706.81 per sec.)
    other operations:                    4856   (78.53 per sec.)

四、oltp-資料庫效能測試中lua指令碼分析

在sysbench0.4的後期版本中sysbench已經取消了test中的oltp模式,換而代之的是oltp的lua指令碼。這一改變大大的提升了sysbench的靈活性。使用者可以結合業務來定製lua指令碼,這樣能更精確的測試出適用於此業務的資料庫效能指標。

這次我們使用sysbench-0.4.12-1.1來看看預設的lua指令碼做了哪些工作,以及我們怎麼來定製lua指令碼。

oltp的測試指令碼預設存放在tests/db下,這個目錄下有很多指令碼,在oltp基準測試中我們用到比較多的是common.luaoltp.lua

[[email protected]-112 db]# pwd
/root/sysbench-0.4.12-1.1/sysbench/tests/db
[[email protected]-112 db]# ll
total 72
-rw-r--r-- 1 root root  3585 Jul 28 09:32 common.lua
-rw-r--r-- 1 root root   340 Jul 28 09:32 delete.lua
-rw-r--r-- 1 root root   830 Jul 28 09:32 insert.lua
-rw-r--r-- 1 root root 12088 Jul 28 09:32 Makefile
-rw-r--r-- 1 root root  1020 Jul 28 09:32 Makefile.am
-rw-r--r-- 1 root root 11569 Jul 28 09:32 Makefile.in
-rw-r--r-- 1 root root  2925 Jul 28 09:32 oltp.lua
-rw-r--r-- 1 root root   342 Jul 28 09:32 oltp_simple.lua
-rw-r--r-- 1 root root   425 Jul 28 09:32 parallel_prepare.lua
-rw-r--r-- 1 root root   343 Jul 28 09:32 select.lua
-rw-r--r-- 1 root root  3964 Jul 28 09:32 select_random_points.lua
-rw-r--r--