壓測工具 sysbench安裝及使用簡介(0.4.12\0.5\1.0.x+版本)

神諭丶發表於2015-11-30

--2017-11-07更新 sysbench 1.0.9+安裝及簡單使用:{

安裝1:通過EPEL直接yum安裝
EPEL可以裝一下(如果沒裝)

wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
yum install -y sysbench 即可

此處僅針對mysql做oltp測試做介紹:
安裝好後,會在/usr/share/sysbench/下存放lua指令碼
安裝2:https://github.com/akopytov/sysbench把sysbench.zip或者直接git clone下來
cd xxx/sysbench-master
make clean
./autogen.sh
./configure --prefix=/usr/local/sysbench/ --with-mysql  --with-mysql-libs=/usr/lib64/mysql/
make && make install

根據具體情況可能需要指定不同的--with-mysql-libs
此處mysql依賴,通過rpm包預設安在/usr/lib64/mysql/


用法與老版本相近,此處舉例:
sysbench --db-driver=mysql /usr/share/sysbench/oltp_read_only.lua --mysql-host=$host --mysql-port=$port --mysql-user=$user --mysql-password=$password --mysql-db=sysbench(需自行建立) --tables=100 --table-size=5000000 --report-interval=10 --threads=64 --time=7200 prepare/run/cleanup

}

--2017-11-07更新 sysbench 0.5 安裝及簡單使用
{

$ sudo yum install gcc gcc-c++ automake make libtool mysql-community-devel
$ cd /tmp && git clone https://github.com/akopytov/sysbench.git
$ cd /tmp/sysbench && ./autogen.sh
$ ./configure --prefix=/usr/local/sysbench-0.5 --with-mysql
$ make && make install


$ cd /usr/local/sysbench-0.5/bin

如mysql
$ ./sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=sysbench --mysql-user=root --mysql-host=127.0.0.1 --mysql-password=123456 prepare

$ ./sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=sysbench --mysql-user=root --mysql-host=127.0.0.1 --mysql-password=123456 --max-time=60 --oltp-read-only=on --max-requests=0 --num-threads=8 run

如fio等
$ ./sysbench --test=fileio --file-total-size=5G prepare
$ ./sysbench --test=fileio --file-total-size=5G --file-test-mode=rndrw --init-rng=on --max-time=300 --max-requests=0 run
$ ./sysbench --test=fileio --file-total-size=5G cleanup

}


此處用的是sysbench 0.5

0.4.12版本和0.5類似




可以為使用者提供如下測試:

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



p.s.
在mysql官方推薦的是sysbench 0.4.12.10
http://dev.mysql.com/downloads/benchmarks.html

 
一. 安裝
解壓後:

  1. $ cd sysbench-0.5
  2. $ ./autogen.sh
  3. $ ./configure --prefix=(選擇sysbench安裝在哪) (如果需要測試oltp可以加後面的選項)--with-mysql-includes=/usr/local/mysql/include(換成你自己的) --with-mysql-libs=/usr/local/mysql/lib --with-mysql (還可以支援oracle和pgsql
  4. $ make && make install

可能需要安裝一下環境:
  1. $ sudo yum -y install libtool automake

原始碼來安裝
autoconf和automake

附帶這兩個原始碼包url
http://mirrors.kernel.org/gnu/autoconf/autoconf-2.65.tar.gz
http://mirrors.kernel.org/gnu/automake/automake-1.15.tar.gz


置環境變數:
  1. $ vi ~/.bash_profile

sysbench --version 或者直接 sysbench 可以看到版本資訊或者幫助資訊
  1. $ source ~/.bash_profile
  2. $ sysbench --version
  3. sysbench 0.5
如果報錯:
sysbench: error while loading shared libraries: libmysqlclient_r.so.15: cannot open shared object file: No such file or directory
則有可能是lib路徑不對

  1. $ sudo vi /etc/ld.so.conf
  2. 新增 /usr/local/mysql/lib 儲存退出
  3. $ sudo /sbin/ldconfig -v





二. file IO 

指定--test=fileio即可。

fileio options:
  --file-num=N                  number of files to create [128]       
// 建立的檔案數

  --file-block-size=N           block size to use in all IO operations [16384]       
// 塊大小,比如4096為4K

  --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]       
// 在某個數請求之後做fsync(),預設為100

  --file-fsync-all=[on|off]     do fsync() after each write operation [off]       
// 開啟或關閉在每個寫操作後執行fsync(),預設為OFF

  --file-fsync-end=[on|off]     do fsync() at the end of test [on]       
// 開啟或關閉結束test時執行fsync(),預設為ON

  --file-fsync-mode=STRING      which method to use for synchronization {fsync, fdatasync} [fsync]       
