1. 程式人生 > >mysql幾種性能測試的工具使用

mysql幾種性能測試的工具使用

following files engines 數據庫 連接線

mysql幾種性能測試的工具使用

近期由於要比較mysql及其分支mariadb, percona的性能,了解了幾個這方面的工具,包括:mysqlslap sysbench tpcc-mysql,做一個整理,備忘,分享

1、mysqlslap
安裝:簡單,裝了mysql就有了

作用:模擬並發測試數據庫性能。

優點:簡單,容易使用。

不足:不能指定生成的數據規模,測試過程不清楚針對十萬級還是百萬級數據做的測試,感覺不太適合做綜合測試,比較適合針對既有數據庫,對單個sql進行優化的測試。

使用方法:
可以使用mysqlslap --help來顯示使用方法:

Default options are read from the following files in the given order:

/etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf

--concurrency代表並發數量,多個可以用逗號隔開,concurrency=10,50,100, 並發連接線程數分別是10、50、100個並發。

--engines代表要測試的引擎,可以有多個,用分隔符隔開。
--iterations代表要運行這些測試多少次。
--auto-generate-sql 代表用系統自己生成的SQL腳本來測試。
--auto-generate-sql-load-type 代表要測試的是讀還是寫還是兩者混合的(read,write,update,mixed)
--number-of-queries 代表總共要運行多少次查詢。每個客戶運行的查詢數量可以用查詢總數/並發數來計算。
--debug-info 代表要額外輸出CPU以及內存的相關信息。
--number-int-cols :創建測試表的 int 型字段數量
--auto-generate-sql-add-autoincrement : 代表對生成的表自動添加auto_increment列,從5.1.18版本開始
--number-char-cols 創建測試表的 char 型字段數量。
--create-schema 測試的schema,MySQL中schema也就是database。
--query 使用自定義腳本執行測試,例如可以調用自定義的一個存儲過程或者sql語句來執行測試。
--only-print 如果只想打印看看SQL語句是什麽,可以用這個選項。

mysqlslap -umysql -p123 --concurrency=100 --iterations=1 --auto-generate-sql --auto-generate-sql-add-autoincrement --auto-generate-sql-load-type=mixed --engine=myisam --number-of-queries=10 --debug-info

或:

指定數據庫和sql語句:

mysqlslap -h192.168.3.18 -P4040 --concurrency=100 --iterations=1 --create-schema=‘test‘ --query=‘select * from test;‘ --number-of-queries=10 --debug-info -umysql -p123

要是看到底做了什麽可以加上:--only-print

Benchmark
Average number of seconds to run all queries: 25.225 seconds
Minimum number of seconds to run all queries: 25.225 seconds
Maximum number of seconds to run all queries: 25.225 seconds
Number of clients running queries: 100
Average number of queries per client: 0

以上表明100個客戶端同時運行要25秒


2、sysbench
安裝:
可以從http://sourceforge.net/projects/sysbench/ 下載
tar zxf sysbench-0.4.12.tar.gz
cd sysbench-0.4.12
./autogen.sh
./configure && make && make install
strip /usr/local/bin/sysbench


安裝時候可能會報錯,後來baidu發現個好文 http://blog.csdn.net/icelemon1314/article/details/7004955 怕以後找不到,也貼過來吧

1.如果mysql不是默認路徑安裝,那麽需要通過指定--with-mysql-includes和--with-mysql-libs參數來加載mysql安裝路徑
2.如果報錯:
../libtool: line 838: X--tag=CC: command not found
../libtool: line 871: libtool: ignoring unknown tag : command not found
../libtool: line 838: X--mode=link: command not found
../libtool: line 1004: *** Warning: inferring the mode of operation is deprecated.: command not found
../libtool: line 1005: *** Future versions of Libtool will require --mode=MODE be specified.: command not found
../libtool: line 2231: X-g: command not found
../libtool: line 2231: X-O2: command not found
那麽執行下根目錄的:autogen.sh文件,然後重新configure && make && make install
3.如果報錯:
sysbench: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
那麽執行下:
n -s /usr/local/mysql5.5/mysql/lib/libmysqlclient.so.18 /usr/lib64/
4.如果執行autogen.sh時,報如下錯誤:
./autogen.sh: line 3: aclocal: command not found
那麽需要安裝一個軟件:
yum install automake
然後需要增加一個參數:查找: AC_PROG_LIBTOOL 將其註釋,然後增加AC_PROG_RANLIB


