sysbench使用

部署
1.1  官方主頁
1.2  安裝
Percona安裝源(yum源)
Wget
https://www.percona.com/redir/downloads/percona-release/redhat/0.1-6/percona-release-0.1-6.noarch.rpm
    yum -y install percona-release-0.1-6.noarch.rpm
yum -y install sysbench
yum install -y sysbench-tpcc
 
Percona安裝源(yum源)
[root@zhumh ~]# wget https://www.percona.com/redir/downloads/percona-release/redhat/0.1-6/percona-release-0.1-6.noarch.rpm
[root@zhumh ~]# yum -y install percona-release-0.1-6.noarch.rpm
[root@zhumh ~]# yum -y install sysbench
[root@zhumh ~]# yum install -y sysbench-tpcc
 
 
 
幫助文檔
[root@zhumh ~]# sysbench --help
Usage:
  sysbench [options]... [testname] [command]
 
Commands implemented by most tests: prepare run cleanup help
 
General options:
  --threads=N                     number of threads to use [1]
                                     使用的線程數爲1
  --events=N                      limit for total number of events [0]
                                     事件總數的限制
  --time=N                        limit for total execution time in seconds [10]
                                     在10秒內的總執行時間限制
  --forced-shutdown=STRING        number of seconds to wait after the --time limit before forcing shutdown, or 'off' to disable [off]
在強制關閉前的時間限制,或「關閉」以禁用的秒數。
  --thread-stack-size=SIZE        size of stack per thread [64K]
                                    每一個線程的堆棧大小64K
  --rate=N                        average transactions rate. 0 for unlimited rate [0]
                                    平均事務率。0的無限速率
  --report-interval=N             periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0]
按期報告中間統計數據,並在幾秒鐘內指定時間間隔。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. []
轉儲完整的統計信息,並在指定的時間點重置全部計數器。這個參數是一個逗號分隔值的列表,它表示在必須執行報告檢查點(s)時從測試開始時所花費的時間。報告檢查點在默認狀況下是關閉的。
  --debug[=on|off]                print more debugging info [off]
                                    打印更多的調試信息
  --validate[=on|off]             perform validation checks where possible [off]
                                    在可能的狀況下執行驗證檢查
  --help[=on|off]                 print help and exit [off]
  --version[=on|off]              print version and exit [off]
                                    打印版本和退出
  --config-file=FILENAME          File containing command line options
                                    打印版本和退出包含命令行選項的文件
  --tx-rate=N                     deprecated alias for --rate [0]
                                    棄用別名
  --max-requests=N                deprecated alias for --events [0]      廢棄的別名——事件
 
  --max-time=N                    deprecated alias for --time [0]     廢棄的別名——時間
  --num-threads=N                 deprecated alias for --threads [1]   已廢棄的別名——線程
 
Pseudo-Random Numbers Generator options:
  --rand-type=STRING random numbers distribution {uniform,gaussian,special,pareto} [special]
rand類型=字符串隨機數字分佈 uniform,gaussian,special,pareto} [special]
  --rand-spec-iter=N number of iterations used for numbers generation [12]
     rand speciter=N的迭代次數,用於數字生成12
  --rand-spec-pct=N  percentage of values to be treated as 'special' (for special distribution) [1]
     rand spec-pct=N的值被視爲「特殊的」(特殊分配)
  --rand-spec-res=N  percentage of 'special' values to use (for special distribution) [75]
     rand spec-res=N的"特殊"值的百分比(用於特殊分配)
  --rand-seed=N      seed for random number generator. When 0, the current time is used as a RNG seed. [0]
     rand-seed=N 隨機數字生成器的種子。當0時,當前時間被用做RNG種子
  --rand-pareto-h=N  parameter h for pareto distibution [0.2]   rand-pareto-h=N pareto的參數
Log options:
  --verbosity=N verbosity level {5 - debug, 0 - only critical messages} [3]    冗長的5級——調試,0——只有關鍵信息3
 
  --percentile=N       percentile to calculate in latency statistics (1-100). Use the special value of 0 to disable percentile calculations [95]     在延遲統計(1-100)中計算百分比。使用0的特殊值來禁用百分位數計算
  --histogram[=on|off] print latency histogram in report [off]      在報告關閉的打印延遲直方圖上
 
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]
                          準備語句使用模式自動,禁用自動
  --db-debug[=on|off] print database-specific debug information [off]
                           打印特定於數據庫的調試信息
Compiled-in database drivers:
  mysql - MySQL driver
 
