1. 程式人生 > >sysbench壓力測試,mysql壓力測試

sysbench壓力測試,mysql壓力測試

sysbench壓力測試工具簡介:

sysbench是一個開源的、模組化的、跨平臺的多執行緒效能測試工具,可以用來進行CPU、記憶體、磁碟I/O、執行緒、資料庫的效能測試。目前支援的資料庫有MySQL、Oracle和PostgreSQL。以下操作都將以支援MySQL資料庫為例進行。
Sysbench的測試主要包括以下幾個方面:
1、磁碟io效能
2、cpu效能
3、記憶體分配及傳輸速度
4、POSIX執行緒效能
5、排程程式效能
6、資料庫效能(OLTP基準測試).

sysbench工具安裝:

預設支援MySQL,如果需要測試Oracle/PostgreSQL,則在configure時需要加上–with-oracle或者–with-pgsql引數.

依賴庫安裝
需要安裝m4 autoconf automake libtool 這幾個包,通過
yum install m4 autoconf automake libtool可進行安裝,否則會報錯( xxx… wasn’t found, exiting)
./autogen.sh (如果是原始碼編譯安裝就不需要執行了)
執行後在目錄下會出現configure資料夾,就說明可以開始執行配置了。

./configure --prefix=/root/sysbench --with-mysql-includes=/usr/local/mysql/include/ --with-mysql-libs
=/usr/local/mysql/lib/

需要指定include和lib目錄。如果沒有,說明安裝時候沒有安裝安裝開發包,這個要單獨安裝的,找Development Libraries 包.
安裝完成後執行:

[[email protected] sysbench]# ll -rth sysbench
total 236K
-rw-r--r--. 1 root root 7.1K Jun 18 04:12 sysbench.h
[[email protected] sysbench]# make
Making all in doc
make[1]: Entering directory `/root/sysbench/doc'
...... [[email protected] sysbench]# make install Making install in doc make[1]: Entering directory `/root/sysbench/doc' .....

沒有報錯的話就在當前的/root/sysbench/sysbench目錄下會生成一個二進位制可執行檔案:sysbench

[[email protected] sysbench]# ll
total 4096
-rw-r--r--. 1 root root    3661 Jun 18 04:12 CMakeLists.txt
-rw-r--r--. 1 root root   24391 Jun 18 04:12 db_driver.c
-rw-r--r--. 1 root root    9911 Jun 18 04:12 db_driver.h
-rw-r--r--. 1 root root  129832 Jun 18 08:49 db_driver.o
drwxr-xr-x. 7 root root    4096 Jun 18 12:50 drivers
-rw-r--r--. 1 root root   25253 Jun 18 12:50 Makefile
-rw-r--r--. 1 root root    2020 Jun 18 04:12 Makefile.am
-rw-r--r--. 1 root root   25998 Jun 18 06:12 Makefile.in
-rw-r--r--. 1 root root    3640 Jun 18 04:12 sb_list.h
-rw-r--r--. 1 root root   16223 Jun 18 04:12 sb_logger.c
-rw-r--r--. 1 root root    4554 Jun 18 04:12 sb_logger.h
-rw-r--r--. 1 root root  116256 Jun 18 08:49 sb_logger.o
-rw-r--r--. 1 root root   13731 Jun 18 04:12 sb_options.c
-rw-r--r--. 1 root root    3108 Jun 18 04:12 sb_options.h
-rw-r--r--. 1 root root  109536 Jun 18 08:49 sb_options.o
-rw-r--r--. 1 root root    3456 Jun 18 04:12 sb_percentile.c
-rw-r--r--. 1 root root    1570 Jun 18 04:12 sb_percentile.h
-rw-r--r--. 1 root root   64616 Jun 18 08:49 sb_percentile.o
-rw-r--r--. 1 root root    5982 Jun 18 04:12 sb_timer.c
-rw-r--r--. 1 root root    3796 Jun 18 04:12 sb_timer.h
-rw-r--r--. 1 root root   54544 Jun 18 08:49 sb_timer.o
-rw-r--r--. 1 root root    6860 Jun 18 04:12 sb_win.c
-rw-r--r--. 1 root root    2747 Jun 18 04:12 sb_win.h
drwxr-xr-x. 4 root root    4096 Jun 18 12:50 scripting
-rwxr-xr-x. 1 root root 3300573 Jun 18 12:24 sysbench
[[email protected] sysbench]# ./sysbench --help
./sysbench: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
[[email protected] sysbench]# ldd sysbench
    linux-vdso.so.1 =>  (0x00007fff3dd70000)
    libmysqlclient.so.18 => not found   //重點在這裡,連結庫沒找到,只好手動加一下
    libdl.so.2 => /lib64/libdl.so.2 (0x00007f95b0e55000)
    librt.so.1 => /lib64/librt.so.1 (0x00007f95b0c4d000)
    libm.so.6 => /lib64/libm.so.6 (0x00007f95b09c9000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f95b07ab000)
    libc.so.6 => /lib64/libc.so.6 (0x00007f95b0417000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f95b1068000)
