標籤:通過 完成 服務 spec 分享 art 2.3 conf mon
近期由於要比較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
--auto-generate-sql, -a 自動產生測試表和資料,表示用mysqlslap工具自己產生的SQL指令碼來測試並發壓力。--auto-generate-sql-load-type=type 測試語句的類型。代表要測試的環境是讀操作還是寫操作還是兩者混合的。取值包括:read,key,write,update和mixed(預設)。--auto-generate-sql-add-auto-increment 代表對產生的表自動添加auto_increment列,從5.1.18版本開始支援。--number-char-cols=N, -x N 自動產生的測試表中包含多少個字元類型的列,預設1--number-int-cols=N, -y N 自動產生的測試表中包含多少個數字類型的列,預設1--number-of-queries=N 總的測試查詢次數(並發客戶數×每客戶查詢次數)--query=name,-q 使用自訂指令碼執行測試,例如可以調用自訂的一個預存程序或者sql語句來執行測試。--create-schema 代表自訂的測試庫名稱,測試的schema,MySQL中schema也就是database。--commint=N 多少條DML後提交一次。--compress, -C 如果伺服器和用戶端支援都壓縮,則壓縮資訊傳遞。--concurrency=N, -c N 表示並發量,也就是類比多少個用戶端同時執行select。可指定多個值,以逗號或者--delimiter參數指定的值做為分隔字元。例如:--concurrency=100,200,500。--engine=engine_name, -e engine_name 代表要測試的引擎,可以有多個,用分隔字元隔開。例如:--engines=myisam,innodb。--iterations=N, -i N 測試執行的迭代次數,代表要在不同並發環境下,各自運行測試多少次。--only-print 只列印測試語句而不實際執行。--detach=N 執行N條語句後斷開重連。--debug-info, -T 列印記憶體和CPU的相關資訊。
說明:
測試的過程需要產生測試表,插入測試資料,這個mysqlslap可以自動產生,預設產生一個mysqlslap的schema,如果已經存在則先刪除。可以用--only-print來列印實際的測試過程,整個測試完成後不會在資料庫中留下痕迹。
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
BenchmarkAverage number of seconds to run all queries: 25.225 secondsMinimum number of seconds to run all queries: 25.225 secondsMaximum number of seconds to run all queries: 25.225 secondsNumber of clients running queries: 100Average number of queries per client: 0
以上表明100個用戶端同時運行要25秒
2、sysbench
安裝:
可以從http://sourceforge.net/projects/sysbench/ 下載tar zxf sysbench-0.4.12.tar.gzcd sysbench-0.4.12./autogen.sh./configure && make && make installstrip /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 benchmarkNo DB drivers specified, using mysqlRunning the test with following options:Number of threads: 100Doing OLTP test.Running mixed OLTP testUsing Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases)Using "BEGIN" for starting transactionsUsing auto_inc on the id columnMaximum number of requests for OLTP test is limited to 4000Threads started!Done.OLTP test statistics:queries performed:read: 56014write: 20005other: 8002total: 84021transactions: 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.4393stotal number of events: 4001total time taken by event execution: 1504.7744per-request statistics:min: 33.45msavg: 376.10msmax: 861.53msapprox. 95 percentile: 505.65msThreads fairness:events (avg/stddev): 40.0100/0.67execution time (avg/stddev): 15.0477/0.22
3、tpcc-mysql
安裝:
如果從原網站上下載源碼比較麻煩,需要工具、註冊、產生認證等。這裡提供一個下載包http://blog.chinaunix.net/blog/downLoad/fileid/8532.htmlexport C_INCLUDE_PATH=/usr/include/mysqlexport PATH=/usr/bin:$PATHexport LD_LIBRARY_PATH=/usr/lib/mysqlcd /tmp/tpcc/srcmake 然後就會在 /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.77620, 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.01830, 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.87440, 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.49550, 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.39860, 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.855STOPPING 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種商品的庫存記錄。
4. The MySQL Benchmark Suite
這個測試載入器是隨著MySQL綁定發行的,基於Perl語言和其中的兩個模組:DBI和Benchmark。如果有需要,它支援所有支援DBI驅動的資料庫。可以通過修改bench-init.pl的選項以符合需要。另外提醒的是,它不支援多CPU。
進行測試時,執行run-all-tests指令碼,具體的命令選項請看README。
5. MySQL super-smack
這是一個強大的廣受讚譽的壓力測試工具,支援MySQL和PostgreSQL。
http://jeremy.zawodny.com/mysql/super-smack/
安裝很簡單,請先仔細閱讀目錄裡的指導檔案。
Preparing test data
做測試時,最好用自己的資料。因為使用真實的資料,使測試變得接近現實和客觀。
Configuration
smack的檔案設定,看起來很簡單。
6. MyBench: A Home-Grown Solution
MyBench一種基於Perl語言易於擴充的測試載入器。
http://jeremy.zawodny.com/mysql/mybench/
mysql幾種效能測試的工具使用