MySQL如何使用sysbench做OLTP基準(zhǔn)測(cè)試

這篇文章給大家分享的是有關(guān)MySQL如何使用sysbench做OLTP基準(zhǔn)測(cè)試的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。

創(chuàng)新互聯(lián)專注于網(wǎng)站建設(shè)|成都網(wǎng)站維護(hù)|優(yōu)化|托管以及網(wǎng)絡(luò)推廣,積累了大量的網(wǎng)站設(shè)計(jì)與制作經(jīng)驗(yàn),為許多企業(yè)提供了網(wǎng)站定制設(shè)計(jì)服務(wù),案例作品覆蓋成都邊坡防護(hù)網(wǎng)等行業(yè)。能根據(jù)企業(yè)所處的行業(yè)與銷售的產(chǎn)品,結(jié)合品牌形象的塑造,量身建設(shè)品質(zhì)網(wǎng)站。

一、 安裝
① 下載源碼包:https://dev.mysql.com/downloads/benchmarks.html
② 安裝依賴 yum -y install automake autoconf libtool
③tar xzvf sysbench-0.4.12.10.tar.gz; cd sysbench-0.4.12.10/
④./autogen.sh; ./configure
⑤ make && make install
然后我們可以在sysbench 目錄看到可以執(zhí)行文件sysbench了

二、命令
首先看下命令基本用法 

  1. root@10.30.5.2:sysbench# ./sysbench --help

  2. Usage:

  3. sysbench [general-options]... --test= [test-options]... command

  4. General options:

  5. --num-threads=N             number of threads to use [1]

  6. --max-requests=N            limit for total number of requests [10000]

  7. --max-time=N                limit for total execution time in seconds [0]

  8. --forced-shutdown=STRING    amount of time to wait after --max-time before forcing shutdown [off]

  9. --thread-stack-size=SIZE    size of stack per thread [32K]

  10. --init-rng=[on|off]         initialize random number generator [off]

  11. --seed-rng=N                seed for random number generator, ignored when 0 [0]

  12. --tx-rate=N                 target transaction rate (tps) [0]

  13. --tx-jitter=N               target transaction variation, in microseconds [0]

  14. --report-interval=N         periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0]

  15. --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. []

  16. --test=STRING               test to run

  17. --debug=[on|off]            print more debugging info [off]

  18. --validate=[on|off]         perform validation checks where possible [off]

  19. --help=[on|off]             print help and exit

  20. --version=[on|off]          print version and exit

  21. Log options:

  22. --verbosity=N      verbosity level {5 - debug, 0 - only critical messages} [4]

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

  24. Compiled-in tests:

  25. fileio - File I/O test

  26. cpu - CPU performance test

  27. memory - Memory functions speed test

  28. threads - Threads subsystem performance test

  29. mutex - Mutex performance test

  30. oltp - OLTP test

  31. Commands: prepare run cleanup help version

  32. See 'sysbench --test= help' for a list of options for each test.

以上可以看到 sysbench可以測(cè)試的有 CPU 、磁盤IO、內(nèi)存、線程、MUTEX 以及OLTP ,
常用參數(shù):
--num-threads=N     并發(fā)線程數(shù)
--max-requests=N    限制壓測(cè)請(qǐng)求總數(shù)
--max-time=N        限制壓測(cè)時(shí)間