mysql options:
  --mysql-host=[LIST,...]          MySQL server host [localhost]
  --mysql-port=[LIST,...]          MySQL server port [3306]
  --mysql-socket=[LIST,...]        MySQL socket
  --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]
                                    若是在客戶端庫中可用,則使用SSL鏈接
  --mysql-ssl-cipher=STRING     use specific cipher for SSL connections []   爲SSL鏈接使用特定的密碼
  --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]     忽略的錯誤列表,或「所有」1213,1020,1205
  --mysql-dry-run[=on|off]         Dry run, pretend that all MySQL client API calls are successful without executing them [off]
乾式運行,假設全部MySQL客戶端API調用都是成功的,而不須要執行它們
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
 
See 'sysbench <testname> help' for a list of options for each test.
 
[root@zhumh ~]# sysbench fileio help
sysbench 1.0.2 (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]   在全部IO操做中使用的塊大小爲16384
  --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]   文件操做模式同步,異步,mmap同步
  --file-async-backlog=N    number of asynchronous operatons to queue per thread [128]
                              每一個線程排隊的異步操做數
  --file-extra-flags=STRING additional flags to use on opening files {sync,dsync,direct} []
                              打開文件同步,dsync,直接使用的其餘標誌
  --file-fsync-freq=N       do fsync() after this number of requests (0 - don't use fsync()) [100]
                              在此請求數以後不要使用fsync,請執行fsync
  --file-fsync-all[=on|off] do fsync() after each write operation [off]   在每次寫操做結束後執行fsync
  --file-fsync-end[=on|off] do fsync() at the end of test [on]    在測試結束時作fsync
  --file-fsync-mode=STRING  which method to use for synchronization {fsync, fdatasync} [fsync]
                               用於同步fsync、fdatasync fsync的方法
  --file-merged-requests=N  merge at most this number of IO requests if possible (0 - don't merge) [0]
                               若是可能的話,最多合併IO請求的數量
  --file-rw-ratio=N         reads/writes ratio for combined test [1.5]     組合測試1.5的讀/寫比率
 
[root@zhumh ~]# sysbench memory help
sysbench 1.0.2 (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]   數據傳輸總量的總規模
  --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] 
                                 類型的內存操做讀取,寫入,沒有寫入
  --memory-access-mode=STRING memory access mode {seq,rnd} [seq]   內存訪問模式seq,rnd seq
 
[root@zhumh ~]# sysbench threads help
sysbench 1.0.2 (using bundled LuaJIT 2.1.0-beta2)
 
threads options:
  --thread-yields=N number of yields to do per request [1000]    每一個請求的產量數
  --thread-locks=N  number of locks per thread [8]   每一個線程8的鎖數
 
[root@zhumh ~]# sysbench mutex help
sysbench 1.0.2 (using bundled LuaJIT 2.1.0-beta2)
 
mutex options:
  --mutex-num=N   total size of mutex array [4096]   互斥鎖的總大小4096
  --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]   在互斥鎖中執行的空循環數
 
[root@zhumh ~]# sysbench cpu help
sysbench 1.0.2 (using bundled LuaJIT 2.1.0-beta2)
 
cpu options:
  --cpu-max-prime=N upper limit for primes generator [10000]    啓動  primes generator 10000的上限
 
使用方法
3.1  命令格式
sysbench [options]... [testname] [command]
3.2 Command
Commands implemented by most tests: prepare run cleanup help
 
    prepare            --生成測試須要的數據
    run                --進行性能測試
    cleanup            --清除測試數據
 
3.3 Testname
包括兩種:內建腳本和 lua腳本
內建腳本以下:
  fileio - File I/O test
  cpu - CPU performance test
  memory - Memory functions speed test
  threads - Threads subsystem performance test
  mutex - Mutex performance test
 
lua腳本以下:
[root@zhumh ~]# ll /usr/share/sysbench/
total 64
-rwxr-xr-x 1 root root  1452 Feb 17 18:01 bulk_insert.lua
-rw-r--r-- 1 root root 13756 Feb 17 18:01 oltp_common.lua
-rwxr-xr-x 1 root root  1116 Feb 17 18:01 oltp_delete.lua
-rwxr-xr-x 1 root root  1957 Feb 17 18:01 oltp_insert.lua
-rwxr-xr-x 1 root root  1265 Feb 17 18:01 oltp_point_select.lua
-rwxr-xr-x 1 root root  1649 Feb 17 18:01 oltp_read_only.lua
-rwxr-xr-x 1 root root  1824 Feb 17 18:01 oltp_read_write.lua
-rwxr-xr-x 1 root root  1118 Feb 17 18:01 oltp_update_index.lua
-rwxr-xr-x 1 root root  1127 Feb 17 18:01 oltp_update_non_index.lua
-rwxr-xr-x 1 root root  1440 Feb 17 18:01 oltp_write_only.lua
-rwxr-xr-x 1 root root  1919 Feb 17 18:01 select_random_points.lua
-rwxr-xr-x 1 root root  2118 Feb 17 18:01 select_random_ranges.lua
drwxr-xr-x 4 root root  4096 Apr 13 14:04 tests
3.4 Options
3.4.1  全局參數
General options:
  --threads=N                     指定測試使用多少線程數,默認爲1
  --events=N                      測試執行的總events數量,默認0
  --time=N                        最大執行時間,單位爲秒。默認是10
  --forced-shutdown=STRING         超過max-time強制中斷, 默認是 off  [off]
  --thread-stack-size=SIZE         每一個線程的堆棧大小, 默認是 64k
  --rate=N                        average transactions rate. 0 for unlimited rate [0]
  --report-interval=N              N秒內輸出一次統計數據。默認0禁用
  --report-checkpoints=[LIST,...] 轉儲徹底統計信息並在指定時間點復位全部計數器。 參數是逗號分隔值的列表,表示從必須執行報告檢查點的測試開始所通過的時間(以秒爲單位)。 默認狀況下,報告檢查點處於關閉狀態
  --debug[=on|off]                是否顯示更多的調試信息, 默認是off
