sysbench 項目測試過程與分析

1、sysbench項目測試過程mysql

1.1 sysbench基準壓測 my.cnflinux

      自動生成MySQL的配置文件:http://imysql.cn/my_cnf_generatorios

[client]
port	= 3306
socket	= /data/mysql/mysql.sock

[mysql]
prompt="\u@mysqldb \R:\m:\s [\d]> "
no-auto-rehash

[mysqld]
user	= mysql
port	= 3306
basedir	= /usr/local/mysql
datadir	= /data/mysql/
socket	= /data/mysql/mysql.sock
pid-file = mysqldb.pid
character-set-server = utf8mb4
skip_name_resolve = 1
open_files_limit = 65536
back_log = 1024
max_connections = 512
max_connect_errors = 1000000
table_open_cache = 1024
table_definition_cache = 1400
table_open_cache_instances = 64
thread_stack = 512K
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 4M
join_buffer_size = 4M
thread_cache_size = 768
interactive_timeout = 600
wait_timeout = 600
tmp_table_size = 32M
max_heap_table_size = 32M
slow_query_log = 1
log_timestamps = SYSTEM
slow_query_log_file = /var/log/slow.log
log-error = /var/log/error.log
long_query_time = 0.1
log_queries_not_using_indexes =1
log_throttle_queries_not_using_indexes = 60
min_examined_row_limit = 100
log_slow_admin_statements = 1
log_slow_slave_statements = 1
server-id = 3306
log-bin = /var/log/mybinlog
sync_binlog = 1
binlog_cache_size = 4M
max_binlog_cache_size = 2G
max_binlog_size = 1G
expire_logs_days = 7
master_info_repository = TABLE
relay_log_info_repository = TABLE
gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates
slave-rows-search-algorithms = 'INDEX_SCAN,HASH_SCAN'
binlog_format = row
binlog_checksum = 1
relay_log_recovery = 1
relay-log-purge = 1
key_buffer_size = 32M
read_buffer_size = 8M
read_rnd_buffer_size = 4M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
lock_wait_timeout = 3600
explicit_defaults_for_timestamp = 1
innodb_thread_concurrency = 64
innodb_sync_spin_loops = 100
innodb_spin_wait_delay = 30

transaction_isolation = REPEATABLE-READ
#innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 500M
innodb_buffer_pool_instances = 8
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_data_file_path = ibdata1:1G:autoextend
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 32M
innodb_log_file_size = 2G
innodb_log_files_in_group = 2
innodb_max_undo_log_size = 2G
innodb_undo_directory = undolog
innodb_undo_tablespaces = 3
innodb_undo_log_truncate = 1

# 根據您的服務器IOPS能力適當調整
# 通常配普通SSD盤的話,能夠調整到 10000 - 20000
# 配置高端PCIe SSD卡的話,則能夠調整的更高,好比 50000 - 80000
innodb_io_capacity = 4000
innodb_io_capacity_max = 8000
innodb_flush_sync = 0
innodb_flush_neighbors = 1
innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_purge_threads = 4
innodb_page_cleaners = 4
innodb_open_files = 65535
innodb_max_dirty_pages_pct = 50
innodb_flush_method = O_DIRECT
innodb_lru_scan_depth = 2000
innodb_checksum_algorithm = 0
innodb_lock_wait_timeout = 5
innodb_rollback_on_timeout = 1
innodb_print_all_deadlocks = 1
innodb_file_per_table = 1
innodb_online_alter_log_max_size = 4G
internal_tmp_disk_storage_engine = InnoDB
innodb_stats_on_metadata = 0
innodb_sort_buffer_size = 64M
innodb_autoextend_increment = 64
innodb_concurrency_tickets = 5000
innodb_old_blocks_time = 1000
innodb_open_files = 65536
innodb_purge_rseg_truncate_frequery = 128
binlog_gtid_simple_recovery = 1

# some var for MySQL 8
log_error_verbosity = 3
innodb_print_ddl_logs = 1
binlog_expire_logs_seconds = 604800
#innodb_dedicated_server = 0

innodb_status_file = 1
# 注意: 開啓 innodb_status_output & innodb_status_output_locks 後, 可能會致使log-error文件增加較快
innodb_status_output = 0
innodb_status_output_locks = 0

#performance_schema
performance_schema = 1
performance_schema_instrument = '%=on'