這里看下OLTP測(cè)試方法

  1. ./sysbench --test=oltp help

  2. sysbench 0.4.12.10:  multi-threaded system evaluation benchmark

  3. oltp options:

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

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

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

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

  8. --oltp-avoid-deadlocks=[on|off]          generate update keys in increasing order to avoid deadlocks [off]

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

  10. --oltp-range-size=N                      range size for range queries [100]

  11. --oltp-point-selects=N                   number of point selects [10]

  12. --oltp-use-in-statement=N                Use IN-statement with 10 PK lookups per query [0]

  13. --oltp-simple-ranges=N                   number of simple ranges [1]

  14. --oltp-sum-ranges=N                      number of sum ranges [1]

  15. --oltp-order-ranges=N                    number of ordered ranges [1]

  16. --oltp-distinct-ranges=N                 number of distinct ranges [1]

  17. --oltp-index-updates=N                   number of index update [1]

  18. --oltp-non-index-updates=N               number of non-index updates [1]

  19. --oltp-nontrx-mode=STRING                mode for non-transactional test {select, update_key, update_nokey, insert, delete} [select]

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

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

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

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

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

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

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

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

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

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

  30. --oltp-point-select-mysql-handler=[on|off]Use MySQL HANDLER for point select [off]

  31. --oltp-point-select-all-cols=[on|off]    select all columns for the point-select query [off]

  32. --oltp-secondary=[on|off]                Use a secondary index in place of the PRIMARY index [off]

  33. --oltp-num-partitions=N                  Number of partitions used for test table [0]

  34. --oltp-num-tables=N                      Number of test tables [1]

  35. General database options:

  36. --db-driver=STRING  specifies database driver to use ('help' to get list of available drivers)

  37. --db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto]

  38. Compiled-in database drivers:

  39. mysql - MySQL driver

  40. mysql options:

  41. --mysql-host=[LIST,...]       MySQL server host [localhost]

  42. --mysql-port=N                MySQL server port [3306]

  43. --mysql-socket=STRING         MySQL socket

  44. --mysql-user=STRING           MySQL user [sbtest]

  45. --mysql-password=STRING       MySQL password []

  46. --mysql-db=STRING             MySQL database name [sbtest]

  47. --mysql-table-engine=STRING   storage engine to use for the test table {myisam,innodb,bdb,heap,ndbcluster,federated} [innodb]

  48. --mysql-engine-trx=STRING     whether storage engine used is transactional or not {yes,no,auto} [auto]

  49. --mysql-ssl=[on|off]          use SSL connections, if available in the client library [off]

  50. --myisam-max-rows=N           max-rows parameter for MyISAM tables [1000000]

  51. --mysql-create-options=STRING additional options passed to CREATE TABLE []

說(shuō)明 :
常用參數(shù)
① 基本參數(shù)
--db-driver=mysql     對(duì)mysql進(jìn)行 OLTP 基準(zhǔn)測(cè)試
--mysql-host 、--mysql-port、--mysql-socket、--mysql-user、--mysql-password 這些是基本的參數(shù)我就不解釋了
--mysql-db=xxx  壓測(cè)的database,這里得指定一下
② oltp常用參數(shù)
--oltp-test-mode=complex/simple/nontrx  測(cè)試模式
--oltp-num-tables=10 oltp測(cè)試的表數(shù)量 0.4.10版本最大表數(shù)量16
--oltp-table-size=xxx  測(cè)試表的記錄數(shù)