作用:模擬並發,可以執行CPU/內存/線程/IO/數據庫等方面的性能測試。數據庫目前支持MySQL/Oracle/PostgreSQL

優點:可以指定測試數據的規模,可以單獨測試讀、寫的性能,也可以測試讀寫混合的性能。

不足:測試的時候,由於網絡原因,測試的非常慢,但是最終給的結果卻很好,並發支持很高,所以給我的感覺是並不太準確。當然也可能我沒搞明白原理

使用方法:

準備數據
sysbench --test=oltp --mysql-table-engine=myisam --oltp-table-size=400000 --mysql-db=dbtest2 --mysql-user=root --mysql-host=192.168.1.101 --mysql-password=pwd prepare
執行測試
sysbench --num-threads=100 --max-requests=4000 --test=oltp --mysql-table-engine=innodb --oltp-table-size=400000 --mysql-db=dbtest1 --mysql-user=root --mysql-host=192.168.1.101 --mysql-password=pwd run

sysbench 0.4.12: multi-threaded system evaluation benchmark

No DB drivers specified, using mysql
Running the test with following options:
Number of threads: 100

Doing OLTP test.
Running mixed OLTP test
Using Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases)
Using "BEGIN" for starting transactions
Using auto_inc on the id column
Maximum number of requests for OLTP test is limited to 4000
Threads started!
Done.