--validate[=on|off]             在可能狀況下執行驗證檢查, 默認是off。
  --help[=on|off]                 輸出 help 信息, 並退出
  --version[=on|off]              輸出版本信息, 並退出
  --config-file=FILENAME          配置文件
  --tx-rate=N                     deprecated alias for --rate [0]
  --max-requests=N                deprecated alias for --events [0]
  --max-time=N                    deprecated alias for --time [0]
  --num-threads=N                 deprecated alias for --threads [1]
 
3.4.2  僞隨機數
Pseudo-Random Numbers Generator options:
- -rand-type=STRING 分佈的隨機數{uniform(均勻分佈),Gaussian(高斯分佈),special(空間分佈)}。默認是special
  --rand-spec-iter=N 產生數的迭代次數。默認是12
  --rand-spec-pct=N  值的百分比被視爲’special’ (for special distribution)。默認是1
  --rand-spec-res=N  'special'的百分比值。默認是75
  --rand-seed=N      seed for random number generator. When 0, the current time is used as a RNG seed. [0]
  --rand-pareto-h=N  參數h用於 pareto 分佈[0.2]
 
 
3.4.3  日誌
Log options:
  --verbosity=N                  日誌級別,默認爲3,5=debug,0=只包含重要信息
  --percentile=N        表示設定採樣比例,默認是 95%,即丟棄5%的長請求,在剩餘的95%裏取最大值  [95]
  --histogram[=on|off] print latency histogram in report [off]
 
 
3.4.4  數據庫
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]
  --db-debug[=on|off] print database-specific debug information [off]
 
 
3.4.5  Mysql
 
Compiled-in database drivers:
  mysql - MySQL driver
 
mysql options:
  --mysql-host=[LIST,...]          MySQL server host [localhost]
  --mysql-port=[LIST,...]          MySQL server port [3306]
  --mysql-socket=[LIST,...]        MySQL socket
  --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]
 
3.4.6  fileio
[root@zhumh ~]# sysbench fileio help
sysbench 1.0.2 (using bundled LuaJIT 2.1.0-beta2)
 