三、測(cè)試
① 測(cè)試準(zhǔn)備:

  1. root@10.30.5.2:sysbench#./sysbench --num-threads=64 --max-requests=200000 --test=oltp --db-driver=mysql --mysql-user=root --mysql-host=10.30.22.2 --mysql-password=x --oltp-test-mode=complex --mysql-db=tab --oltp-table-size=5000000 --oltp-num-tables=16 prepare

  2. sysbench 0.4.12.10:  multi-threaded system evaluation benchmark

  3. Creating table 'sbtest14'...

  4. Creating table 'sbtest7'...

  5. Creating table 'sbtest'...

  6. Creating table 'sbtest11'...

  7. Creating table 'sbtest8'...

  8. Creating table 'sbtest6'...

  9. Creating table 'sbtest9'...

  10. Creating table 'sbtest12'...

  11. Creating table 'sbtest3'...

  12. Creating table 'sbtest15'...

  13. Creating table 'sbtest2'...

  14. Creating table 'sbtest4'...

  15. Creating table 'sbtest1'...

  16. Creating table 'sbtest5'...

  17. Creating table 'sbtest13'...

  18. Creating table 'sbtest10'...

  19. Creating 5000000 records in table 'sbtest11'...

  20. Creating 5000000 records in table 'sbtest1'...

  21. Creating 5000000 records in table 'sbtest14'...

  22. Creating 5000000 records in table 'sbtest'...

  23. Creating 5000000 records in table 'sbtest6'...

  24. Creating 5000000 records in table 'sbtest2'...

  25. Creating 5000000 records in table 'sbtest13'...

  26. Creating 5000000 records in table 'sbtest15'...

  27. Creating 5000000 records in table 'sbtest12'...

  28. Creating 5000000 records in table 'sbtest4'...

  29. Creating 5000000 records in table 'sbtest3'...

  30. Creating 5000000 records in table 'sbtest9'...

  31. Creating 5000000 records in table 'sbtest8'...

  32. Creating 5000000 records in table 'sbtest10'...

  33. Creating 5000000 records in table 'sbtest5'...

  34. Creating 5000000 records in table 'sbtest7'...

② 測(cè)試結(jié)果

點(diǎn)擊(此處)折疊或打開(kāi)

  1. root@10.30.5.2:sysbench# ./sysbench --num-threads=64 --max-requests=200000 --test=oltp --db-driver=mysql --mysql-user=root --mysql-host=10.30.22.xxx --mysql-password=xxx --oltp-test-mode=complex --mysql-db=tab --oltp-table-size=5000000 --oltp-num-tables=16 run

  2. sysbench 0.4.12.10:  multi-threaded system evaluation benchmark

  3. Running the test with following options:

  4. Number of threads: 64

  5. Random number generator seed is 0 and will be ignored

  6. Doing OLTP test.

  7. Running mixed OLTP test

  8. Using Special distribution (12 iterations,  1 pct of values are returned in 75 pct cases)

  9. Using "BEGIN" for starting transactions

  10. Using auto_inc on the id column

  11. Maximum number of requests for OLTP test is limited to 200000

  12. Using 16 test tables

  13. Threads started!

  14. Done.

  15. OLTP test statistics:

  16. queries performed:

  17. read:                            2800224

  18. write:                           1000080

  19. other:                           400032

  20. total:                           4200336

  21. transactions:                        200016 (2000.64 per sec.)

  22. deadlocks:                           0      (0.00 per sec.)

  23. read/write requests:                 3800304 (38012.16 per sec.)

  24. other operations:                    400032 (4001.28 per sec.)

  25. General statistics:

  26. total time:                          99.9760s

  27. total number of events:              200016

  28. total time taken by event execution: 6394.8091

  29. response time:

  30. min:                                 11.00ms

  31. avg:                                 31.97ms

  32. max:                                293.00ms

  33. approx.  95 percentile:              52.10ms

  34. Threads fairness:

  35. events (avg/stddev):           3125.2500/50.55

  36. execution time (avg/stddev):   99.9189/0.01

③ 測(cè)試清除

點(diǎn)擊(此處)折疊或打開(kāi)

  1. root@10.30.5.2:sysbench# ./sysbench --num-threads=64 --max-requests=200000 --test=oltp --db-driver=mysql --mysql-user=root --mysql-host=10.30.22.xxx --mysql-password=xxx --oltp-test-mode=complex --mysql-db=tab --oltp-table-size=5000000 --oltp-num-tables=16 cleanup

  2. sysbench 0.4.12.10:  multi-threaded system evaluation benchmark

  3. Dropping table 'sbtest'...

  4. Dropping table 'sbtest1'...

  5. Dropping table 'sbtest2'...

  6. Dropping table 'sbtest3'...

  7. Dropping table 'sbtest4'...

  8. Dropping table 'sbtest5'...

  9. Dropping table 'sbtest6'...

  10. Dropping table 'sbtest7'...

  11. Dropping table 'sbtest8'...

  12. Dropping table 'sbtest9'...

  13. Dropping table 'sbtest10'...

  14. Dropping table 'sbtest11'...

  15. Dropping table 'sbtest12'...

  16. Dropping table 'sbtest13'...

  17. Dropping table 'sbtest14'...

  18. Dropping table 'sbtest15'...

  19. Done.