OLTP test statistics:
queries performed:
read: 56014
write: 20005
other: 8002
total: 84021
transactions: 4001 (259.14 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 76019 (4923.75 per sec.)
other operations: 8002 (518.29 per sec.)

Test execution summary:
total time: 15.4393s
total number of events: 4001
total time taken by event execution: 1504.7744
per-request statistics:
min: 33.45ms
avg: 376.10ms
max: 861.53ms
approx. 95 percentile: 505.65ms

Threads fairness:
events (avg/stddev): 40.0100/0.67
execution time (avg/stddev): 15.0477/0.22


3、tpcc-mysql
安裝:
如果從原網站上下載源碼比較麻煩,需要工具、註冊、生成證書等。這裏提供一個下載包http://blog.chinaunix.net/blog/downLoad/fileid/8532.html
export C_INCLUDE_PATH=/usr/include/mysql
export PATH=/usr/bin:$PATH
export LD_LIBRARY_PATH=/usr/lib/mysql
cd /tmp/tpcc/src
make
然後就會在 /tmp/tpcc-mysql 下生成 tpcc 命令行工具 tpcc_load 、 tpcc_start

作用:測試mysql數據庫的整體性能

優點:符合tpcc標準,有標準的方法,模擬真實的交易活動,結果比較可靠。

不足:不能單獨測試讀或者寫的性能,對於一些以查詢為主或者只寫的應用,就沒有這麽大的意義了。

使用方法:

加載數據
創建庫
mysql>create database tpcc10;
創建表:
shell>mysql tpcc10 < create_table.sql
添加外鍵:
shell>mysql tpcc10 < add_fkey_idx.sql

加載數據:
1、單進程加載:
shell>./tpcc_load 192.168.11.172 tpcc10 root pwd 300
|主機||數據庫||用戶||密碼||warehouse|
2、並發加載:(推薦,但需要修改一下)
shell>./load.sh tpcc300 300
|數據庫||warehouse|
3、測試
./tpcc_start -h192.168.11.172 -d tpcc -u root -p ‘pwd‘ -w 10 -c 10 -r 10 -l 60 -i 10 -f /mnt/hgfs/mysql/tpcc100_2013522.txt
***************************************
*** ###easy### TPC-C Load Generator ***
***************************************
option h with value ‘192.168.11.172‘
option d with value ‘tpcc‘
option u with value ‘root‘
option p with value ‘pwd‘
option w with value ‘1‘
option c with value ‘100‘
option r with value ‘120‘
option l with value ‘60‘
option i with value ‘10‘
option f with value ‘/mnt/hgfs/mysql/tpcc100_2013522.txt‘
<Parameters>
[server]: 192.168.11.172
[port]: 3306
[DBname]: tpcc
[user]: root
[pass]: pwd
[warehouse]: 1
[connection]: 100
[rampup]: 120 (sec.)
[measure]: 60 (sec.)

RAMP-UP TIME.(120 sec.)

MEASURING START.

10, 245(77):10.923|28.902, 242(0):3.677|10.796, 25(0):1.579|2.198, 24(0):17.451|21.047, 25(4):19.999|33.776
20, 262(75):9.070|11.917, 263(0):3.407|4.716, 26(0):1.608|1.776, 27(0):11.347|16.408, 26(1):19.166|21.018
30, 247(90):11.130|14.131, 241(0):2.367|2.654, 24(0):0.960|1.095, 24(0):9.308|16.538, 25(3):19.999|24.874
40, 237(69):11.840|13.009, 239(1):3.638|7.245, 24(0):0.692|0.773, 23(0):8.756|10.456, 23(1):19.527|20.495
50, 252(69):10.548|17.925, 256(0):2.652|2.893, 26(0):1.177|3.579, 27(0):14.648|15.018, 25(4):19.999|26.398
60, 256(78):9.323|11.328, 251(1):3.895|5.380, 25(0):0.785|1.542, 25(0):11.382|15.829, 26(0):18.481|18.855

STOPPING THREADS....................................................................................................

<Raw Results>
[0] sc:1041 lt:458 rt:0 fl:0
[1] sc:1490 lt:2 rt:0 fl:0
[2] sc:150 lt:0 rt:0 fl:0
[3] sc:150 lt:0 rt:0 fl:0
[4] sc:137 lt:13 rt:0 fl:0
in 60 sec.

<Raw Results2(sum ver.)>
[0] sc:1041 lt:458 rt:0 fl:0
[1] sc:1490 lt:2 rt:0 fl:0
[2] sc:150 lt:0 rt:0 fl:0
[3] sc:150 lt:0 rt:0 fl:0
[4] sc:137 lt:13 rt:0 fl:0

<Constraint Check> (all must be [OK])
[transaction percentage]
Payment: 43.36% (>=43.0%) [OK]
Order-Status: 4.36% (>= 4.0%) [OK]
Delivery: 4.36% (>= 4.0%) [OK]
Stock-Level: 4.36% (>= 4.0%) [OK]
[response time (at least 90% passed)]
New-Order: 69.45% [NG] *
Payment: 99.87% [OK]
Order-Status: 100.00% [OK]
Delivery: 100.00% [OK]
Stock-Level: 91.33% [OK]

<TpmC>
1499.000 TpmC

關於Tpcc的概念請參見http://baike.baidu.com/view/2776305.htm
這裏把測試用例介紹貼一下
TPC-C測試用到的模型是一個大型的商品批發銷售公司,它擁有若幹個分布在不同區域的商品倉庫。當業務擴展的時候,公司將添加新的倉庫。
每個倉庫負責為10個銷售點供貨,其中每個銷售點為3000個客戶提供服務,每個客戶提交的訂單中,平均每個訂單有10項產品,
所有訂單中約1%的產品在其直接所屬的倉庫中沒有存貨,必須由其他區域的倉庫來供貨。同時,每個倉庫都要維護公司銷售的100000種商品的庫存記錄


mysql幾種性能測試的工具使用