1. 程式人生 > >sysbench壓測過程

sysbench壓測過程

 1.sysbench安裝(sysbench1.1.0)

 
 [[email protected] soft]# ls sysbench1.1.0.zip

sysbench1.1.0.zip

解壓:

[[email protected] soft]# unzip sysbench1.1.0.zip

安裝依賴:

yum -y install mysql-devel

yum -y  install make automake libtool pkgconfig libaio-devel vim-common

編譯安裝:

cd sysbench-master/

./autogen.sh

./configure --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib

make

make install

cd /usr/local/share/sysbench

若編譯安裝出錯的解決方法:

ls -l /usr/local/mysql/lib/libmysqlclient.so.18*

ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/

vi /etc/ld.so.conf

export LD_LIBRARY_PATH=/usr/local/mysql/lib

ldconfig 

2.sysbench壓測說明

[[email protected] sysbench-master]# cd /usr/local/share/sysbench

[[email protected] sysbench]# ls

bulk_insert.lua  oltp_delete.lua  oltp_point_select.lua  oltp_read_write.lua    oltp_update_non_index.lua  select_random_points.lua  tests oltp_common.lua  oltp_insert.lua  oltp_read_only.lua     oltp_update_index.lua  oltp_write_only.lua        select_random_ranges.lua

使用其中的oltp_read_write.lua進行讀寫壓力測試:

第1步:構建資料

sysbench oltp_read_write.lua --mysql-socket=/tmp/mysql3306.sock --mysql-host=192.168.88.8 --mysql-port=3306 --mysql-db=lbgtest --mysql-user=root --mysql-password=root --table_size=50000 --tables=10 --threads=20 --time=60 --report-interval=10 prepare

第2步:壓測

sysbench oltp_read_write.lua --mysql-socket=/tmp/mysql3306.sock --mysql-host=192.168.88.8 --mysql-port=3306 --mysql-db=lbgtest --mysql-user=root --mysql-password=root --table_size=50000 --tables=10 --threads=20 --time=60 --report-interval=10 run

選項說明:

--mysql-db=lbgtest   --用來測試的庫,需先建立好。

--table-size=100000 表示每個測試表資料量為 100000

--tables=10     測試的表的個數(會自動建立)。

--threads=20    20個併發連結進行測試。

time=60  表示測試總時長為 60

--report-interval=10 表示每10秒輸出一次測試進度報告

註明:上面的oltp_read_write.lua可寫成絕對路徑,將prepare改為run即可進行測試。

3.壓測示例

 建測試庫:

mysql> create database lbgtest;

建立測試資料:

[[email protected] sysbench]# sysbench oltp_read_write.lua --mysql-socket=/tmp/mysql3306.sock --mysql-host=192.168.88.8 --mysql-port=3306 --mysql-db=lbgtest --mysql-user=root --mysql-password=root --table_size=50000 --tables=10 --threads=20 --time=60 --report-interval=10 prepare

sysbench 1.1.0 (using bundled LuaJIT 2.1.0-beta3)

Initializing worker threads...

Creating table 'sbtest7'...

Creating table 'sbtest10'...

Creating table 'sbtest8'...

Creating table 'sbtest3'...

Creating table 'sbtest1'...

Creating table 'sbtest2'...

Creating table 'sbtest6'...

Creating table 'sbtest5'...

Creating table 'sbtest4'...

Creating table 'sbtest9'...

Inserting 50000 records into 'sbtest3'

Inserting 50000 records into 'sbtest5'

Inserting 50000 records into 'sbtest1'

Inserting 50000 records into 'sbtest6'

Inserting 50000 records into 'sbtest9'

Inserting 50000 records into 'sbtest2'

Inserting 50000 records into 'sbtest4'

Inserting 50000 records into 'sbtest8'

Inserting 50000 records into 'sbtest10'

Inserting 50000 records into 'sbtest7'

Creating a secondary index on 'sbtest5'...

Creating a secondary index on 'sbtest6'...

Creating a secondary index on 'sbtest4'...

Creating a secondary index on 'sbtest7'...

Creating a secondary index on 'sbtest1'...

Creating a secondary index on 'sbtest9'...