#innodb monitor
innodb_monitor_enable="module_innodb"
innodb_monitor_enable="module_server"
innodb_monitor_enable="module_dml"
innodb_monitor_enable="module_ddl"
innodb_monitor_enable="module_trx"
innodb_monitor_enable="module_os"
innodb_monitor_enable="module_purge"
innodb_monitor_enable="module_log"
innodb_monitor_enable="module_lock"
innodb_monitor_enable="module_buffer"
innodb_monitor_enable="module_index"
innodb_monitor_enable="module_ibuf_system"
innodb_monitor_enable="module_buffer_page"
innodb_monitor_enable="module_adaptive_hash"

[mysqldump]
quick
max_allowed_packet = 32M

1.2 sysbench 測試準備sql

  1. 測試環境數據庫

  主機、CPU、內存、RAID、硬盤、文件系統、內存、MySQL、sysbenchvim

2. 壓測基準值bash

  多少張表,每張表多少數據量,測試腳本,測試多少時間,最大請求數多少,併發線程數,生成多大數量服務器

1.3 進行sysbench OLTP 測試-混合讀寫session

  1. 準備數據多線程

[root@mysql8 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.15 MySQL Community Server - GPL

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database sbtest;
Query OK, 1 row affected (0.42 sec)

mysql> exit
Bye
[root@mysql8 ~]# cd /sysbench/
[root@mysql8 sysbench]# sysbench ./share/sysbench/tests/include/oltp_legacy/oltp.lua \
--mysql-host=172.16.216.195 --mysql-port=3306 --mysql-user=root --mysql-password=#root# \
--oltp-test-mode=complex --oltp-tables-count=10 --oltp-table-size=100000 \
--threads=10 --time=120 --report-interval=10 prepare
# --threads=10:表示發起10個併發鏈接
# --report-interval=10:表示每10秒輸出一次測試進度報告
# --oltp-tables-count=10:表示會生成10個測試表
# --oltp-table-size=100000:表示每一個測試表填充數據量爲100000
sysbench 1.0.16 (using bundled LuaJIT 2.1.0-beta2)

Creating table 'sbtest1'...
Inserting 100000 records into 'sbtest1'
Creating secondary indexes on 'sbtest1'...
Creating table 'sbtest2'...
Inserting 100000 records into 'sbtest2'
Creating secondary indexes on 'sbtest2'...
Creating table 'sbtest3'...
Inserting 100000 records into 'sbtest3'
Creating secondary indexes on 'sbtest3'...
Creating table 'sbtest4'...
Inserting 100000 records into 'sbtest4'
Creating secondary indexes on 'sbtest4'...
Creating table 'sbtest5'...
Inserting 100000 records into 'sbtest5'
Creating secondary indexes on 'sbtest5'...
Creating table 'sbtest6'...
Inserting 100000 records into 'sbtest6'
Creating secondary indexes on 'sbtest6'...
Creating table 'sbtest7'...
Inserting 100000 records into 'sbtest7'
Creating secondary indexes on 'sbtest7'...
Creating table 'sbtest8'...
Inserting 100000 records into 'sbtest8'
Creating secondary indexes on 'sbtest8'...
Creating table 'sbtest9'...
Inserting 100000 records into 'sbtest9'
Creating secondary indexes on 'sbtest9'...
Creating table 'sbtest10'...
Inserting 100000 records into 'sbtest10'
Creating secondary indexes on 'sbtest10'...

2. 執行測試

[root@mysql8 ~]# mkdir /sysbench/report/ -p
[root@mysql8 sysbench]# sysbench ./share/sysbench/tests/include/oltp_legacy/oltp.lua \
--mysql-host=172.16.216.195 --mysql-port=3306 --mysql-user=root --mysql-password=#root# \
--oltp-test-mode=complex --oltp-tables-count=10 --oltp-table-size=100000 \
--threads=10 --time=120 --report-interval=10 run >> /sysbench/report/mysysbench-20190225.log

3. 清理數據

[root@mysql8 sysbench]# sysbench ./share/sysbench/tests/include/oltp_legacy/oltp.lua \
--mysql-host=172.16.216.195 --mysql-port=3306 --mysql-user=root --mysql-password=#root# cleanup
sysbench 1.0.16 (using bundled LuaJIT 2.1.0-beta2)

Dropping table 'sbtest1'...

4. 測試結果

    重點關注:TPS,QPS,95%以上的響應時長統計

[root@mysql8 report]# more mysysbench-20190225.log 
sysbench 1.0.16 (using bundled LuaJIT 2.1.0-beta2)

Running the test with following options:
Number of threads: 10
Report intermediate results every 10 second(s)
Initializing random number generator from current time


Initializing worker threads...

Threads started!
# 每10秒鐘報告一次測試結果,tps,qps,95%以上的響應時長統計
[ 10s ] thds: 10 tps: 235.04 qps: 4719.82 (r/w/o: 3304.58/944.16/471.08) lat (ms,95%): 55.82 err/s: 0.00 reconn/s: 0.00
[ 20s ] thds: 10 tps: 178.21 qps: 3563.14 (r/w/o: 2494.90/711.83/356.41) lat (ms,95%): 62.19 err/s: 0.00 reconn/s: 0.00
[ 30s ] thds: 10 tps: 330.10 qps: 6598.23 (r/w/o: 4619.12/1319.01/660.10) lat (ms,95%): 63.32 err/s: 0.00 reconn/s: 0.00
[ 40s ] thds: 10 tps: 310.48 qps: 6208.25 (r/w/o: 4346.35/1240.83/621.06) lat (ms,95%): 102.97 err/s: 0.00 reconn/s: 0.00
[ 50s ] thds: 10 tps: 113.91 qps: 2278.52 (r/w/o: 1594.59/456.12/227.81) lat (ms,95%): 253.35 err/s: 0.00 reconn/s: 0.00
[ 60s ] thds: 10 tps: 293.66 qps: 5880.66 (r/w/o: 4115.41/1177.83/587.42) lat (ms,95%): 59.99 err/s: 0.10 reconn/s: 0.00
[ 70s ] thds: 10 tps: 289.04 qps: 5773.85 (r/w/o: 4042.82/1152.95/578.07) lat (ms,95%): 68.05 err/s: 0.00 reconn/s: 0.00
[ 80s ] thds: 10 tps: 187.30 qps: 3746.45 (r/w/o: 2622.66/749.19/374.59) lat (ms,95%): 43.39 err/s: 0.00 reconn/s: 0.00
[ 90s ] thds: 10 tps: 234.98 qps: 4705.58 (r/w/o: 3292.91/942.72/469.96) lat (ms,95%): 130.13 err/s: 0.00 reconn/s: 0.00
[ 100s ] thds: 10 tps: 306.92 qps: 6138.76 (r/w/o: 4296.85/1228.07/613.84) lat (ms,95%): 64.47 err/s: 0.00 reconn/s: 0.00
[ 110s ] thds: 10 tps: 187.60 qps: 3749.19 (r/w/o: 2625.20/748.60/375.40) lat (ms,95%): 46.63 err/s: 0.20 reconn/s: 0.00
[ 120s ] thds: 10 tps: 290.62 qps: 5815.27 (r/w/o: 4071.46/1162.57/581.24) lat (ms,95%): 97.55 err/s: 0.00 reconn/s: 0.00
SQL statistics:
    queries performed:
        read:                            414288       # 讀總數
        write:                           118360       # 寫總數
        other:                           59181        # 其它操做,如commit
        total:                           591829       # 所有總數
    transactions:                        29589  (246.53 per sec.)     # 總事務數(TPS,每秒事務數)
    queries:                             591829 (4931.09 per sec.)    # 讀寫數(QPS,每秒讀寫次數)
    ignored errors:                      3      (0.02 per sec.)       # 忽略的錯誤數
    reconnects:                          0      (0.00 per sec.)

General statistics:            # 一些統計結果
    total time:                          120.0183s      # 總耗時
    total number of events:              29589          # 共發生了多少事務數

Latency (ms):                 # 響應時長統計
         min:                                    3.97   # 最小耗時
         avg:                                   40.56   # 平均耗時
         max:                                 5478.23   # 最長耗時
         95th percentile:                       70.55   # 95%請求的最大響應時間
         sum:                              1199998.40   # 總耗時

Threads fairness:            # 與線程相關的指標
    events (avg/stddev):           2958.9000/47.60      # 事件(平均值/誤差)
    execution time (avg/stddev):   119.9998/0.00        # 執行時間(平均值/誤差)

1.4 生成圖片報告

gnuplot下載地址:https://sourceforge.net/projects/gnuplot/files/latest/download

經過Excel進行數據分析:https://www.ibm.com/developerworks/community/wikis/home?lang=en#!/wiki/Power%20Systems/page/nmon_analyser

1.4.1 安裝及使用 gnuplot

[root@mysql8 software]# yum install  gnuplot
[root@mysql8 ~]# gnuplot 
G N U P L O T
	Version 4.6 patchlevel 2    last modified 2013-03-14 
	Build System: Linux x86_64

	Copyright (C) 1986-1993, 1998, 2004, 2007-2013
	Thomas Williams, Colin Kelley and many others

	gnuplot home:     http://www.gnuplot.info
	faq, bugs, etc:   type "help FAQ"
	immediate help:   type "help"  (plot window: hit 'h')

Terminal type set to 'x11'

gnuplot> plot '/root/mysysbench-20190225.log' using 9 with lines title 'QPS'
# using 9:表示使用第9列數據做圖
# with lines:定義圖中的趨勢使用線來表示
# title ‘QPS’:定義線的名稱
# 使用,(逗號)分割,進行多列數據的繪製

86146

http://sourceforge.net/projects/nmon/files/nmon16g_x86.tar.gz

[root@mysql8 report]# vim sysbench_monitor.sh
#!/bin/bash
#開始前獲取全局配置參數
#每五秒獲取一次cpu load,MySQL全局信息,InnoDB引擎相關信息,線程信息 
INTERVAL=5
PREFIX=$INTERVAL-sec-status
RUNFILE=/sysbench/report
mysql -uroot -p123456 -e 'show global variables'>>mysql-variables
while  test -e $RUNFILE; do
        file=$(date +%F_%H)
        sleep=$(date +%s.%N |awk "{print $INTERVAL -(\$1 % $INTERVAL)}")
        sleep $sleep
        ts="$(date +"TS %s.%N %F %T")"
        loadavg="$(uptime)"                                 #經過uptime命令獲取cpu load
        echo "$ts $loadavg">> $PREFIX-${file}-status
        mysql -uroot -p123456  -e "show global status" >> $PREFIX-${file}-status 2>/dev/null &   #獲取MySQL全局信息
        echo "$ts $loadavg">> $PREFIX-${file}-innodbstatus
        mysql -uroot -p123456  -e "show engine innodb status\G" >> $PREFIX-${file}-innodbstatus 2>/dev/null &    #獲取引擎信息
        echo "$ts $loadavg">> $PREFIX-${file}-processlist
        mysql -uroot -p123456  -e "show full processlist\G" >>$PREFIX-${file}-processlist 2>/dev/null &  #獲取線程信息
        echo $ts
done
echo Exiting because $RUNFILE not exist
[root@mysql8 report]# chmod +x sysbench_monitor.sh 
[root@mysql8 report]# nohup /sysbench/report/sysbench_monitor.sh &
[root@mysql8 report]# vim sysbench_anaylyze.sh
#!/bin/bash
awk '
        BEGIN{
                printf "#ts date time load QPS";
                fmt = " %.2f";
                }
                /^TS/ { # The timestamp lines begin with TS.
                        ts = substr($2, 1, index($2,".") - 1);
                        load = NF -  2;
                        diff = ts -prev_ts;
                        prev_ts = ts;
                        printf "\n%s %s %s %s",ts,$3,$4,substr($load, 1, length($load)-1);
                }
                /Queries/ {
                        printf fmt, ($2-Queries)/diff;
                        Queries=$2
                }
                ' "$@"
[root@mysql8 report]# chmod +x sysbench_anaylyze.sh
[root@mysql8 report]# /sysbench/report/sysbench_anaylyze.sh 5-sec-status-2019-03-02_15-status > sysbench_status_out.log1.5 每次壓縮後要作什麼

1.5 每次壓縮後要作什麼

  1. 清數據

  2. 重啓主機

2、sysbench 其它類型測試

2.1 只讀(從庫查詢)

[root@mysql8 sysbench]# sysbench /sysbench/share/sysbench/tests/include/oltp_legacy/oltp.lua --mysql-host=172.16.216.195 --mysql-port=3306 --mysql-user=root --mysql-password=123456 --mysql-db=sbtest --oltp-tables-count=10 --oltp-table-size=100000 --threads=10 --time=20 --report-interval=10 --rand-init=on --max-requests=0 --oltp-test-mode=nontrx --oltp-nontrx-mode=select --oltp-read-only=on --oltp-skip-trx=on prepare
[root@mysql8 sysbench]# sysbench /sysbench/share/sysbench/tests/include/oltp_legacy/oltp.lua --mysql-host=172.16.216.195 --mysql-port=3306 --mysql-user=root --mysql-password=123456 --mysql-db=sbtest --oltp-tables-count=10 --oltp-table-size=100000 --threads=10 --time=20 --report-interval=10 --rand-init=on --max-requests=0 --oltp-test-mode=nontrx --oltp-nontrx-mode=select --oltp-read-only=on --oltp-skip-trx=on run > /sysbench/report/mysysbench-20190302.log
[root@mysql8 sysbench]# sysbench /sysbench/share/sysbench/tests/include/oltp_legacy/oltp.lua --mysql-host=172.16.216.195 --mysql-port=3306 --mysql-user=123456--mysql-password=root --oltp-tables-count=10 cleanup

2.2 只寫-更新測試(主庫寫)

若是基準測試的時候,你只想比較兩個項目的update(或insert)效率,那能夠不使用oltp腳本,而直接改用update_index.lua。

[root@mysql8 sysbench]# sysbench /sysbench/share/sysbench/tests/include/oltp_legacy/update_index.lua --mysql-host=172.16.216.195 --mysql-port=3306 --mysql-user=root --mysql-password=123456 --mysql-db=sbtest --oltp-tables-count=10 --oltp-table-size=10000 --threads=10 --time=20 --report-interval=10 --rand-init=on --oltp-read-only=off prepare
[root@mysql8 sysbench]# sysbench /sysbench/share/sysbench/tests/include/oltp_legacy/update_index.lua --mysql-host=172.16.216.195 --mysql-port=3306 --mysql-user=123456 --mysql-password=root --mysql-db=sbtest --oltp-tables-count=10 --oltp-table-size=100000 --threads=10 --time=20 --report-interval=10 --rand-init=on --oltp-read-only=off run > /sysbench/report/mysysbench-19030205.log
[root@mysql8 sysbench]# sysbench /sysbench/share/sysbench/tests/include/oltp_legacy/update_index.lua --mysql-host=172.16.216.195--mysql-port=3306 --mysql-user=root --oltp-tables-count=10 --mysql-password=123456 cleanup

3、IO性能測試-fileio

[root@mysql8 sysbench]# sysbench fileio help
sysbench 1.0.16 (using bundled LuaJIT 2.1.0-beta2)

fileio options:
  --file-num=N                  number of files to create [128]                       # 建立測試文件的數量。默認是 128
  --file-block-size=N           block size to use in all IO operations [16384]        # 測試時文件塊的大小。默認是 16384(16K)
  --file-total-size=SIZE        total size of files to create [2G]                    # 測試文件的總大小。默認是 2G
  --file-test-mode=STRING       test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw} # 文件測試模式{seqwr(順序寫), seqrewr(順序讀寫),
