CentOS效能測試最新工具 – sysbench

來源:互聯網
上載者:User

sysbench是一款開源的多線程效能測試工具,可以執行CPU/記憶體/線程/IO/資料庫等方面的效能測試。資料庫目前支援MySQL/Oracle/PostgreSQL。本文只是簡單示範一下幾種測試的用法,後續準備利用sysbench來對MySQL進行一系列的測試。具體的一些參數設定,需要根據不同的測試要求來進行調整.

編譯安裝

# wget -c http://sourceforge.net/projects/sysbench/files/sysbench/0.4.12/sysbench-0.4.12.tar.gz/download

#tar zxvf sysbench-0.4.12.tar.gz

#cd sysbench-0.4.12

#./configure && make && make install

如果需要測試Oracle/PostgreSQL,則在configure時需要加上–with-oracle或者–with-pgsql參數

參數

[root@localhost sysbench]# ./sysbench

測試案例:
sysbench [general-options]… –test=<test-name> [test-options]… command

通用選項:
–num-threads=N 建立測試線程的數目。預設為1.
–max-requests=N 請求的最大數目。預設為10000,0代表不限制。
–max-time=N 最大執行時間,單位是s。預設是0,不限制。
–forced-shutdown=STRING 超過max-time強制中斷。預設是off。]
–thread-stack-size=SIZE 每個線程的堆棧大小。預設是32K。
–init-rng=[on|off] 在測試開始時是否初始化隨機數發生器。預設是off。
–test=STRING 指定測試專案名稱。
–debug=[on|off] 是否顯示更多的調試資訊。預設是off。
–validate=[on|off] 在可能情況下執行驗證檢查。預設是off。

測試專案:
fileio – File I/O test
cpu – CPU performance test
memory – Memory functions speed test
threads – Threads subsystem performance test
mutex – Mutex performance test(互斥效能測試)
oltp – OLTP test

指令: prepare(測試前準備工作) run(正式測試) cleanup(測試後刪掉測試資料) help version

See ‘sysbench –test=<name> help’ for a list of options for each test. 查看每個測試專案的更多選項列表。

[root@localhost bin]# ./sysbench –test=fileio help
–file-num=N 建立測試檔案的數量。預設是128
–file-block-size=N 測試時檔案塊的大小。預設是16384(16K)
–file-total-size=SIZE 測試檔案的總大小。預設是2G
–file-test-mode=STRING 檔案測試模式{seqwr(順序寫), seqrewr(順序讀寫), seqrd(順序讀), rndrd(隨機讀), rndwr(隨機寫), rndrw(隨機讀寫)}
–file-io-mode=STRING 檔案操作模式{sync(同步),async(非同步),fastmmap(快速map映射),slowmmap(慢map映射)}。預設是sync
–file-extra-flags=STRING 使用額外的標誌來開啟檔案{sync,dsync,direct} 。預設為空白
–file-fsync-freq=N 執行fsync()的頻率。(0 – 不使用fsync())。預設是100
–file-fsync-all=[on|off] 每執行完一次寫操作就執行一次fsync。預設是off
–file-fsync-end=[on|off] 在測試結束時才執行fsync。預設是on
–file-fsync-mode=STRING 使用哪種方法進行同步{fsync, fdatasync}。預設是fsync
–file-merged-requests=N 如果可以,合并最多的IO請求數(0 – 表示不合并)。預設是0
–file-rw-ratio=N 測試時的讀寫比例。預設是1.5

[root@localhost bin]# ./sysbench –test=cpu help
–cpu-max-prime=N 最大質數發生器數量。預設是10000

[root@localhost bin]# ./sysbench –test=memory help
–memory-block-size=SIZE 測試時記憶體塊大小。預設是1K
–memory-total-size=SIZE 傳輸資料的總大小。預設是100G
–memory-scope=STRING 記憶體存取範圍{global,local}。預設是global
–memory-hugetlb=[on|off] 從HugeTLB池記憶體配置。預設是off
–memory-oper=STRING 記憶體操作類型。{read, write, none} 預設是write
–memory-access-mode=STRING儲存空間存取方式{seq,rnd} 預設是seq

[root@localhost bin]# ./sysbench –test=threads help
–thread-yields=N 每個請求產生多少個線程。預設是1000
–thread-locks=N 每個線程的鎖的數量。預設是8

[root@localhost bin]# ./sysbench –test=mutex help
–mutex-num=N 數組互斥的總大小。預設是4096
–mutex-locks=N 每個線程互斥鎖的數量。預設是50000
–mutex-loops=N 內部互斥鎖的空迴圈數量。預設是10000

