TiDB 學習第 7 天:TiDB 性能測試

一、工具介紹

TiDB性能測試使用sysbench工具來進行壓測,sysbench是數據庫功能及性能測試工具,它的測試功能如下:

  • CPU 運算性能測試
  • 磁盤 IO 性能測試
  • 調度程序性能測試
  • 內存分配及傳輸速度測試
  • POSIX 線程性能測試
  • 數據庫性能測試(OLTP 基準測試,需要通過 /usr/share/sysbench/ 目錄中的 Lua 腳本執行,例如 oltp_read_only.lua 腳本執行只讀測試)

二、sysbench工具安裝及使用

1、 Centos的安裝

 sudo yum install -y sysbench

2、查看幫助信息

   # 查看幫助信息
 [tidb@cdh01 ~]$ sudo sysbench --help
 # 查看測試幫助信息
 sudo sysbench fileio help / sudo sysbench cpu help

#### 3、CPU測試信息

# 查看CPU幫助信息 sudo sysbench cpu help
[tidb@cdh01 ~]$ sudo sysbench cpu help   
sysbench 1.0.17 (using system LuaJIT 2.0.4)
cpu options:
  --cpu-max-prime=N upper limit for primes generator [10000]

4、CPU測試

sudo sysbench --cpu-max-prime=10000 --threads=2 cpu run

5、磁盤IO性能測試

# 磁盤準備階段
sysbench --test=fileio --num-threads=16 --file-total-size=30G --file-test-mode=rndrw prepare

# 磁盤IO運行檢測
sysbench --test=fileio --num-threads=16 --file-total-size=30G --file-test-mode=rndrw run

Extra file open flags: (none)
128 files, 240MiB each
30GiB total file size
Block size 16KiB
Number of IO requests: 0
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
Initializing worker threads...

Threads started!


File operations:
    reads/s:                      757.99
    writes/s:                     504.77
    fsyncs/s:                     1811.27

Throughput:
    read, MiB/s:                  11.84    
    written, MiB/s:               7.89

General statistics:
    total time:                          10.1038s
    total number of events:              29017

Latency (ms):
         min:                                    0.00
         avg:                                    5.53
         max:                                  374.29
         95th percentile:                       33.12
         sum:                               160351.92

Threads fairness:    
    events (avg/stddev):           1813.5625/196.79       
    execution time (avg/stddev):   10.0220/0.03

6、線程測試

sysbench --test=threads --num-threads=64 --thread-yields=100 --thread-locks=2 run   
測試寫入64線程請求,每個請求產生100個數據量,最後測試執行時間

WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
WARNING: --num-threads is deprecated, use --threads instead
sysbench 1.0.17 (using system LuaJIT 2.0.4)

Running the test with following options:
Number of threads: 64
Initializing random number generator from current time


Initializing worker threads...

Threads started!


General statistics:
    total time:                          10.0057s
    total number of events:              134204

Latency (ms):
         min:                                    0.03
         avg:                                    4.77
         max:                                   74.11
         95th percentile:                       16.71
         sum:                               639949.82

Threads fairness:
    events (avg/stddev):           2096.9375/94.14
    execution time (avg/stddev):   9.9992/0.00                   # 測試最後執行時間爲9.9秒

7、內存測試

sysbench --test=memory --memory-block-size=8k --memory-total-size=40G run

WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
sysbench 1.0.17 (using system LuaJIT 2.0.4)

Running the test with following options:
Number of threads: 1
Initializing random number generator from current time

Running memory speed test with the following options:
  block size: 8KiB
  total size: 40960MiB
  operation: write
  scope: global
Initializing worker threads...
Threads started!
Total operations: 5242880 (1073492.41 per second)
40960.00 MiB transferred (8386.66 MiB/sec)
General statistics:
    total time:                          4.8814s
    total number of events:              5242880

Latency (ms):
         min:                                    0.00
         avg:                                    0.00
         max:                                    1.30
         95th percentile:                        0.00
         sum:                                 3911.72