總結(jié):
1> PREPARE階段
   在 PREPARE 階段我們就需要想好,此時(shí)mysql 的配置,如 innodb_flush_log_at_trx_commit 、 sync_binlog 以及BP 的大小等。
   然后結(jié)合 BP 的大小我們需要?jiǎng)?chuàng)建表的記錄數(shù),表的個(gè)數(shù),并發(fā)線程等,綜合考慮
   ① 若數(shù)據(jù)量 < BP 所有數(shù)據(jù)都會(huì)緩存到內(nèi)存,此時(shí)增加 并發(fā)線程數(shù) 來(lái)測(cè)整個(gè)此時(shí)的CPU核數(shù)是否能抗住測(cè)試壓力
   ② 若數(shù)據(jù)量 >> BP 則主要測(cè)試整個(gè)系統(tǒng)的穩(wěn)定性,我們可以結(jié)合監(jiān)控看緩存命中率( orzdba ),以及對(duì)應(yīng)的 磁盤IO( iostat / orzdba ) 等,來(lái)獲取整個(gè)數(shù)據(jù)庫(kù)系統(tǒng)的薄弱點(diǎn)

2> RUN 階段
    在 RUN 階段的同時(shí) ,我們可以通過(guò) orzdba/iostat 等工具查看當(dāng)前的數(shù)據(jù)庫(kù)狀態(tài)
    ① 上面的測(cè)試結(jié)果我們可以看到,    
     transactions: 200016 (2000.64 per sec.) TPS 大概為 2000
     read/write requests: 3800304 (38012.16 per sec.) QPS 達(dá)到 38000
     approx. 95 percentile: 52.10ms  95%的請(qǐng)求相應(yīng)時(shí)間在52.10ms左右
    可以說(shuō)性能是相當(dāng)不錯(cuò)了(這里我測(cè)試的是騰訊云 CDB , 配置為 1000MB 的BP )
    ② 通過(guò)orzdba 結(jié)合running過(guò)程查看數(shù)據(jù)庫(kù)狀態(tài)