[[email protected] sysbench]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib   //手動建立一個軟連結
[[email protected] sysbench]# ldconfig  //生效
[[email protected] sysbench]# ldd sysbench //在檢視就找到ibmysqlclient.so.18
    linux-vdso.so.1 =>  (0x00007fffc5ffc000)
    libmysqlclient.so.18 => /usr/lib/libmysqlclient.so.18 (0x00007fa7895d8000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007fa7893d4000)
    librt.so.1 => /lib64/librt.so.1 (0x00007fa7891cb000)
    libm.so.6 => /lib64/libm.so.6 (0x00007fa788f47000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fa788d2a000)
    libc.so.6 => /lib64/libc.so.6 (0x00007fa788995000)
    libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007fa78868f000)
    libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fa788479000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fa789bb0000)
[[email protected] sysbench]# ./sysbench --help //執行help成功
[[email protected] ~]# sysbench --help
Missing required command argument.
Usage:
  sysbench [general-options]... --test=<test-name> [test-options]... command

General options:
  --num-threads=N             使用執行緒數 預設[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 [64K]
  --tx-rate=N                 target transaction rate (tps) [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 [off]
  --rand-init=[on|off]        initialize random number generator [off]
  --rand-type=STRING          random numbers distribution {uniform,gaussian,special,pareto} [special]
  --rand-spec-iter=N          number of iterations used for numbers generation [12]
  --rand-spec-pct=N           percentage of values to be treated as 'special' (for special distribution) [1]
  --rand-spec-res=N           percentage of 'special' values to use (for special distribution) [75]
  --rand-seed=N               seed for random number generator, ignored when 0 [0]
  --rand-pareto-h=N           parameter h for pareto distibution [0.2]

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

  --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

Commands: prepare run cleanup help version

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

測試fileio命令幫助:

[[email protected] ~]# sysbench --test=fileio help  
sysbench 0.4.12:  multi-threaded system evaluation benchmark
fileio options: 
引數詳解:
--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,即可32

測試cpu命令幫助:

[root@db-master ~]# sysbench --test=cpu help
sysbench 0.4.12:  multi-threaded system evaluation benchmark
cpu options:
 引數詳解:
  --cpu-max-prime=N      用來選項指定最大的素數,具體引數可以根據CPU的效能來設定,預設為10000

測試memory命令幫助:

[root@db-master ~]# sysbench  --test=memory help
sysbench 0.4.12:  multi-threaded system evaluation benchmark
memory options:
引數詳解:
  --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

測試threads命令幫助:

[[email protected]-master ~]# sysbench  --test=threads help
sysbench 0.4.12:  multi-threaded system evaluation benchmark
threads options:
引數詳解: 
  --thread-yields=N      指定每個請求的壓力,預設為1000
  --thread-locks=N       指定每個執行緒的鎖數量,預設為8

測試mutex命令幫助:

[[email protected] ~]# sysbench  --test=mutex help 
sysbench 0.4.12:  multi-threaded system evaluation benchmark
mutex options:
引數詳解:
  --mutex-num=N    陣列互斥的總大小。預設是4096
  --mutex-locks=N    每個執行緒互斥鎖的數量。預設是50000
  --mutex-loops=N    內部互斥鎖的空迴圈數量。預設是10000

測試oltp命令幫助:

[[email protected] ~]# sysbench --test=oltp help 
sysbench 0.4.12:  multi-threaded system evaluation benchmark
oltp options:
引數詳解:
  --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      範圍查詢的範圍大小,該值應比oltp-table-size小。預設是100
  --oltp-point-selects=N          單個事務中指定的selec查詢個數 [10]
  --oltp-simple-ranges=N          單個事務中指定的簡單範圍查詢個數 [1]
  --oltp-sum-ranges=N             單個事務中指定的SUM範圍查詢個數 [1]
  --oltp-order-ranges=N           單個事務中指定的ORDER範圍查詢個數 [1]
  --oltp-distinct-ranges=N         單個事務中指定的DISTINCT範圍查詢個數 [1]
  --oltp-index-updates=N          單個事務中指定的使用索引更新的個數 [1]
  --oltp-non-index-updates=N     單個事務中指定的不使用索引更新的個數 [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    特殊分佈的百分比值 (for special distribution)。 預設是1
  --oltp-dist-res=N    ‘special’的百分比值。預設是75
General database options:
  --db-driver=STRING  specifies database driver to use ('help' to get list of available drivers)
  --db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto]
Compiled-in database drivers:
  mysql - MySQL driver
  pgsql - PostgreSQL driver
mysql options:
  --mysql-host=[LIST,...]       MySQL server 地址 預設[localhost]
  --mysql-port=N                MySQL server 埠 預設[3306]
  --mysql-socket=STRING         MySQL socket
  --mysql-user=STRING           MySQL 使用者名稱 預設[sbtest]
  --mysql-password=STRING       MySQL 密碼 預設[]
  --mysql-db=STRING             MySQL database name [sbtest]
  --mysql-table-engine=STRING   使用的儲存引擎包括{myisam,innodb,bdb,heap,ndbcluster,federated} 預設[innodb]
  --mysql-engine-trx=STRING     whether storage engine used is transactional or not {yes,no,auto} [auto]
  --mysql-ssl=[on|off]          use SSL connections, if available in the client library [off]
  --myisam-max-rows=N           max-rows parameter for MyISAM tables [1000000]
  --mysql-create-options=STRING additional options passed to CREATE TABLE []
pgsql options:
  --pgsql-host=STRING     PostgreSQL server host [localhost]
  --pgsql-port=N          PostgreSQL server port [5432]
  --pgsql-user=STRING     PostgreSQL user [sbtest]
  --pgsql-password=STRING PostgreSQL password []
  --pgsql-db=STRING       PostgreSQL database name [sbtest]

總結:
以上就是sysbench工具的安裝配置及相關選項引數的介紹,可以根據自己的需要新增對應的引數進行壓力測試即可。在下一篇文件中將會對上面的幾種模式進行相應的測試。

不用在目錄執行sysbench

[root@localhost sysbench]# cp /root/sysbench/sysbench/sysbench /usr/local/bin/
[root@localhost sysbench]# cd /root
[root@localhost ~]# sysbench --help

CPU測試:

sysbench CPU測試使用64位整數,測試計算素數直到某個最大值(cpu-max-prime)所需要的時間,
檢視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取值為”執行緒數量”即可

[[email protected] ~]# sysbench --test=cpu --cpu-max-prime=10000 --num-threads=2 run
sysbench 0.5:  multi-threaded system evaluation benchmark

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


Primer numbers limit: 10000

Threads started!


General statistics:
    total time:                          6.0122s
    total number of events:              10000
    total time taken by event execution: 12.0109s
    response time:
         min:                                  1.04ms
         avg:                                  1.20ms
         max:                                  7.87ms
         approx.  95 percentile:               1.43ms

Threads fairness:
    events (avg/stddev):           5000.0000/9.00
    execution time (avg/stddev):   6.0055/0.00

執行緒(thread)測試

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

[[email protected] ~]# sysbench --test=threads --num-threads=2 --thread-yields=100 --thread-locks=2 run
sysbench 0.5:  multi-threaded system evaluation benchmark

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


Threads started!


General statistics:
    total time:                          0.4479s
    total number of events:              10000
    total time taken by event execution: 0.8868s
    response time:
         min:                                  0.02ms
         avg:                                  0.09ms
         max:                                  3.87ms
         approx.  95 percentile:               0.14ms

Threads fairness:
    events (avg/stddev):           5000.0000/1.00
    execution time (avg/stddev):   0.4434/0.00

檔案IO效能測試

生成需要的測試檔案,檔案總大小5G,16個併發執行緒。執行完後會在當前目錄下生成一堆小檔案。
在測試之前先看下磁碟空間

[[email protected] ~]# df -hl
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              52G   11G   41G  21% /
tmpfs                 497M     0  497M   0% /dev/shm
[[email protected] ~]# sysbench --test=fileio --file-total-size=2g --file-test-mode=rndrw --num-threads=2 --init-rng=on --file-num=16 --file-block-size=16384 run
sysbench 0.5:  multi-threaded system evaluation benchmark

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


Extra file open flags: 0
16 files, 128Mb each
2Gb total file size
Block size 16Kb
Number of IO requests: 10000
Read/Write ratio for combined random IO test: 1.50
Periodic FSYNC enabled, calling fsync() each 100 requests.
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing random r/w test
Threads started!

Operations performed:  5999 reads, 4001 writes, 1600 Other = 11600 Total
Read(每秒隨機讀) 93.734Mb  Written(隨機寫) 62.516Mb  Total transferred 156.25Mb  (27.144Mb/sec) 吞吐量
 1737.20 Requests/sec executed

General statistics:
    total time:                          5.7564s
    total number of events:              10000
    total time taken by event execution: 5.0908s
    response time:
         min:                                  0.00ms
         avg:                                  0.51ms
         max:                                159.40ms
         approx.  95 percentile:               0.13ms

Threads fairness:
    events (avg/stddev):           5000.0000/306.00
    execution time (avg/stddev):   2.5454/0.50

測試完成執行cleanup
測試結束後,記得執行cleanup,以確保測試所產生的檔案都已刪除:
[[email protected] ~]# sysbench --test=fileio --file-num=16 --file-total-size=2g cleanup
sysbench 0.5:  multi-threaded system evaluation benchmark

Removing test files...

互斥鎖(Mutex)測試

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

[[email protected] ~]# sysbench --test=mutex --num-threads=2 --mutex-num=1024 --mutex-locks=10000 --mutex-loops=5000 run
sysbench 0.5:  multi-threaded system evaluation benchmark

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


Threads started!


General statistics:
    total time:                          0.0013s
    total number of events:              2
    total time taken by event execution: 0.0010s
    response time:
         min:                                  0.46ms
         avg:                                  0.52ms
         max:                                  0.59ms
         approx.  95 percentile:               0.58ms

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

記憶體測試

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

[[email protected] ~]# sysbench --test=memory --num-threads=2 --memory-block-size=8192 --memory-total-size=1g run
sysbench 0.5:  multi-threaded system evaluation benchmark

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


Threads started!

Operations performed: 131072 (1264058.81 ops/sec)

1024.00 MB transferred (9875.46 MB/sec) 吞吐量


General statistics:
    total time:                          0.1037s
    total number of events:              131072
    total time taken by event execution: 0.1677s
    response time:
         min:                                  0.00ms
         avg:                                  0.00ms
         max:                                  4.30ms
         approx.  95 percentile:               0.00ms   95%的時間分佈

Threads fairness:
    events (avg/stddev):           65536.0000/509.00
    execution time (avg/stddev):   0.0839/0.00

對mysql事務型OLTP的測試

sysbench 0.5通過一系列LUA指令碼來替換之前的oltp,來模擬更接近真實的基準測試環境。這些測試指令碼包含:insert.lua、oltp.lua、parallel_prepare.lua、select_random_points.lua、update_index.lua、delete.lua oltp_simple.lua、select.lua、select_random_ranges.lua、update_non_index.lua,指令碼使用方式基本類似。
sysbench 0.5預設使用sbtest庫,但是需要自己手工先建立好,也可以使用–mysql-db指定,其他非預設項指定選項:

-mysql-host
-mysql-port
-mysql-socket
-mysql-user
-mysql-password
-mysql-db
-mysql-ssl

prepare
生成表並插入資料,可使用parallel_prepare.lua指令碼來並行準備資料。

–db-driver 伺服器型別 mysql | drizzle,預設為mysql
–mysql-table-engine 表存數引擎
–myisam-max-rows MyISAM表MAX_ROWS選項(用於大表)
–oltp-table-count 生成表數量[sbtest1、sbtest2...]
–oltp-table-size 生成表的行數
–oltp-secondary ID列生成二級索引而不是主鍵
–oltp-auto-inc 設定ID列是否自增 on | off,預設為on

1 prepare準備階段

首先要做的就是資料準備
對於mysql的OLTP測試,和file一樣,同樣需要經歷prepare,run,cleanup三個階段。prepare階段會在資料庫中產生一張指定行數的表,預設表在sbtest架構下,表名為
sbtest(sysbench預設生成表的儲存引擎為innodb),如建立一張100萬條記錄的表:
create database sbtest;
然後

[[email protected] ~]# cd /root/sysbench/sysbench/
./sysbench --test=tests/db/parallel_prepare.lua --max-time=100 --oltp-dist-type=uniform --max-requests=0 --mysql-user=root --mysql-password="" --mysql-table-engine=innodb --oltp-table-size=100 --oltp-tables-count=8 --oltp-range-size=90 --oltp-point-selects=1 --oltp-simple-ranges=1 --oltp-sum-ranges=1 --oltp-order-ranges=1 --oltp-distinct-ranges=1 --oltp-non-index-updates=10 --num-threads=20  --mysql-host=127.0.0.1 --mysql-port=3306 prepare

測試:

./sysbench --test=tests/db/oltp.lua --max-time=100 --oltp-dist-type=uniform --max-requests=0 --mysql-user=root --mysql-password="" --mysql-table-engine=innodb
--oltp-table-size=100 --oltp-tables-count=8 --oltp-range-size=90 --oltp-point-selects=1 --oltp-simple-ranges=1 --oltp-sum-ranges=1 --oltp-order-ranges=1 --oltp-distinct-ranges=1 --oltp-non-index-updates=10 --num-threads=20  --mysql-host=127.0.0.1 --mysql-port=3306 run

引數說明:
–test 指定使用的測試指令碼
–max-time=100 指定測試時長為100s
–mysql-user 資料庫帳號
–mysql-password 資料庫密碼
–mysql-table-engine 儲存引擎型別
–test 測試的型別oltp系統
–num-threads 測試的執行緒數
–mysql-host 資料庫地址
–mysql-port 資料庫埠

測試結果:

Threads started!

OLTP test statistics:
    queries performed:
        read:                            179470-- 讀總數
        write:                           453935-- 寫總數
        other:                           70678-- 其他操作總數(SELECT、INSERT、UPDATE、DELETE之外的操作,例如COMMIT等)
        total:                           704083 -- 全部總數
    transactions事務量:                        34784  (347.32 per sec.)-- 總事務數(每秒事務數)
    read/write requests讀寫總操作:                 633405 (6324.57 per sec.) -- 讀寫總數(每秒讀寫次數)
    other operations其他操作:                    70678  (705.72 per sec.)-- 其他操作總數(每秒其他操作次數)
    ignored errors:                      1110   (11.08 per sec.)-- 每秒忽略的錯誤
    reconnects:                          0      (0.00 per sec.)--每秒重連次數

General statistics:
    total time(總時長):                          100.1499s -- 總耗時
    total number of events:              34784 -- 共發生多少事務數
    total time taken by event execution: 1996.2507s -- 所有事務耗時相加(不考慮並行因素)
    response time(相應時間):
         min最小:                                  2.54ms-- 最小耗時
         avg平均:                                 57.39ms-- 平均耗時
         max最大:                               1074.85ms -- 最長耗時
         approx.  95 percentile:             133.50ms-- 超過99%平均耗時

Threads fairness:
    events (avg/stddev):           1739.2000/35.03
    execution time (avg/stddev):   99.8125/0.05

別忘了善後清理工作

[[email protected]ocalhost ~]# sysbench --test=/root/sysbench/sysbench/tests/db/oltp.lua --oltp-table-size=100 --mysql-db=sbtest --mysql-user=root --mysql-password="" --oltp-tables-count=8 --mysql-host=127.0.0.1 cleanup
sysbench 0.5:  m