fileio options:
  --file-num=N             指定測試生成多少文件[128]
  --file-block-size=N        指定測試塊的大小(一般測試mysql默認爲16k[16384],或8k[8192])[16384]
  --file-total-size=SIZE      指定測試生成總文件大小(file-total-size/file-num=文件個數)[2G]
  --file-test-mode=STRING   --指定測試磁盤IO的模式
        seqwr       順序寫
        seqrewr     順序讀寫
        seqrd       順序讀
        rndrd       隨機讀
        rndwr       隨機寫
        rndrw       隨機讀寫
 
  --file-io-mode=STRING    文件操做模式{sync(同步),async(異步),fastmmap(快速map映射),slowmmap(慢map映射)}。默認是sync
  --file-async-backlog=N    對應每一個線程隊列的異步操做數,默認爲128。
  --file-extra-flags=STRING 使用額外的標誌來打開文件(sync,dsync,direct),mysql一般用direct方式
  --file-fsync-freq=N       --執行fsync()的頻率,默認爲100,0爲不使用 (0 - don't use fsync()) [100]
  --file-fsync-all[=on|off] do fsync()--每次執行完一次寫操做就執行一次fsync(),默認爲off
  --file-fsync-end[=on|off] --在測試結束時才執行fsync。默認是on
  --file-fsync-mode=STRING  用什麼樣的模式來同步文件fsync, fdatasync (see above) fsync
  --file-merged-requests=N  --若是能夠,合併最多的IO請求數(0 – 表示不合並)。默認是0
  --file-rw-ratio=N         --測試時的讀寫比例。默認是1.5
 
 
生成測試用的數據文件,要求生成的數據文件至少要比內存大,不然數據因爲被操做系統緩存而沒法體現 I/O 密集型工做負載。
3.4.7  cpu
[root@zhumh ~]# sysbench cpu help
sysbench 1.0.2 (using bundled LuaJIT 2.1.0-beta2)
 
cpu options:
  --cpu-max-prime=N upper limit for primes generator [10000]
 
 
cpu 測試爲測試計算素數直到某個最大值所需的時間。–cpu-max-prime指定這個最大素數值 
sysben測試cpu時,爲何採用素數加法運算? 
在這種模式下每一個請求在於計算素數——cpu-max-primes選項指定一個值。全部的計算執行使用64位的整數。
 
3.4.8  memory
[root@zhumh ~]# sysbench memory help
sysbench 1.0.2 (using bundled LuaJIT 2.1.0-beta2)
 
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
 
3.4.9  threads
[root@zhumh ~]# sysbench threads help
sysbench 1.0.2 (using bundled LuaJIT 2.1.0-beta2)
 
threads options:
1. --thread-yields=N number of yields to do per request [1000] 每一個請求產生多少個線程,默認[1000]
2. --thread-locks=N number of locks per thread [8]    每一個線程的鎖數量,默認 [8]
 
 
線程調度:線程併發執行,循環響應信號量花費的時間{越少越好}
測試線程調度器的性能。對於高負載狀況下測試線程調度器的行爲很是有用
 
3.4.10  mutex
[root@zhumh ~]# sysbench mutex help
sysbench 1.0.2 (using bundled LuaJIT 2.1.0-beta2)
 
mutex options:
1.    -- mutex - num = N total  size  of  mutex array  [ 4096 ]  數組互斥總大小,默認[4096]
2.    -- mutex - locks = N number  of  mutex locks to do per thread  [ 50000 ] 每一個線程互斥鎖的數量,默認 [50000]
3.    -- mutex - loops = N number  of  empty loops to do inside mutex  lock  [ 10000 內部互斥鎖的空循環數量,默認 [10000
 
 
 
互斥鎖:併發線程同時申請互斥鎖循環必定次數花費的時間{越少越好}
測試互斥鎖的性能,方式是模擬全部線程在同一時刻併發運行,並都短暫請求互斥鎖
3.4.11  OLTP
[root@zhumh ~]# sysbench /usr/share/sysbench/oltp_common.lua help
sysbench 1.0.2 (using bundled LuaJIT 2.1.0-beta2)
 
oltp_common.lua options:
  --distinct_ranges=N           Number of SELECT DISTINCT queries per transaction [1]
                                  每一個事務選擇不一樣查詢的數量
  --sum_ranges=N              Number of SELECT SUM() queries per transaction [1]
                                  每一個事務1的SELECT SUM()查詢數                             
  --skip_trx[=on|off]           Don't start explicit transactions and execute all queries as in the AUTOCOMMIT mode [off]
                                  不啓動顯式的事務,在自動提交模式下執行全部查詢
  --secondary[=on|off]          Use a secondary index in place of the PRIMARY KEY [off]
                                   使用一個二級索引來代替主鍵
  --create_secondary[=on|off]   Create a secondary index in addition to the PRIMARY KEY [on]
                                   除了主鍵以外,還能夠建立一個二級索引
  --index_updates=N             Number of UPDATE index queries per transaction [1]
                                   每一個事務的更新索引查詢數量
  --range_size=N                Range size for range SELECT queries [100]
                                   範圍選擇查詢100
  --auto_inc[=on|off]           Use AUTO_INCREMENT column as Primary Key (for MySQL), or its alternatives in other DBMS. When disabled, use client-generated IDs [on]
     使用autoincrement列做爲主鍵(MySQL自增鍵),或者在其餘DBMS中使用它的替代品。當禁用時,使用客戶機生成的id
  --delete_inserts=N            Number of DELETE/INSERT combination per transaction [1]
                                   每一個事務的刪除/插入組合數
  --tables=N                    Number of tables [1]       表的數量
  --mysql_storage_engine=STRING Storage engine, if MySQL is used [innodb]
       mysqlstorageengine=字符串存儲引擎,若是MySQL使用innodb
  --non_index_updates=N         Number of UPDATE non-index queries per transaction [1]
                                     每一個事務更新非索引查詢的數量
  --table_size=N                Number of rows per table [10000]    每表10000行數
  --pgsql_variant=STRING        Use this PostgreSQL variant when running with the PostgreSQL driver. The only currently supported variant is 'redshift'. When enabled, create_secondary is automatically disabled, and delete_inserts is set to 0
在PostgreSQL驅動程序運行時使用此PostgreSQL變量。目前惟一支持的變體‘redshift’是啓用後,CealEdieAudio將自動禁用,DeleTeEnEdvts設置爲0。
  --simple_ranges=N             Number of simple range SELECT queries per transaction [1]
每一個事務簡單範圍選擇查詢的數量
  --order_ranges=N              Number of SELECT ORDER BY queries per transaction [1]
                                   每一個事務查詢的選擇順序數
  --range_selects[=on|off]      Enable/disable all range SELECT queries [on]
                                   啓用/禁用全部範圍選擇查詢
  --point_selects=N             Number of point SELECT queries per transaction [10]
每一個事務10的點選擇查詢數
                                   
 
測試樣例
4.1 Mysql
4.1.1  準備
建立sbtest數據庫
 
Create database sbtest;
4.1.2  測試腳本
sysbench --threads=10 --tables=10 --table-size=100000 --rand-type=uniform --report-interval=1 --time=60  --mysql-user=root --mysql-password=root --mysql-socket=/data/mysql/db_zhumh/mysql.sock   /usr/share/sysbench/oltp_read_write.lua prepare
 
sysbench --threads=10 --tables=10 --table-size=100000 --rand-type=uniform --report-interval=1 --time=60  --mysql-user=root --mysql-password=root --mysql-socket=/data/mysql/db_zhumh/mysql.sock   /usr/share/sysbench/oltp_read_write.lua run
 
 
4.2 IO
--建立10G的文件,分紅4個,測試16K塊大小,使用direct方式讀,測試600秒(10分鐘),啓用64個線程,每3秒輸出一次結果
#sysbench  --file-num=4 --file-block-size=16384 --file-total-size=10G --file-test-mode=rndrd --file-extra-flags=direct --max-requests=0 --max-time=600 --num-threads=64 --report-interval=3  fileio  prepare  
 
#sysbench  --file-num=4 --file-block-size=16384 --file-total-size=10G --file-test-mode=rndrd --file-extra-flags=direct --max-requests=0 --max-time=600 --num-threads=64 --report-interval=3  fileio  run
 
#sysbench   --file-num=4 --file-block-size=16384 --file-total-size=10G --file-test-mode=rndrd --file-extra-flags=direct --max-requests=0 --max-time=600 --num-threads=64 --report-interval=3 fileio  cleanup
 
磁盤:S3610 * 6 raid10, 內存128G
測試出相關場景下的極限IOPS
 
隨機讀寫(3:2 oltp場景)
 sysbench --num-threads=16 --report-interval=3 --max-requests=0 --max-time=300  --test=fileio --file-num=200 --file-total-size=200G --file-test-mode=rndrw --file-block-size=16384 --file-extra-flags=direct run
fileio_oltp_32
 
隨機讀寫(5:1 oltp場景)
 sysbench --num-threads=16 --report-interval=3 --max-requests=0 --max-time=300  --test=fileio --file-num=200 --file-total-size=200G --file-test-mode=rndrw --file-block-size=16384 --file-extra-flags=direct --file-rw-ratio=5  run
fileio_oltp_51
 
隨機寫
 sysbench --num-threads=16 --report-interval=3 --max-requests=0 --max-time=300  --test=fileio --file-num=200 --file-total-size=200G --file-test-mode=rndwr --file-block-size=16384 --file-extra-flags=direct run
fileio_rndwr
 
隨機讀
 sysbench --num-threads=16 --report-interval=3 --max-requests=0 --max-time=300  --test=fileio --file-num=200 --file-total-size=200G --file-test-mode=rndrd --file-block-size=16384 --file-extra-flags=direct run
5 Tpcc
5.1 Option
[root@localhost sysbench]# sysbench /usr/share/sysbench/tpcc.lua help  
sysbench 1.1.0 (using bundled LuaJIT 2.1.0-beta3)
 
tpcc.lua options:
  --enable_purge=STRING          Use purge transaction (yes, no) [no]
  --force_pk=N                   Force using auto-inc PK on history table [0]
  --mysql_storage_engine=STRING   Storage engine, if MySQL is used [innodb]
  --mysql_table_options=STRING    Extra table options, if MySQL is used. e.g. 'COLLATE latin1_bin' []
  --report_csv=STRING             Report output in csv (yes, no) [no]
   --scale=N                      Scale factor (warehouses) [100]
   --tables=N                     Number of tables [1]
  --trx_level=STRING              Transaction isolation level (RC, RR or SER) [RR]
  --use_fk=N                     Use foreign keys [1]
5.2  測試腳本
./tpcc.lua --mysql-socket=/mysqldb/db_master/mysql.sock --mysql-user=root --mysql-password=zabbix.9.31 --mysql-db=sbt --time=30 --threads=64 --report-interval=1 --tables=10 --scale=10 --db-driver=mysql prepare
 
./tpcc.lua --mysql-socket=/mysqldb/db_master/mysql.sock --mysql-user=root --mysql-password=zabbix.9.31 --mysql-db=sbt --time=30 --threads=64 --report-interval=1 --tables=10 --scale=10 --db-driver=mysql run
 
./tpcc.lua --mysql-socket=/mysqldb/db_master/mysql.sock --mysql-user=root --mysql-password=zabbix.9.31 --mysql-db=sbt --time=30 --threads=64 --report-interval=1 --tables=10 --scale=10 --db-driver=mysql cleanup
6 操做步驟
安裝:
  (準備條件:sysbench-1.0.15-1.el7.centos.x86_64,percona-release-0.1-6.noarch兩個包)
 
6.1 root用戶隨便建個文件夾
sysbench-1.0.15-1.el7.centos.x86_64,percona-release-0.1-6.noarch兩個包扔進去
 
6.2  環境準備
yum -y install make automake libtool pkgconfig libaio-devel
yum -y install mariadb-devel openssl-devel
yum -y install postgresql-devel
6.3安裝
# rpm -ivh percona-release-0.1-6.noarch.rpm
 
# rpm -ivh sysbench-1.0.15-1.el7.centos.x86_64.rpm
 
6.4 驗證
[root@bogon ~]# sysbench --help
 
有結果返回,驗證成功
 
7 壓力測試
7.1 先建立一個測試的數據庫
mysql> create database sbtest;
Query OK, 1 row affected (1.10 sec)
 
mysql> show databases;
 
 
 
 
 
7.2 查看本地socket地址
mysql> select @@socket;
 
7.3 準備測試環境:
[root@bogon ~]# sysbench --threads=10 --tables=10 --table-size=100000 --rand-type=uniform --report-interval=1 --time=60 --mysql-user=root --mysql-password=oracle --mysql-socket=/mysqldb/db_master/mysql.sock /usr/share/sysbench/oltp_read_write.lua prepare
 
 
 
 
 
7.4開始運行增壓
[root@bogon ~]# sysbench --threads=10 --tables=10 --table-size=100000 --rand-type=uniform --report-interval=1 --time=60  --mysql-user=root --mysql-password=oracle --mysql-socket=/home/mysql/mysqldb/db_master/mysql.sock   /usr/share/sysbench/oltp_read_write.lua run
 
 
 
8 測試結果
8.1  cpu 測試
 
[root@oracle01 ~]# sysbench --threads=10 --tables=10 --table-size=100000 --rand-type=uniform --report-interval=1 --time=10  --mysql-user=root --mysql-password=oracle --mysql-socket=/mysqldb/db_master/mysql.sock   /usr/share/sysbench/oltp_read_write.lua run
。。。。
SQL statistics:
    queries performed:
        read:                            714      --讀總數
        write:                           204     --寫總數
        other:                           102     --其餘操做(CURD以外的操做,例如COMMIT)
        total:                           1020     --所有總數
    transactions:                        51     (4.62 per sec.)      --總事務數(每秒事務數)
    queries:                             1020   (92.48 per sec.)    --其餘操做總數(每秒其餘操做次數)
    ignored errors:                      0      (0.00 per sec.)      --總忽略錯誤總數(每秒忽略錯誤次數)
    reconnects:                          0      (0.00 per sec.)    --重連總數(每秒重連次數)
 
Throughput:    --吞吐量
    events/s (eps):                      4.6238       
    time elapsed:                        11.0300s   --經歷時間
total number of events:              51          -- 事件總數
Throughput = (number of requests) / (total time) 
total time = 測試結束時間 - 測試開始時間 
測試結束時間 = MAX(請求開始時間 + Elapsed Time) 
測試開始時間 = MIN(請求開始時間) 
 
Latency (ms):
         min:                                 1500.36
         avg:                                 2082.19
         max:                                 2633.22
         95th percentile:                     2493.86
         sum:                               106191.66
 
 
Threads fairness:    --併發統計
    events (avg/stddev):           5.1000/0.30     --總處理事件數/標準誤差
    execution time (avg/stddev):   10.6192/0.29
cpu測試主要是進行素數的加法運算
 
8.2  IO測試
[root@localhost ~]# sysbench  --file-num=4 --file-block-size=16384 --file-total-size=1G --file-test-mode=rndrd --file-extra-flags=direct --max-requests=0 --max-time=600 --num-threads=64 --report-interval=3  fileio  prepare  
WARNING: --num-threads is deprecated, use --threads instead
WARNING: --max-time is deprecated, use --time instead
sysbench 1.0.15 (using bundled LuaJIT 2.1.0-beta2)
 
4 files, 262144Kb each, 1024Mb total
Creating files for the test...
Extra file open flags: directio
Reusing existing file test_file.0
Creating file test_file.1
Creating file test_file.2    (建立文件)
Creating file test_file.3
805306368 bytes written in 128.84 seconds (5.96 MiB/sec).
 
[root@localhost ~]# sysbench  --file-num=4 --file-block-size=16384 --file-total-size=1G --file-test-mode=rndrd --file-extra-flags=direct --max-requests=0 --max-time=10 --num-threads=64 --report-interval=3  fileio  run
WARNING: --num-threads is deprecated, use --threads instead
WARNING: --max-time is deprecated, use --time instead
sysbench 1.0.15 (using bundled LuaJIT 2.1.0-beta2)
 
Running the test with following options:    使用如下選項運行測試:
Number of threads: 64       線程數量:64
Report intermediate results every 3 second(s)   每3秒(s)報告中間結果
Initializing random number generator from current time   從當前時間初始化隨機數生成器
  
 
Extra file open flags: directio    額外的文件打開標誌:方向
4 files, 256MiB each            4個文件,256 mib
1GiB total file size            1GB總文件大小
Block size 16KiB                 塊大小爲16k
Number of IO requests: 0         IO請求數:0
Read/Write ratio for combined random IO test: 1.50   組合隨機IO測試的讀/寫比率1.5
Periodic FSYNC enabled, calling fsync() each 100 requests.
啓用了按期 FSYNC,調用FSYNC每100個請求
Calling fsync() at the end of test, Enabled.   在測試結束時調用fsync
Using synchronous I/O mode   使用同步I / O模式
Doing random read test   作隨機讀取測試
Initializing worker threads...  初始化工做線程…
 
 
Threads started!
 
[ 3s ] reads: 2.34 MiB/s writes: 0.00 MiB/s fsyncs: 0.00/s latency (ms,95%): 877.615
[ 6s ] reads: 3.45 MiB/s writes: 0.00 MiB/s fsyncs: 0.00/s latency (ms,95%): 657.933
[ 9s ] reads: 3.38 MiB/s writes: 0.00 MiB/s fsyncs: 0.00/s latency (ms,95%): 646.192
 
 
File operations:  文件操做
    reads/s:                      189.14   讀的速率
    writes/s:                     0.00     寫的速率
    fsyncs/s:                     0.00     fsync的速率
 
Throughput:
    read, MiB/s:                  2.96  讀的大小(m)
    written, MiB/s:               0.00   寫的大小(m)
 
General statistics:
    total time:                          10.4033s   總時間
    total number of events:              1969       事件總數量
 
Latency (ms):
         min:                                   18.13
         avg:                                  331.26
         max:                                 1335.37
         95th percentile:                      746.32
         sum:                               652243.23
 
Threads fairness:
    events (avg/stddev):           30.7656/3.41
    execution time (avg/stddev):   10.1913/0.13
 
 
 
[root@localhost ~]# sysbench   --file-num=4 --file-block-size=16384 --file-total-size=1G --file-test-mode=rndrd --file-extra-flags=direct --max-requests=0 --max-time=10 --num-threads=64 --report-interval=3 fileio  cleanup
WARNING: --num-threads is deprecated, use --threads instead
WARNING: --max-time is deprecated, use --time instead
sysbench 1.0.15 (using bundled LuaJIT 2.1.0-beta2)
 
Removing test files...
 
8.3  tpcc測試
 
[root@oracle01 sysbench]# ./tpcc.lua --mysql-socket=/mysqldb/db_master/mysql.sock --mysql-user=root --mysql-password=oracle --mysql-db=sbtest --time=30 --threads=64 --report-interval=1 --tables=10 --scale=10 --db-driver=mysql prepare
。。。。
(準備環境:建立 10張表)
[root@oracle01 sysbench]# ./tpcc.lua --mysql-socket=/mysqldb/db_master/mysql.sock --mysql-user=root --mysql-password=oracle --mysql-db=sbtest --time=30 --threads=64 --report-interval=1 --tables=10 --scale=10 --db-driver=mysql run
。。。。
SQL statistics:
    queries performed:   --查詢執行:
        read:                            1195    --讀總數
        write:                           1171    --寫總數
        other:                           308     --其餘操做(CURD以外的操做,例如COMMIT)
        total:                           2674     --所有總數   
    transactions:                        84     (1.65 per sec.)--總事務數(每秒事務數)
    queries:                             2674   (52.47 per sec.)--其餘操做總數(每秒其餘操做次數)
    ignored errors:                      6      (0.12 per sec.)--總忽略錯誤總數(每秒忽略錯誤次數)
    reconnects:                          0      (0.00 per sec.)--重連總數(每秒重連次數)
 
General statistics:  --常規統計
    total time:                          50.9527s   --總耗時
    total number of events:              84      --共發生多少事務數
 
Latency (ms):
         min:                                 4420.74
         avg:                                30312.93
         max:                                50944.12
         95th percentile:                    46941.21
         sum:                              2546286.47
 
Threads fairness:    --併發統計
    events (avg/stddev):           1.3125/0.46   --總處理事件數/標準誤差
    execution time (avg/stddev):   39.7857/6.21
 
 
 
[root@oracle01 sysbench]# ./tpcc.lua --mysql-socket=/mysqldb/db_master/mysql.sock --mysql-user=root --mysql-password=oracle --mysql-db=sbtest --time=30 --threads=64 --report-interval=1 --tables=10 --scale=10 --db-driver=mysql cleanup
sysbench 1.0.15 (using bundled LuaJIT 2.1.0-beta2)
 
Dropping tables '1'...
Dropping tables '2'...
Dropping tables '3'...
Dropping tables '4'...
Dropping tables '5'...
Dropping tables '6'...
Dropping tables '7'...
Dropping tables '8'...
Dropping tables '9'...
Dropping tables '10'...
(清除測試)
 
 
 
 
9經常使用命令
9.1  cpu測試
 
準備
[root@oracle01 ~]# sysbench --threads=10 --tables=10 --table-size=100000 --rand-type=uniform --report-interval=1 --time=10 --mysql-user=root --mysql-password=oracle --mysql-socket=/mysqldb/db_master/mysql.sock   /usr/share/sysbench/oltp_read_write.lua prepare
運行
[root@oracle01 ~]# sysbench --threads=10 --tables=10 --table-size=100000 --rand-type=uniform --report-interval=1 --time=10 --mysql-user=root --mysql-password=oracle --mysql-socket=/mysqldb/db_master/mysql.sock   /usr/share/sysbench/oltp_read_write.lua run
清除
[root@oracle01 ~]# sysbench --threads=10 --tables=10 --table-size=100000 --rand-type=uniform --report-interval=1 --time=10 --mysql-user=root --mysql-password=oracle --mysql-socket=/mysqldb/db_master/mysql.sock   /usr/share/sysbench/oltp_read_write.lua cleanup
 
 
9.2 IO測試
 
準備
[root@oracle01 ~]# sysbench  --file-num=4 --file-block-size=16384 --file-total-size=1G --file-test-mode=rndrd --file-extra-flags=direct --max-requests=0 --max-time=600 --num-threads=64 --report-interval=3  fileio  prepare  
運行
[root@oracle01 ~]# sysbench  --file-num=4 --file-block-size=16384 --file-total-size=1G --file-test-mode=rndrd --file-extra-flags=direct --max-requests=0 --max-time=600 --num-threads=64 --report-interval=3  fileio run
清除
[root@oracle01 ~]# sysbench  --file-num=4 --file-block-size=16384 --file-total-size=1G --file-test-mode=rndrd --file-extra-flags=direct --max-requests=0 --max-time=600 --num-threads=64 --report-interval=3  fileio cleanup
 
9.3 tpcc測試
 
準備
[root@oracle01 sysbench]# ./tpcc.lua --mysql-socket=/mysqldb/db_master/mysql.sock --mysql-user=root --mysql-password=oracle --mysql-db=sbtest --time=30 --threads=64 --report-interval=1 --tables=10 --scale=10 --db-driver=mysql prepare
運行
[root@oracle01 sysbench]# ./tpcc.lua --mysql-socket=/mysqldb/db_master/mysql.sock --mysql-user=root --mysql-password=oracle --mysql-db=sbtest --time=30 --threads=64 --report-interval=1 --tables=10 --scale=10 --db-driver=mysql run
清除
[root@oracle01 sysbench]# ./tpcc.lua --mysql-socket=/mysqldb/db_master/mysql.sock --mysql-user=root --mysql-password=oracle --mysql-db=sbtest --time=30 --threads=64 --report-interval=1 --tables=10 --scale=10 --db-driver=mysql cleanup
 
 
9.4 磁盤測試
準備
[root@oracle01 sysbench]#sysbench --num-threads=16 --report-interval=3 --max-requests=0 --max-time=300  --test=fileio --file-num=200 --file-total-size=200G --file-test-mode=rndrw --file-block-size=16384 --file-extra-flags=direct prepare
運行
[root@oracle01 sysbench]#sysbench --num-threads=16 --report-interval=3 --max-requests=0 --max-time=300  --test=fileio --file-num=200 --file-total-size=200G --file-test-mode=rndrw --file-block-size=16384 --file-extra-flags=direct run
清除
[root@oracle01 sysbench]#sysbench --num-threads=16 --report-interval=3 --max-requests=0 --max-time=300  --test=fileio --file-num=200 --file-total-size=200G --file-test-mode=rndrw --file-block-size=16384 --file-extra-flags=direct cleanup
相關文章
相關標籤/搜索