Threads fairness:
    events (avg/stddev):           5242880.0000/0.00
    execution time (avg/stddev):   3.9117/0.00         # 測試內存總大小40G   內存緩衝區大小爲8k

8、TiDB OLTP基準測試

基準測試分爲3個步驟進行:基準測試腳本如下:
在這裏插入圖片描述

1)首先需要先生成測試表
運行命令查看mysql數據庫測試參數標準:sudo sysbeach --help
  --mysql-host=[LIST,...]          MySQL server host [localhost]    mysql主機ip
  --mysql-port=[LIST,...]          MySQL server port [3306]         端口/mysql默認端口3306   tidb端口 4000
  --mysql-socket=[LIST,...]        MySQL socket                     mysql安裝路徑
  --mysql-user=STRING              MySQL user [sbtest]               數據庫用戶名
  --mysql-password=STRING          MySQL password []                  密碼
  --mysql-db=STRING                MySQL database name [sbtest]       需要進行壓測的數據庫名稱
  --mysql-ssl[=on|off]             use SSL connections, if available in the client library [off]
  --mysql-ssl-cipher=STRING        use specific cipher for SSL connections []
  --mysql-compression[=on|off]     use compression, if available in the client library [off]
  --mysql-debug[=on|off]           trace all client library calls [off]
  --mysql-ignore-errors=[LIST,...] list of errors to ignore, or "all" [1213,1020,1205]
  --mysql-dry-run[=on|off]         Dry run, pretend that all MySQL client API calls are successful without executing them [off]
#  運行語句生成測試表  
sudo sysbench --db-driver=mysql --mysql-host=ip --mysql-port=4000 \
				   --mysql-user=root --mysql-password= --mysql-db=BIGDATA \
				   --range_size=100 --table_size=10000 --threads=2 --events=0 --time=60 \
				   --rand-type=uniform /usr/share/sysbench/oltp_read_only.lua prepare

在這裏插入圖片描述

2)運行語句進行測試(表的讀性能統計基於表的數據是10000)
運行測試.lua測試語句並指定線程數
 sudo sysbench --db-driver=mysql --mysql-host=ip --mysql-port=4000 \
				   --mysql-user=root --mysql-password= --mysql-db=BIGDATA \
				   --range_size=100 --table_size=10000 --threads=2 --events=0 --time=60 \
				   --rand-type=uniform /usr/share/sysbench/oltp_read_only.lua run

程序運行結果如下:

Threads started!
SQL statistics:
    queries performed:                    #性能統計
        read:                            63854   # 讀統計 (select語句)
        write:                           0       # 寫統計 (insert、delete、update語句)
        other:                           9122    # 其他語句 (如commit等)
        total:                           72976   # 總執行語句之和
    transactions:                        4561   (76.00 per sec.)   #總事務數(每秒處理的事務)
    queries:                             72976  (1216.08 per sec.)  #查詢性能(每秒的查詢性能)
    ignored errors:                      0      (0.00 per sec.)
    reconnects:                          0      (0.00 per sec.)

General statistics:
    total time:                          60.0072s    # 總時長
    total number of events:              4561        # 事務總數
 
Latency (ms):                                   #延遲時間
         min:                                   19.30   # 最小延遲時間
         avg:                                   26.30   # 平均延遲
         max:                                 1238.63   # 最大延遲
         95th percentile:                       33.12   # 95%以上語句響應時間
         sum:                               119963.62   # 總延遲時長

Threads fairness:                      # 線程公平性
    events (avg/stddev):           2280.5000/0.50
    execution time (avg/stddev):   59.9818/0.00

3、清除測試表

# 清除測試表
 sudo sysbench --db-driver=mysql --mysql-host=ip --mysql-port=4000 \
				   --mysql-user=root --mysql-password= --mysql-db=BIGDATA \
				   --range_size=100 --table_size=10000 --threads=2 --events=0 --time=60 \
				   --rand-type=uniform /usr/share/sysbench/oltp_read_only.lua clearnup

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章