點(diǎn)擊(此處)折疊或打開(kāi)

  1. root@10.30.5.2:orzdba_home# ./orzdba -mysql -innodb -rt

  2. .=================================================.

  3. |       Welcome to use the orzdba tool !          |

  4. |          Yep...Chinese English~                 |

  5. '=============== Date : 2017-04-18 ==============='

  6. HOST: 10.30.22.2   IP: 10.30.5.2

  7. DB  : performance_schema|tab

  8. Var : binlog_format[MIXED] max_binlog_cache_size[17179869184G] max_binlog_size[1G]

  9. max_connect_errors[999999999] max_connections[800] max_user_connections[0]

  10. open_files_limit[102400] sync_binlog[0] table_definition_cache[768]

  11. table_open_cache[512] thread_cache_size[512]

  12. innodb_adaptive_flushing[ON] innodb_adaptive_hash_index[ON] innodb_buffer_pool_size[893M]

  13. innodb_file_per_table[ON] innodb_flush_log_at_trx_commit[2] innodb_flush_method[O_DIRECT]

  14. innodb_io_capacity[20000] innodb_lock_wait_timeout[7200] innodb_log_buffer_size[64M]

  15. innodb_log_file_size[500M] innodb_log_files_in_group[2] innodb_max_dirty_pages_pct[75]

  16. innodb_open_files[1024] innodb_read_io_threads[4] innodb_thread_concurrency[0]

  17. innodb_write_io_threads[4]

  18. --------                     -QPS- -TPS-         -Hit%- ---innodb bp pages status-- -----innodb data status---- --innodb log--   his --log(byte)--  read ---query--- ------threads------ -----bytes---- --------tcprstat(us)--------

  19. time  |  ins   upd   del    sel   iud|     lor    hit|   data   free  dirty flush| reads writes  read written|fsyncs written| list uflush  uckpt  view inside  que| run  con  cre  cac|   recv   send|  count    avg 95-avg 99-avg|

  20. 17:24:53|    0     0     0      0     0|       0 100.00|      0      0      0     0|     0      0      0      0|     0       0|    0      0      0     0     0     0|   0    0    0    0|      0      0|      0      0      0      0|

  21. 17:24:54| 2153  6454  2153  30115 10760|  478891  97.72|  55869      0  19432  2372| 11355   6686 177.4m  79.2m|     2    5.1m|  137   1.7m  180.6m   57     0     0|  20   68    0    1|   1.1m  10.7m|  23711    267    183    236|

  22. 17:24:55| 1960  5891  1962  27470  9813|  437599  97.71|  55872      0  19793  2132| 10416   6063 162.8m  71.4m|     1    4.8m|  142   2.4m  183.5m   62     0     0|  14   68    0    1|  1005k   9.7m|  23004    356    215    283|

  23. 17:24:56| 2027  6091  2033  28422 10151|  451846  97.74|  55870      0  20024  2249| 10609   6320 165.8m  75.2m|     3    4.9m|  133   927k  186.5m   59     0     0|   8   68    0    1|   1.0m  10.2m|  22684    299    186    244|

  24. 17:24:57| 2291  6865  2286  32067 11442|  511514  97.69|  55870      0  20248  2611| 12314   7194 192.4m  87.0m|     2    5.4m|  128    19k  189.6m   54     0     0|   4   68    0    1|   1.1m  11.5m|  25197    267    188    234|

  25. 17:24:58| 2210  6632  2207  30947 11049|  493747  97.77|  55865      0  20361  2371| 11478   6810 179.3m  79.5m|     2    5.4m|  130   267k  192.9m   64     0     0|  48   68    0    1|   1.1m  11.3m|  24586    270    182    232|

  26. 17:24:59| 2225  6680  2226  31102 11131|  496716  97.70|  55866      0  20305  2602| 11891   7059 185.8m  86.6m|     1    5.3m|  149   473k  196.0m   53     0     0|  11   68    0    1|   1.1m  11.3m|  20655    371    219    304|

  27. 17:25:00| 2126  6377  2130  29819 10633|  472984  97.70|  55868      0  20195  2489| 11332   6749 177.1m  82.8m|     2    5.0m|  125   370k  199.0m   62     0     0|  13   68    0    1|   1.1m  10.8m|   8707    958    664    856|

  28. 17:25:01| 2169  6507  2165  30307 10841|  484346  97.71|  55766     99  20214  2485| 11550   6849 180.5m  82.7m|     1    5.1m|  133   808k  202.0m   57     0     0|  15   68    0    1|   1.1m  11.2m|   8578    996    636    844|

    可以發(fā)現(xiàn) 在 32個(gè) thread并發(fā)進(jìn)行complex操作的時(shí)候,每秒的insert量 update量 delete量 select量可以看得非常清楚,還有innodb_log 的fsync量,以及數(shù)據(jù)庫(kù)的response time。

感謝各位的閱讀!關(guān)于“MySQL如何使用sysbench做OLTP基準(zhǔn)測(cè)試”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!

網(wǎng)站標(biāo)題:MySQL如何使用sysbench做OLTP基準(zhǔn)測(cè)試
本文URL:http://muchs.cn/article2/jcjeic.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)、網(wǎng)站內(nèi)鏈網(wǎng)站收錄、軟件開(kāi)發(fā)、網(wǎng)站制作網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名