Creating a secondary index on 'sbtest3'...

Creating a secondary index on 'sbtest2'...

Creating a secondary index on 'sbtest10'...

Creating a secondary index on 'sbtest8'...

完成後檢視測試資料:

可以在測試庫裡看到資料:

mysql> use lbgtest;

mysql> show tables;

+-------------------+

| Tables_in_lbgtest |

+-------------------+

| sbtest1           |

| sbtest10          |

| sbtest2           |

| sbtest3           |

| sbtest4           |

| sbtest5           |

| sbtest6           |

| sbtest7           |

| sbtest8           |

| sbtest9           |

+-------------------+

mysql> select count(1) from sbtest1;

+----------+

| count(1) |

+----------+

|    50000 |

+----------+

1 row in set (0.02 sec)

測試:

[[email protected] sysbench]# sysbench oltp_read_write.lua --mysql-socket=/tmp/mysql3306.sock --mysql-host=192.168.88.8 --mysql-port=3306 --mysql-db=lbgtest --mysql-user=root --mysql-password=root --table_size=50000 --tables=10 --threads=20 --time=60 --report-interval=10 run

sysbench 1.1.0 (using bundled LuaJIT 2.1.0-beta3)

Running the test with following options:

Number of threads: 20

Report intermediate results every 10 second(s)

Initializing random number generator from current time

Initializing worker threads...

Threads started!

[ 10s ] thds: 20 tps: 112.24 qps: 2281.24 (r/w/o: 1598.45/456.37/226.42) lat (ms,95%): 303.33 err/s: 0.00 reconn/s: 0.00

[ 20s ] thds: 20 tps: 141.68 qps: 2829.12 (r/w/o: 1983.33/562.42/283.36) lat (ms,95%): 244.38 err/s: 0.00 reconn/s: 0.00

[ 30s ] thds: 20 tps: 160.33 qps: 3198.39 (r/w/o: 2239.41/638.32/320.66) lat (ms,95%): 219.36 err/s: 0.00 reconn/s: 0.00

[ 40s ] thds: 20 tps: 161.93 qps: 3248.02 (r/w/o: 2272.64/651.52/323.86) lat (ms,95%): 207.82 err/s: 0.00 reconn/s: 0.00

[ 50s ] thds: 20 tps: 153.09 qps: 3055.18 (r/w/o: 2140.95/608.16/306.08) lat (ms,95%): 227.40 err/s: 0.00 reconn/s: 0.00

[ 60s ] thds: 20 tps: 167.67 qps: 3354.30 (r/w/o: 2347.85/671.10/335.35) lat (ms,95%): 223.34 err/s: 0.00 reconn/s: 0.00

SQL statistics:

    queries performed:

        read:                            125762

        write:                           35932

        other:                           17966

        total:                           179660

    transactions:                        8983   (149.56 per sec.)

    queries:                             179660 (2991.27 per sec.)

    ignored errors:                      0      (0.00 per sec.)

    reconnects:                          0      (0.00 per sec.)

Throughput:

    events/s (eps):                      149.5636

    time elapsed:                        60.0614s

    total number of events:              8983

Latency (ms):

         min:                                 18.81

         avg:                                133.67

         max:                                922.85

         95th percentile:                    240.02

         sum:                            1200750.85

Threads fairness:

    events (avg/stddev):           449.1500/6.83

    execution time (avg/stddev):   60.0375/0.04 

4.測試結果說明

  queries performed:

        read:                125762   //讀總數

        write:                35932    //寫⼊總數

        other:               17966     //其他操作

        total:                179660   //總運算元

    transactions:       8983   (149.56 per sec.)   //TPS每秒事務數

    queries:           179660 (2991.27 per sec.)   //QPS 每秒的讀寫請求數

    ignored errors:      0      (0.00 per sec.)

    reconnects:        0      (0.00 per sec.)

Throughput:

    events/s (eps):                   149.5636

    time elapsed:                    60.0614s   //總時間

    total number of events:            8983     //總事務數

 

其中主要看:

    transactions:       8983   (149.56 per sec.)   //TPS每秒事務數

    queries:           179660 (2991.27 per sec.)   //QPS 每秒的讀寫請求數