[root@localhost bin]# ./sysbench –test=oltp help
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

General database options:
–db-driver=STRING 指定資料庫驅動程式(‘help’ to get list of available drivers)
–db-ps-mode=STRING編製報表使用模式{auto, disable} [auto]

Compiled-in database drivers:
mysql – MySQL driver

mysql options:
–mysql-host=[LIST,...] MySQL server host [localhost]
–mysql-port=N MySQL server port [3306]
–mysql-socket=STRING MySQL socket
–mysql-user=STRING MySQL user [sbtest]
–mysql-password=STRING MySQL password []
–mysql-db=STRING MySQL database name [sbtest]
–mysql-table-engine=STRING storage engine to use for the test table {myisam,innodb,bdb,heap,ndbcluster,federated} [innodb]
–mysql-engine-trx=STRING whether storage engine used is transactional or not {yes,no,auto} [auto]
–mysql-ssl=[on|off] use SSL connections, if available in the client library [off]
–myisam-max-rows=N max-rows parameter for MyISAM tables [1000000]
–mysql-create-options=STRING additional options passed to CREATE TABLE []

測試

1、CPU測試

[root@localhost bin]# ./sysbench –test=cpu –cpu-max-prime=20000 run

sysbench 0.4.12: multi-threaded system evaluation benchmark

Number of threads: 1

Doing CPU performance benchmark

Threads started!
Done.

Maximum prime number checked in CPU test: 20000
Test execution summary:
total time: 31.9364s
total number of events: 10000
total time taken by event execution: 31.9334
per-request statistics:
min: 3.18ms
avg: 3.19ms
max: 3.60ms
approx. 95 percentile: 3.20ms

Threads fairness:
events (avg/stddev): 10000.0000/0.00
execution time (avg/stddev): 31.9334/0.00

2、線程數測試

thread-locks小於線程數除以2,lock越少,處理時間越長。

# ./sysbench –test=threads –num-threads=512 –thread-yields=100 –thread-locks=2 run

sysbench 0.4.12: multi-threaded system evaluation benchmark
Running the test with following options:Number of threads: 512
Doing thread subsystem performance test

Thread yields per test: 100 Locks used: 2

Threads started!

WARNING: Operation time (0.000000) is less than minimal counted value, counting as 1.000000

WARNING: Percentile statistics will be inaccurateDone.

Test execution summary:

total time: 4.1759s

total number of events: 10000

total time taken by event execution: 2038.5959

per-request statistics:

min: 0.00ms

avg: 203.86ms

max: 2735.47ms

approx. 95 percentile: 829.60ms
Threads fairness:

events (avg/stddev): 19.5312/8.26

execution time (avg/stddev): 3.9816/0.04

3、磁碟IO效能測試

首先產生需要的測試檔案,檔案總大小3G,16個並發線程,隨機讀寫入模式。執行完後會在目前的目錄下產生一堆小檔案。

# ./sysbench –test=fileio –num-threads=16 –file-total-size=3G –file-test-mode=rndrw prepare

sysbench 0.4.12: multi-threaded system evaluation benchmark

128 files, 24576Kb each, 3072Mb total

Creating files for the test…

開始測試:

# ./sysbench –test=fileio –num-threads=16 –file-total-size=3G –file-test-mode=rndrw run

sysbench 0.4.12: multi-threaded system evaluation benchmark

Running the test with following options:Number of threads: 16

Extra file open flags: 0

128 files, 24Mb each

3Gb total file size

Block size 16Kb

Number of random requests for random IO: 10000

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 modeDoing random r/w test

Threads started!

WARNING: Operation time (0.000000) is less than minimal counted value, counting as 1.000000

WARNING: Percentile statistics will be inaccurateDone.

Operations performed: 6004 Read, 3996 Write, 12800 Other = 22800 TotalRead 93.812Mb Written 62.438Mb Total transferred 156.25Mb (6.472Mb/sec) 414.21 Requests/sec executed

Test execution summary:

total time: 24.1426s

total number of events: 10000

total time taken by event execution: 164.4243

per-request statistics:

min: 0.00ms

avg: 16.44ms

max: 821.08ms approx. 95 percentile: 102.40ms
Threads fairness:

events (avg/stddev): 625.0000/63.99 e

xecution time (avg/stddev): 10.2765/0.62

清理現場

# ./sysbench –test=fileio –num-threads=16 –file-total-size=3G –file-test-mode=rndrw cleanup

sysbench 0.4.12: multi-threaded system evaluation benchmark

Removing test files…

4、記憶體測試

