1. 程式人生 > >sysbench安裝、使用、結果解讀

sysbench安裝、使用、結果解讀

sim win r script self cnblogs parse 4.0 報告 inf

sysbench是一個模塊化的、跨平臺、多線程基準測試工具,主要用於評估測試各種不同系統參數下的數據庫負載情況。
目前sysbench代碼托管在github上,項目地址:https://github.com/akopytov/sysbench

一、 下載安裝

git clone https://github.com/akopytov/sysbench

### RHEL/CentOS
``` shell
yum -y install make automake libtool pkgconfig libaio-devel
# For MySQL support, replace with mysql-devel on RHEL/CentOS 5
yum -y install mariadb-devel openssl-devel
# For PostgreSQL support
yum -y install postgresql-devel

./autogen.sh
# Add --with-pgsql to build with PostgreSQL support
./configure
make -j
make install

sysbench is a scriptable multi-threaded benchmark tool based on LuaJIT. It is most frequently used for database benchmarks, but can also be used to create arbitrarily complex workloads that do not involve a database server.

sysbench comes with the following bundled benchmarks:

  • oltp_*.lua: a collection of OLTP-like database benchmarks
  • fileio: a filesystem-level benchmark
  • cpu: a simple CPU benchmark
  • memory: a memory access benchmark
  • threads: a thread-based scheduler benchmark
  • mutex: a POSIX mutex benchmark

sysbench支持以下幾種測試模式:

1CPU運算性能
2、磁盤IO性能
3、調度程序性能
4、內存分配及傳輸速度
5POSIX線程性能
6、數據庫性能(OLTP基準測試)
目前sysbench主要支持 mysql,drizzle,pgsql,oracle 等幾種數據庫。

三、OLTP測試前準備
初始化測試庫環境(總共10個測試表,每個表 100000 條記錄,填充隨機生成的數據):

cd /tmp/sysbench-0.4.12-1.1/sysbench
mysqladmin create sbtest

./sysbench --mysql-host=1.2.3.4 --mysql-port=3317 --mysql-user=tpcc --mysql-password=tpcc  --test=tests/db/oltp.lua --oltp_tables_count=10 --oltp-table-size=100000 --rand-init=on prepare

關於這幾個參數的解釋:

--test=tests/db/oltp.lua 表示調用 tests/db/oltp.lua 腳本進行 oltp 模式測試
--oltp_tables_count=10 表示會生成 10 個測試表
--oltp-table-size=100000 表示每個測試表填充數據量為 100000 
--rand-init=on 表示每個測試表都是用隨機數據來填充的

如果在本機,也可以使用 –mysql-socket 指定 socket 文件來連接。加載測試數據時長視數據量而定,若過程比較久需要稍加耐心等待。

真實測試場景中,數據表建議不低於10個,單表數據量不低於500萬行,當然了,要視服務器硬件配置而定。如果是配備了SSD或者PCIE SSD這種高IOPS設備的話,則建議單表數據量最少不低於1億行

四、進行OLTP測試

在上面初始化數據參數的基礎上,再增加一些參數,即可開始進行測試了:

./sysbench --mysql-host=1.2.3.4. --mysql-port=3306 --mysql-user=tpcc --mysql-password=tpcc --test=tests/db/oltp.lua --oltp_tables_count=10 --oltp-table-size=10000000 --num-threads=8 --oltp-read-only=off --report-interval=10 --rand-type=uniform --max-time=3600  --max-requests=0 --percentile=99 run >> ./log/sysbench_oltpX_8_20140921.log

幾個選項稍微解釋下

--num-threads=8 表示發起 8個並發連接
--oltp-read-only=off 表示不要進行只讀測試,也就是會采用讀寫混合模式測試
--report-interval=10 表示每10秒輸出一次測試進度報告
--rand-type=uniform 表示隨機類型為固定模式,其他幾個可選隨機模式:uniform(固定),gaussian(高斯),special(特定的),pareto(帕累托)
--max-time=120 表示最大執行時長為 120
--max-requests=0 表示總請求數為 0,因為上面已經定義了總執行時長,所以總請求數可以設定為 0;也可以只設定總請求數,不設定最大執行時長
--percentile=99 表示設定采樣比例,默認是 95%,即丟棄1%的長請求,在剩余的99%裏取最大值

即:模擬 對10個表並發OLTP測試,每個表1000萬行記錄,持續壓測時間為 1小時。

真實測試場景中,建議持續壓測時長不小於30分鐘,否則測試數據可能不具參考意義。

五、測試結果解讀:

測試結果解讀如下:

sysbench 0.5:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 8
Report intermediate results every 10 second(s)
Random number generator seed is 0 and will be ignored


Threads started!
-- 10秒鐘報告一次測試結果,tps、每秒讀、每秒寫、99%以上的響應時長統計
[  10s] threads: 8, tps: 1111.51, reads/s: 15568.42, writes/s: 4446.13, response time: 9.95ms (99%)
[  20s] threads: 8, tps: 1121.90, reads/s: 15709.62, writes/s: 4487.80, response time: 9.78ms (99%)
[  30s] threads: 8, tps: 1120.00, reads/s: 15679.10, writes/s: 4480.20, response time: 9.84ms (99%)
[  40s] threads: 8, tps: 1114.20, reads/s: 15599.39, writes/s: 4456.30, response time: 9.90ms (99%)
[  50s] threads: 8, tps: 1114.00, reads/s: 15593.60, writes/s: 4456.70, response time: 9.84ms (99%)
[  60s] threads: 8, tps: 1119.30, reads/s: 15671.60, writes/s: 4476.50, response time: 9.99ms (99%)
OLTP test statistics:
    queries performed:
        read:                            938224    -- 讀總數
        write:                           268064    -- 寫總數
        other:                           134032    -- 其他操作總數(SELECTINSERTUPDATEDELETE之外的操作,例如COMMIT等)
        total:                           1340320    -- 全部總數
    transactions:                        67016  (1116.83 per sec.)    -- 總事務數(每秒事務數)
    deadlocks:                           0      (0.00 per sec.)    -- 發生死鎖總數
    read/write requests:                 1206288 (20103.01 per sec.)    -- 讀寫總數(每秒讀寫次數)
    other operations:                    134032 (2233.67 per sec.)    -- 其他操作總數(每秒其他操作次數)

General statistics:    -- 一些統計結果
    total time:                          60.0053s    -- 總耗時
    total number of events:              67016    -- 共發生多少事務數
    total time taken by event execution: 479.8171s    -- 所有事務耗時相加(不考慮並行因素)
    response time:    -- 響應時長統計
         min:                                  4.27ms    -- 最小耗時
         avg:                                  7.16ms    -- 平均耗時
         max:                                 13.80ms    -- 最長耗時
         approx.  99 percentile:               9.88ms    -- 超過99%平均耗時

Threads fairness:
    events (avg/stddev):           8377.0000/44.33
    execution time (avg/stddev):   59.9771/0.00

***** **

Build and Install
    ./autogen.sh
    # Add --with-pgsql to build with PostgreSQL support
    ./configure
    make -j
    make install

The above will build sysbench with MySQL support by default. If you have MySQL headers and libraries in non-standard locations (and no mysql_config can be found in the PATH), you can specify them explicitly with --with-mysql-includes and --with-mysql-libs options to ./configure.

To compile sysbench without MySQL support, use --without-mysql. If no database drivers are available database-related scripts will not work, but other benchmarks will be functional.

Usage

General Syntax

The general command line syntax for sysbench is:

	  sysbench [options]... [testname] [command] 
  • testname is an optional name of a built-in test (e.g. fileio, memory, cpu, etc.), or a name of one of the bundled Lua scripts (e.g. oltp_read_only), or a path to a custom Lua script. If no test name is specified on the command line (and thus, there is no command too, as in that case it would be parsed as a testname), or the test name is a dash ("-"), then sysbench expects a Lua script to execute on its standard input.

  • command is an optional argument that will be passed by sysbench to the built-in test or script specified with testname. command defines the action that must be performed by the test. The list of available commands depends on a particular test. Some tests also implement their own custom commands.

    Below is a description of typical test commands and their purpose:

    • prepare: performs preparative actions for those tests which need them, e.g. creating the necessary files on disk for the fileio test, or filling the test database for database benchmarks.
    • run: runs the actual test specified with the testname argument. This command is provided by all tests.
    • cleanup: removes temporary data after the test run in those tests which create one.
    • help: displays usage information for the test specified with the testname argument. This includes the full list of commands provided by the test, so it should be used to get the available commands.
  • options is a list of zero or more command line options starting with ‘--‘. As with commands, the sysbench testname help command should be used to describe available options provided by a particular test.

    See General command line options for a description of general options provided by sysbench itself.

You can use sysbench --help to display the general command line syntax and options.

General Command Line Options

The table below lists the supported common options, their descriptions and default values:

OptionDescriptionDefault value
--threads The total number of worker threads to create 1
--events Limit for total number of requests. 0 (the default) means no limit 0
--time Limit for total execution time in seconds. 0 means no limit 10
--warmup-time Execute events for this many seconds with statistics disabled before the actual benchmark run with statistics enabled. This is useful when you want to exclude the initial period of a benchmark run from statistics. In many benchmarks, the initial period is not representative because CPU/database/page and other caches need some time to warm up 0
--rate Average transactions rate. The number specifies how many events (transactions) per seconds should be executed by all threads on average. 0 (default) means unlimited rate, i.e. events are executed as fast as possible 0
--thread-init-timeout Wait time in seconds for worker threads to initialize 30
--thread-stack-size Size of stack for each thread 32K
--report-interval Periodically report intermediate statistics with a specified interval in seconds. Note that statistics produced by this option is per-interval rather than cumulative. 0 disables intermediate reports 0
--debug Print more debug info off
--validate Perform validation of test results where possible off
--help Print help on general syntax or on a specified test, and exit off
--verbosity Verbosity level (0 - only critical messages, 5 - debug) 4
--percentile sysbench measures execution times for all processed requests to display statistical information like minimal, average and maximum execution time. For most benchmarks it is also useful to know a request execution time value matching some percentile (e.g. 95% percentile means we should drop 5% of the most long requests and choose the maximal value from the remaining ones). This option allows to specify a percentile rank of query execution times to count 95
--luajit-cmd perform a LuaJIT control command. This option is equivalent to luajit -j. See LuaJIT documentation for more information

Note that numerical values for all size options (like --thread-stack-size in this table) may be specified by appending the corresponding multiplicative suffix (K for kilobytes, M for megabytes, G for gigabytes and T for terabytes).

Random Numbers Options

sysbench provides a number of algorithms to generate random numbers that are distributed according to a given probability distribution. The table below lists options that can be used to control those algorithms.

OptionDescriptionDefault value
--rand-type random numbers distribution {uniform, gaussian, special, pareto, zipfian} to use by default. Benchmark scripts may choose to use either the default distribution, or specify it explictly, i.e. override the default. special
--rand-seed seed for random number generator. When 0, the current time is used as an RNG seed. 0
--rand-spec-iter number of iterations for the special distribution 12
--rand-spec-pct percentage of the entire range where ‘special‘ values will fall in the special distribution 1
--rand-spec-res percentage of ‘special‘ values to use for the special distribution 75
--rand-pareto-h shape parameter for the Pareto distribution 0.2
--rand-zipfian-exp shape parameter (theta) for the Zipfian distribution 0.8

 

sysbench安裝、使用、結果解讀