// 使用什麼方法同步,預設為fsync

  --file-merged-requests=N      merge at most this number of IO requests if possible (0 - don't merge) [0]       
// 儘可能合併IO請求的數量,預設為0

  --file-rw-ratio=N             reads/writes ratio for combined test [1.5]       
// 讀寫比例,預設為1.5



測試例子:

  1. $ sysbench --test=fileio --file-num=10 --file-total-size=1G --file-block-size=4096 --file-test-mode=seqwr --file-io-mode=sync prepare        // 先做檔案準備 引數為prepare 建立10個檔案 每個102.4MB 檔案塊為4K 
  2. sysbench 0.5: multi-threaded system evaluation benchmark
  3. 10 files, 104857Kb each, 1023Mb total
  4. Creating files for the test...
  5. Extra file open flags: 0
  6. Creating file test_file.0
  7. Creating file test_file.1
  8. Creating file test_file.2
  9. Creating file test_file.3
  10. Creating file test_file.4
  11. Creating file test_file.5
  12. Creating file test_file.6
  13. Creating file test_file.7
  14. Creating file test_file.8
  15. Creating file test_file.9
  16. 1073766400 bytes written in 12.11 seconds (84.56 MB/sec).

  17. $ sysbench --test=fileio --file-num=10 --file-total-size=1G --file-block-size=4096 --file-test-mode=seqwr --file-io-mode=sync run    // 開始測試,引數改為run
  18. sysbench 0.5: multi-threaded system evaluation benchmark
  19. Running the test with following options:
  20. Number of threads: 1
  21. Random number generator seed is 0 and will be ignored
  22. Extra file open flags: 0
  23. 10 files, 102.4Mb each
  24. 1024Mb total file size
  25. Block size 4Kb
  26. Periodic FSYNC enabled, calling fsync() each 100 requests.
  27. Calling fsync() at the end of test, Enabled.
  28. Using synchronous I/O mode
  29. Doing sequential write (creation) test
  30. Threads started!
  31. Operations performed: 0 reads, 10000 writes, 1000 Other = 11000 Total
  32. Read 0b Written 39.062Mb Total transferred 39.062Mb (8.3495Mb/sec)
  33. 2137.47 Requests/sec executed
  34. General statistics:
  35. total time: 4.6784s
  36. total number of events: 10000
  37. total time taken by event execution: 0.0767s
  38. response time:
  39. min: 0.00ms
  40. avg: 0.01ms
  41. max: 0.08ms
  42. approx. 95 percentile: 0.01ms
  43. Threads fairness:
  44. events (avg/stddev): 10000.0000/0.00
  45. execution time (avg/stddev): 0.0767/0.00
  46. $ sysbench --test=fileio --file-num=10 --file-total-size=1G --file-block-size=4096 --file-test-mode=seqwr --file-io-mode=sync cleanup    // 引數為cleanup 清除測試檔案
  47. sysbench 0.5: multi-threaded system evaluation benchmark
  48. Removing test files...


三. CPU test

指定--test=cpu即可

cpu options:
  --cpu-max-prime=N      upper limit for primes generator [10000]       
// 設定素數最大上限值,預設為10000 



測試例子:

  1. $ sysbench --test=cpu --cpu-max-prime=1024 run
  2. sysbench 0.5: multi-threaded system evaluation benchmark
  3. Running the test with following options:
  4. Number of threads: 1
  5. Random number generator seed is 0 and will be ignored
  6. Primer numbers limit: 1024
  7. Threads started!
  8. General statistics:
  9. total time: 0.4622s
  10. total number of events: 10000
  11. total time taken by event execution: 0.4561s
  12. response time:
  13. min: 0.04ms
  14. avg: 0.05ms
  15. max: 0.15ms
  16. approx. 95 percentile: 0.05ms
  17. Threads fairness:
  18. events (avg/stddev): 10000.0000/0.00
  19. execution time (avg/stddev): 0.4561/0.00


四. memory test

指定--test=memory即可

memory options:
  --memory-block-size=SIZE    size of memory block for test [1K]         
// 記憶體塊的大小,預設為1K

  --memory-total-size=SIZE    total size of data to transfer [100G]       
// 總共需要傳輸的大小,預設為100G

  --memory-scope=STRING       memory access scope {global,local} [global]
// 記憶體訪問是全域性還是本地,預設為全域性

  --memory-hugetlb=[on|off]   allocate memory from HugeTLB pool [off]
// 是否從HugeTLB中分配記憶體,預設為否

  --memory-oper=STRING        type of memory operations {read, write, none} [write]
// 記憶體的操作方式,讀,寫,或none,預設為寫

  --memory-access-mode=STRING memory access mode {seq,rnd} [seq]
// 記憶體訪問模式,順序或隨機,預設為序列



測試例子:

  1. $ sysbench --test=memory --memory-block-size=4096 --memory-total-size=50G --memory-oper=read --memory-access-mode=rnd run
  2. sysbench 0.5: multi-threaded system evaluation benchmark
  3. Running the test with following options:
  4. Number of threads: 1
  5. Random number generator seed is 0 and will be ignored
  6. Threads started!
  7. Operations performed: 13107200 (950195.57 ops/sec)
  8. 51200.00 MB transferred (3711.70 MB/sec)
  9. General statistics:
  10. total time: 13.7942s
  11. total number of events: 13107200
  12. total time taken by event execution: 5.8543s
  13. response time:
  14. min: 0.00ms
  15. avg: 0.00ms
  16. max: 0.06ms
  17. approx. 95 percentile: 0.00ms
  18. Threads fairness:
  19. events (avg/stddev): 13107200.0000/0.00
  20. execution time (avg/stddev): 5.8543/0.00


五. threads test

指定--test=threads即可。

threads options:
  --thread-yields=N      number of yields to do per request [1000]
  --thread-locks=N       number of locks per thread [8]
// 每個執行緒鎖的數目



測試例子:

  1. [op@sAno1y sysbench]$ sysbench --test=threads run
  2. sysbench 0.5: multi-threaded system evaluation benchmark
  3. Running the test with following options:
  4. Number of threads: 1
  5. Random number generator seed is 0 and will be ignored
  6. Threads started!
  7. General statistics:
  8. total time: 3.6699s
  9. total number of events: 10000
  10. total time taken by event execution: 3.6635s
  11. response time:
  12. min: 0.35ms
  13. avg: 0.37ms
  14. max: 0.74ms
  15. approx. 95 percentile: 0.37ms
  16. Threads fairness:
  17. events (avg/stddev): 10000.0000/0.00
  18. execution time (avg/stddev): 3.6635/0.00


六. mutex test

指定--test=mutex即可。

mutex options:
  --mutex-num=N        total size of mutex array [4096]
// 互斥體資料大小,預設為4K

  --mutex-locks=N      number of mutex locks to do per thread [50000]
// 每個執行緒的互斥鎖,預設為50000

  --mutex-loops=N      number of empty loops to do inside mutex lock [10000]
// 互斥鎖內空迴圈的數目,預設為10000



測試例子:

  1. [op@sAno1y sysbench]$ sysbench --test=mutex --mutex-num=8192 --number-locks=102400 run
  2. sysbench 0.5: multi-threaded system evaluation benchmark
  3. Running the test with following options:
  4. Number of threads: 1
  5. Random number generator seed is 0 and will be ignored
  6. Threads started!
  7. General statistics:
  8. total time: 0.0049s
  9. total number of events: 1
  10. total time taken by event execution: 0.0048s
  11. response time:
  12. min: 4.79ms
  13. avg: 4.79ms
  14. max: 4.79ms
  15. approx. 95 percentile: 4.79ms
  16. Threads fairness:
  17. events (avg/stddev): 1.0000/0.00
  18. execution time (avg/stddev): 0.0048/0.00


七. oltp test
指定--test=oltp即可。

oltp options:
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

mysql options:
  --mysql-host=[LIST,...]       MySQL server host [localhost]
  --mysql-port=N                MySQL server port [3306]
  --mysql-socket=STRING         MySQL socket
  --mysql-user=STRING           MySQL user [sbtest]
  --mysql-password=STRING       MySQL password []
  --mysql-db=STRING             MySQL database name [sbtest]
  --mysql-table-engine=STRING   storage engine to use for the test table {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 []


建立測試資料:
--oltp-table-size為單表建立資料的數量

  1. sysbench --test=oltp --mysql-table-engine=innodb --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-host=localhost --mysql-password=root --mysql-db=test --oltp-table-size=50000000 prepare

開始run:其中--num-threads為併發數,--max-time為測試的時長(秒)

  1. sysbench --test=oltp --mysql-table-engine=innodb --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-host=localhost --mysql-password=root --mysql-db=test --oltp-table-size=5000000 --num-threads=1000 --max-time=60 --max-requests=0 --report-interval=10 run

在sysbench 0.5的版本中,則可以使用一個lua指令碼來建立表,並且可以指定多張表,比如:
其中 oltp_tables_count為指定prepare幾張,--rand-init開啟則表示隨機寫數:

  1. sysbench --test=/opt/app/sysbench-0.5/sysbench/tests/db/oltp.lua --mysql-table-engine=innodb --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-host=localhost --mysql-password=root --mysql-db=test \
  2. --oltp-table-size=50000000 --oltp_tables_count=10 --rand-init=on prepare

生成的測試表的資料樣例:
*************************** 1. row ***************************
 id: 1
  k: 50206885
  c: 08566691963-88624912351-16662227201-46648573979-64646226163-77505759394-75470094713-41097360717-15161106334-50535565977
pad: 63188288836-92351140030-06390587585-66802097351-49282961843
*************************** 2. row ***************************
 id: 2
  k: 49910688
  c: 95969429576-20587925969-20202408199-67602281819-18293380360-38184587501-73192830026-41693404212-56705243222-89212376805
pad: 09512147864-77936258834-40901700703-13541171421-15205431759
*************************** 3. row ***************************
 id: 3
  k: 50204693
  c: 26283585383-48610978532-72166636310-67148386979-89643583984-06169170732-23477134062-17788128188-73465768032-24619558652
pad: 21979564480-87492594656-60524686334-78820761788-57684966682
*************************** 4. row ***************************
 id: 4
  k: 52180295
  c: 72200234338-75748118569-08939863650-01688814841-36798767826-71560494483-89421079440-11810718401-29133837777-68338627243
pad: 80945118876-33522718290-51523426562-15979384524-91541356971
*************************** 5. row ***************************
 id: 5
  k: 41395699
  c: 29279855805-99348203463-85191104223-39587263726-81794340135-73817557808-54578801760-64404111877-55434439976-37212880746
pad: 59222897263-22759023974-22020489960-93434521232-77981152534
5 rows in set (0.00 sec)




測試結果明:
  1. No DB drivers specified, using mysql
  2. Running the test with following options:
  3. Number of threads: 1
  4. Random number generator seed is 0 and will be ignored
  5. Doing OLTP test.
  6. Running mixed OLTP test
  7. Using Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases)
  8. Using "BEGIN" for starting transactions
  9. Using auto_inc on the id column
  10. Maximum number of requests for OLTP test is limited to 10000
  11. Using 1 test tables
  12. Threads started!
  13. Done.
  14. OLTP test statistics:
  15. queries performed:
  16. read: 140000 -- 讀總數
  17. write: 50000 -- 寫總數
  18. other: 20000 -- 其他操作總數(除了dml之外的操作)
  19. total: 210000 -- 全部總數
  20. transactions: 10000 (229.62 per sec.) -- 總事務數
  21. deadlocks: 0 (0.00 per sec.) -- 死鎖數
  22. read/write requests: 190000 (4362.73 per sec.) -- 讀寫總數
  23. other operations: 20000 (459.23 per sec.) -- 其他操作總數
  24. General statistics:
  25. total time: 43.5507s -- 總耗時
  26. total number of events: 10000 -- 總共發生的事務數
  27. total time taken by event execution: 43.4491 -- 所有事務耗時相加(不考慮並行因素)
  28. response time:
  29. min: 3.75ms -- 最小耗時
  30. avg: 4.34ms -- 平均耗時
  31. max: 30.58ms -- 最大耗時
  32. approx. 95 percentile: 4.44ms -- 去掉5%的最大最小值,剩餘95%平均耗時
  33. Threads fairness:
  34. events (avg/stddev): 10000.0000/0.00
  35. execution time (avg/stddev): 43.4491/0.00




附錄: (通用選項)
  1. Usage:
  2. sysbench [general-options]... --test= [test-options]... command
  3. General options:
  4. --num-threads=N number of threads to use [1]
  5. --max-requests=N limit for total number of requests [10000]
  6. --max-time=N limit for total execution time in seconds [0]
  7. --forced-shutdown=STRING amount of time to wait after --max-time before forcing shutdown [off]
  8. --thread-stack-size=SIZE size of stack per thread [64K]
  9. --tx-rate=N target transaction rate (tps) [0]
  10. --report-interval=N periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0]
  11. --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. []
  12. --test=STRING test to run
  13. --debug=[on|off] print more debugging info [off]
  14. --validate=[on|off] perform validation checks where possible [off]
  15. --help=[on|off] print help and exit
  16. --version=[on|off] print version and exit [off]
  17. --rand-init=[on|off] initialize random number generator [off]
  18. --rand-type=STRING random numbers distribution {uniform,gaussian,special,pareto} [special]
  19. --rand-spec-iter=N number of iterations used for numbers generation [12]
  20. --rand-spec-pct=N percentage of values to be treated as 'special' (for special distribution) [1]
  21. --rand-spec-res=N percentage of 'special' values to use (for special distribution) [75]
  22. --rand-seed=N seed for random number generator, ignored when 0 [0]
  23. --rand-pareto-h=N parameter h for pareto distibution [0.2]
  24. Log options:
  25. --verbosity=N verbosity level {5 - debug, 0 - only critical messages} [3]
  26. --percentile=N percentile rank of query response times to count [95]
  27. Compiled-in tests:
  28. fileio - File I/O test
  29. cpu - CPU performance test
  30. memory - Memory functions speed test
  31. threads - Threads subsystem performance test
  32. mutex - Mutex performance test
  33. Commands: prepare run cleanup help version
  34. See 'sysbench --test= help' for a list of options for each test.


作者公眾號(持續更新)


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

相關文章