下面的參數指定了本次測試整個過程是在記憶體中傳輸 1G 的資料量,每個 block 大小為 8K。

./sysbench –test=memory –num-threads=64 –memory-block-size=8192 –memory-total-size=1G run

sysbench 0.4.12: multi-threaded system evaluation benchmark

Running the test with following options:

Number of threads: 64

Doing memory operations speed test

Memory block size: 8K

Memory transfer size: 1024M

Memory operations type: writeMemory scope type: globalThreads started!(last message repeated 1 times)

WARNING: Operation time (0.000000) is less than minimal counted value, counting as 1.000000

WARNING: Percentile statistics will be inaccurate(last message repeated 1 times)Done.

Operations performed: 131072 (416391.08 ops/sec)

1024.00 MB transferred (3253.06 MB/sec)

Test execution summary:

total time: 0.3148s

total number of events: 131072

total time taken by event execution: 17.5553

per-request statistics:

min: 0.00ms

avg: 0.13ms

max: 289.55ms

approx. 95 percentile: 0.00ms
Threads fairness:

events (avg/stddev): 2048.0000/4854.85

execution time (avg/stddev): 0.2743/0.04

5、Mutex測試

測試mutex
[root@localhost ]# ./sysbench –test=mutex –num-threads=1500 –max-requests=2000 –mutex-num=10240 –mutex-locks=100000

–mutex-loops=15000 run
sysbench 0.4.12: multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 1500

Doing mutex performance test
Threads started!
Done.
Test execution summary:
total time: 74.0710s
total number of events: 1500
total time taken by event execution: 5410.6925
per-request statistics:
min: 485.77ms
avg: 3607.13ms
max: 13770.44ms
approx. 95 percentile: 12489.67ms

Threads fairness:
events (avg/stddev): 1.0000/0.00
execution time (avg/stddev): 3.6071/3.97

6、MySQL資料庫測試


首先需要建立預設的sbtest資料庫,或者使用–mysql-db指定一個已經存在的資料庫

產生測試資料,引擎為myisam,表大小為1000000條記錄

[root@localhost ]# ./sysbench --test=oltp --mysql-table-engine=myisam --oltp-table-size=1000000 \--mysql-user=root --mysql-socket=/opt/mysql/run/mysql.sock prepare
sysbench 0.4.12:  multi-threaded system evaluation benchmarkNo DB drivers specified, using mysqlCreating table 'sbtest'...Creating 1000000 records in table 'sbtest'...root@sbtest 11:42:18>desc sbtest.sbtest;+-------+------------------+------+-----+---------+----------------+| Field | Type             | Null | Key | Default | Extra          |+-------+------------------+------+-----+---------+----------------+| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment || k     | int(10) unsigned | NO   | MUL | 0       |                || c     | char(120)        | NO   |     |         |                || pad   | char(60)         | NO   |     |         |                |+-------+------------------+------+-----+---------+----------------+

執行測試

[root@localhost ]# ./sysbench --test=oltp --mysql-table-engine=myisam --oltp-table-size=1000000 \--mysql-user=root --mysql-socket=/opt/mysql/run/mysql.sock run
sysbench 0.4.12:  multi-threaded system evaluation benchmarkNo DB drivers specified, using mysqlRunning the test with following options:Number of threads: 1Doing OLTP test.Running mixed OLTP testUsing Special distribution (12 iterations,  1 pct of values are returned in 75 pct cases)Using "LOCK TABLES WRITE" for starting transactionsUsing auto_inc on the id columnMaximum number of requests for OLTP test is limited to 10000Threads started!Done.OLTP test statistics:    queries performed:        read:                            140000        write:                           50000        other:                           20000        total:                           210000    transactions:                        10000  (336.64 per sec.)    deadlocks:                           0      (0.00 per sec.)    read/write requests:                 190000 (6396.11 per sec.)    other operations:                    20000  (673.27 per sec.)Test execution summary:    total time:                          29.7056s    total number of events:              10000    total time taken by event execution: 29.6301    per-request statistics:         min:                                  2.27ms         avg:                                  2.96ms         max:                                 43.88ms         approx.  95 percentile:               3.36msThreads fairness:    events (avg/stddev):           10000.0000/0.00    execution time (avg/stddev):   29.6301/0.00

清理現場

[root@localhost ]# ./sysbench--test=oltp --mysql-table-engine=myisam --oltp-table-size=1000000 \--mysql-user=root --mysql-socket=/opt/mysql/run/mysql.sock cleanup
sysbench 0.4.12:  multi-threaded system evaluation benchmarkNo DB drivers specified, using mysqlDropping table 'sbtest'...Done.


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.