seqrd(順序讀), rndrd(隨機讀), rndwr(隨機寫), rndrw(隨機讀寫)}
  --file-io-mode=STRING         file operations mode {sync,async,mmap} [sync]         # 文件操做模式{sync(同步),async(異步),fastmmap(快速
map 映射),slowmmap(慢 map 映射)}。默認是 sync
  --file-async-backlog=N        number of asynchronous operatons to queue per thread [128]
  --file-extra-flags=[LIST,...] list of additional flags to use to open files {sync,dsync,direct} []
  --file-fsync-freq=N           do fsync() after this number of requests (0 - don't use fsync()) [100]  # 執行 fsync()的頻率。(0 – 不使用 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]   # 在測試結束時才執行 fsync。默認是 on 
  --file-fsync-mode=STRING      which method to use for synchronization {fsync, fdatasync} [fsync]   # 使用額外的標誌來打開文件{sync,dsync,direct} 。
默認爲空
  --file-merged-requests=N      merge at most this number of IO requests if possible (0 - don't merge) [0]  # 若是能夠,合併最多的 IO 請求數(0 – 表示不合並)。默
認是 0
  --file-rw-ratio=N             reads/writes ratio for combined test [1.5] # 測試時的讀寫比例。默認是 1.5

Sysbench 的文件測試模式:

  • seqwr 順序寫

  • seqrew r 順序讀寫

  • seqrd 順序讀

  • rndrd 隨機讀

  • rndwr 隨機寫

  • rndrw 隨機讀寫

3.1 準備 IO 測試文件:執行以下命令,生成 16 個文件,用於本次測試

[root@mysql8 ~]# mkdir /mysql/data/tmp -p
[root@mysql8 ~]# cd /mysql/data/tmp
[root@mysql8 tmp]# sysbench fileio --file-num=16 --file-total-size=20M prepare
sysbench 1.0.16 (using bundled LuaJIT 2.1.0-beta2)

16 files, 1280Kb each, 20Mb total
Creating files for the test...
Extra file open flags: (none)
Creating file test_file.0
Creating file test_file.1
Creating file test_file.2
Creating file test_file.3
Creating file test_file.4
Creating file test_file.5
Creating file test_file.6
Creating file test_file.7
Creating file test_file.8
Creating file test_file.9
Creating file test_file.10
Creating file test_file.11
Creating file test_file.12
Creating file test_file.13
Creating file test_file.14
Creating file test_file.15
20971520 bytes written in 0.61 seconds (32.86 MiB/sec).
[root@mysql8 tmp]# ls
test_file.0  test_file.10  test_file.12  test_file.14  test_file.2  test_file.4  test_file.6  test_file.8
test_file.1  test_file.11  test_file.13  test_file.15  test_file.3  test_file.5  test_file.7  test_file.9

3.2 測試多線程下小 IO 的隨機只讀性能

[root@mysql8 tmp]# sysbench fileio --file-num=16 --file-total-size=20M --file-test-mode=rndrd --file-extra-flags=direct  --file-fsync-freq=0 --file-block-size=16384 run
# --file-num=16:文件數量是16個
# --file-total-size=20M:文件總大小20M
# --file-test-mode=rndrd:測試模式是隨機讀取
# --file-extra-flags=direct:使用額外的標誌來打開文件{sync,dsync,direct}
# --file-fsync-freq=0:執行fsync()的頻率
# --file-block-size=16384:測試時文件塊的大小位16384(16k)
sysbench 1.0.16 (using bundled LuaJIT 2.1.0-beta2)

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


Extra file open flags: directio
16 files, 1.25MiB each
20MiB total file size
Block size 16KiB
Number of IO requests: 0
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 read test
Initializing worker threads...

Threads started!


File operations:
    reads/s:                      7332.59    # 每秒讀寫次數,也就是IOPS,越大越好
    
    writes/s:                     0.00       # 每秒寫的次數
    fsyncs/s:                     0.00       # 每秒同步的次數

Throughput:   #吞吐量          
    read, MiB/s:                  114.57     # 每秒讀多少兆,越大越好
    written, MiB/s:               0.00       

General statistics:
    total time:                          10.0002s   # 總時間
    total number of events:              73340      # 總事件

Latency (ms):
         min:                                    0.06
         avg:                                    0.14
         max:                                    8.55
         95th percentile:                        0.18        # 95%的響應時間,越小越好
         sum:                                 9939.93

Threads fairness:
    events (avg/stddev):           73340.0000/0.00
    execution time (avg/stddev):   9.9399/0.00

3.3 測試多線程下小IO的隨機寫入性能

[root@mysql8 tmp]# sysbench fileio --file-num=16 --file-total-size=20M --file-test-mode=rndwr --max-time=120 --file-extra-flags=direct --file-fsync-freq=0 --file-block-size=16384 run
WARNING: --max-time is deprecated, use --time instead
sysbench 1.0.16 (using bundled LuaJIT 2.1.0-beta2)

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


Extra file open flags: directio
16 files, 1.25MiB each
20MiB total file size
Block size 16KiB
Number of IO requests: 0
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 write test
Initializing worker threads...

Threads started!


File operations:
    reads/s:                      0.00
    writes/s:                     6236.45
    fsyncs/s:                     0.13

Throughput:
    read, MiB/s:                  0.00
    written, MiB/s:               97.44

General statistics:
    total time:                          120.0013s
    total number of events:              748392

Latency (ms):
         min:                                    0.06
         avg:                                    0.16
         max:                                 1417.16
         95th percentile:                        0.20
         sum:                               119277.92

Threads fairness:
    events (avg/stddev):           748392.0000/0.00
    execution time (avg/stddev):   119.2779/0.00
[root@mysql8 ~]# iostat 5
Linux 3.10.0-957.5.1.el7.x86_64 (mysql8.linuxplus.com)  03/02/2019      _x86_64_        (2 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           3.30    0.03    2.42    2.42    0.00   91.82

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda             109.04       259.23      1440.35    3636386   20204721
scd0              0.00         0.07         0.00       1028          0
dm-0            109.23       258.41      1438.81    3624842   20183129
dm-1              0.37         0.22         1.39       3016      19560

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           1.83    0.00   13.36   37.39    0.00   47.41

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda            4130.40         0.00     66077.60          0     330388
scd0              0.00         0.00         0.00          0          0
dm-0           4130.20         0.00     66074.40          0     330372
dm-1              0.00         0.00         0.00          0          0

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           2.16    0.00   20.48   30.49    0.00   46.87

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda            6307.80         0.00    100981.60          0     504908
scd0              0.00         0.00         0.00          0          0
dm-0           6308.20         0.00    100988.00          0     504940
dm-1              0.00         0.00         0.00          0          0

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           2.36    0.00   20.11   29.10    0.00   48.43

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda            6778.60         0.00    108450.40          0     542252
scd0              0.00         0.00         0.00          0          0
dm-0           6778.40         0.00    108447.20          0     542236
dm-1              0.00         0.00         0.00          0          0

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           2.16    0.00   18.97   27.16    0.00   51.72

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda            6572.20         0.00    105148.00          0     525740
scd0              0.00         0.00         0.00          0          0
dm-0           6572.00         0.00    105144.80          0     525724
dm-1              0.00         0.00         0.00          0          0

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           1.49    0.00   10.73   14.45    0.00   73.33

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda            3265.20         0.00     52256.80          0     261284
scd0              0.00         0.00         0.00          0          0
dm-0           3265.20         0.00     52256.80          0     261284
dm-1              0.00         0.00         0.00          0          0

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           1.11    0.00    1.31    4.92    0.00   92.66

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda               2.99         3.19        38.22         16        191
scd0              0.00         0.00         0.00          0          0
dm-0              3.59         3.19        39.02         16        195
dm-1              0.00         0.00         0.00          0          0

3.4 測試多線程下小IO的隨機讀寫性能

[root@mysql8 tmp]# sysbench fileio --file-num=16 --file-total-size=20M --file-test-mode=rndrw --file-extra-flags=direct --file-fsync-freq=0 --max-time=60 --file-block-size=16384 run  
WARNING: --max-time is deprecated, use --time instead
sysbench 1.0.16 (using bundled LuaJIT 2.1.0-beta2)

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


Extra file open flags: directio
16 files, 1.25MiB each
20MiB total file size
Block size 16KiB
Number of IO requests: 0
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
Initializing worker threads...

Threads started!


File operations:
    reads/s:                      4239.61
    writes/s:                     2826.41
    fsyncs/s:                     0.27

Throughput:
    read, MiB/s:                  66.24
    written, MiB/s:               44.16

General statistics:
    total time:                          60.0002s
    total number of events:              423975

Latency (ms):
         min:                                    0.06
         avg:                                    0.14
         max:                                  558.82
         95th percentile:                        0.18
         sum:                                59647.57

Threads fairness:
    events (avg/stddev):           423975.0000/0.00
    execution time (avg/stddev):   59.6476/0.00
[root@mysql8 ~]# iostat 10
Linux 3.10.0-957.5.1.el7.x86_64 (mysql8.linuxplus.com)  03/02/2019      _x86_64_        (2 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           3.25    0.03    2.47    2.50    0.00   91.75

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda             140.33       491.59      1709.91    7095746   24681318
scd0              0.00         0.07         0.00       1028          0
dm-0            140.51       490.79      1708.41    7084202   24659710
dm-1              0.36         0.21         1.36       3016      19560

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           1.60    0.00   12.18   15.37    0.00   70.85

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda            4111.30     39457.60     26351.60     394576     263516
scd0              0.00         0.00         0.00          0          0
dm-0           4111.30     39457.60     26351.60     394576     263516
dm-1              0.00         0.00         0.00          0          0

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           1.82    0.00   18.68   30.46    0.00   49.03

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda            6489.40     62289.60     41530.40     622896     415304
scd0              0.00         0.00         0.00          0          0
dm-0           6489.50     62289.60     41532.00     622896     415320
dm-1              0.00         0.00         0.00          0          0

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           1.95    0.00   21.36   28.00    0.00   48.69

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda            7318.10     70248.00     46834.40     702480     468344
scd0              0.00         0.00         0.00          0          0
dm-0           7318.00     70248.00     46832.80     702480     468328
dm-1              0.00         0.00         0.00          0          0

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           2.07    0.00   21.02   28.28    0.00   48.63

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda            7119.20     68332.80     45603.20     683328     456032
scd0              0.00         0.00         0.00          0          0
dm-0           7119.20     68332.80     45603.20     683328     456032
dm-1              0.00         0.00         0.00          0          0

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           2.05    0.00   18.25   27.48    0.00   52.21

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda            6722.40     64524.80     43022.00     645248     430220
scd0              0.00         0.00         0.00          0          0
dm-0           6722.50     64524.80     43022.00     645248     430220
dm-1              0.00         0.00         0.00          0          0

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           2.17    0.00   20.75   24.93    0.00   52.15

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda            7425.50     71278.40     47521.20     712784     475212
scd0              0.00         0.00         0.00          0          0
dm-0           7425.50     71278.40     47521.20     712784     475212
dm-1              0.00         0.00         0.00          0          0

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           1.40    0.00    9.11   10.04    0.00   79.45

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda            3218.20     30884.80     20594.65     308848     205946
scd0              0.00         0.00         0.00          0          0
dm-0           3218.20     30884.80     20594.65     308848     205946
dm-1              0.00         0.00         0.00          0          0

3.5 清理測試時生成的文件

[root@mysql8 tmp]# sysbench fileio --threads=20 --file-total-size=20M --file-test-mode=rndrw cleanup
sysbench 1.0.16 (using bundled LuaJIT 2.1.0-beta2)

Removing test files...

4、CPU 性能測試

[root@mysql8 tmp]# sysbench cpu --cpu-max-prime=2000 run
# --cpu-max-prime=N 最大質數發生器數量。默認是 10000
sysbench 1.0.16 (using bundled LuaJIT 2.1.0-beta2)

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


Prime numbers limit: 2000

Initializing worker threads...

Threads started!

CPU speed:
    events per second:  9643.27

General statistics:
    total time:                          10.0002s
    total number of events:              96451

Latency (ms):
         min:                                    0.09
         avg:                                    0.10
         max:                                   28.52
         95th percentile:                        0.12
         sum:                                 9970.21

Threads fairness:
    events (avg/stddev):           96451.0000/0.00
    execution time (avg/stddev):   9.9702/0.00

5、內存性能測試

[root@mysql8 tmp]# sysbench memory help
sysbench 1.0.16 (using bundled LuaJIT 2.1.0-beta2)

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] # 內存訪問範圍{global,local}。默認是 global
  --memory-hugetlb[=on|off]   allocate memory from HugeTLB pool [off]     # 從 HugeTLB 池內存分配。默認是 off
  --memory-oper=STRING        type of memory operations {read, write, none} [write] # 內存操做類型。{read, write, none} 默認是 write
  --memory-access-mode=STRING memory access mode {seq,rnd} [seq] # 存儲器存取方式{seq,rnd} 默認是 seq
  [root@mysql8 tmp]# sysbench memory --memory-block-size=8k --memory-total-size=1G run
sysbench 1.0.16 (using bundled LuaJIT 2.1.0-beta2)

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: 1024MiB
  operation: write
  scope: global

Initializing worker threads...

Threads started!

Total operations: 131072 (1153336.20 per second)

1024.00 MiB transferred (9010.44 MiB/sec)


General statistics:
    total time:                          0.1119s
    total number of events:              131072

Latency (ms):
         min:                                    0.00
         avg:                                    0.00
         max:                                    3.77
         95th percentile:                        0.00
         sum:                                   92.14

Threads fairness:
    events (avg/stddev):           131072.0000/0.00
    execution time (avg/stddev):   0.0921/0.00

6、線程性能測試

[root@mysql8 ~]# sysbench threads help
sysbench 1.0.16 (using bundled LuaJIT 2.1.0-beta2)

threads options:
  --thread-yields=N number of yields to do per request [1000]    # 每一個請求產生多少個線程。默認是 1000
  --thread-locks=N  number of locks per thread [8]  # 每一個線程的鎖的數量。默認是 8
 [root@mysql8 ~]# sysbench threads --num-threads=100 --thread-yields=100 --thread-locks=4 run
WARNING: --num-threads is deprecated, use --threads instead
sysbench 1.0.16 (using bundled LuaJIT 2.1.0-beta2)

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


Initializing worker threads...

Threads started!


General statistics:
    total time:                          10.0367s
    total number of events:              15943

Latency (ms):
         min:                                    0.20
         avg:                                   62.86
         max:                                 7007.05
         95th percentile:                      118.92
         sum:                              1002219.97

Threads fairness:
    events (avg/stddev):           159.4300/157.31
    execution time (avg/stddev):   10.0222/0.01

You have mail in /var/spool/mail/root

7、OLTP性能測試

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                   # 查詢範圍。默認是 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
相關文章
相關標籤/搜索