TPCC-MySQL使用手冊

一、 下載工具包

Tpcc-mysql是percona基於tpcc衍生出來的產品,專用於mysql基準測試,其源碼放在bazaar(Bazaar是一個分佈式的版本控制系統,採用 GPL 許可協議,

可運行於 Windows、GNU/Linux、UNIX 以及 Mac OS 系統之上。Bazaar 由 Canonical 公司(Ubuntu母公司)贊助)上,因此還需要先安裝bazaar客戶端。


使用root安裝rpm包


rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm

然後就可以開始安裝bzr客戶端了:


yum install bzr

之後,就可以開始用bzr客戶端下載tpcc-mysql源碼了。


cd /tmp

bzr branch lp:~percona-dev/perconatools/tpcc-mysql


二、編譯安裝

編譯非常簡單

      cd tpcc-mysql/src

      make all

      編譯常見問題:

export MYSQL_HOME=/home/okooo/apps/schedule-slave/  指定一次mysql的位置,不然下面的操作找不到

1、          找不到mysql的頭文件。

解決:export C_INCLUDE_PATH=$MYSQL_HOME/include

2、          找不到mysql_config程序   /bin/sh: mysql_config: command not found

解決:export PATH=$MYSQL_HOME/bin:$PATH

3、          運行時找不到mysql庫

解決:export LD_LIBRARY_PATH=$MYSQL_HOME/lib



cd /tmp/tpcc-mysql/src

make

然後就會在 /tmp/tpcc-mysql 下生成 tpcc 命令行工具 tpcc_load 、 tpcc_start


tpcc-mysql有幾個腳本很重要

create_table.sql:創建所需的數據庫表,共9個表

add_fkey_idx.sql:創建索引和外鍵

drop_cons.sql:刪除約束


三、開始加載測試數據

初始化測試庫環境


cd /tmp/tpcc-mysql

mysqladmin create tpcc1000

mysql tpcc1000


mysqladmin -S /home/okooo/apps/schedule-slave/tmp/mysql.sock   create  tpcc100               //創建所需的數據庫

mysql -S /home/okooo/apps/schedule-slave/tmp/mysql.sock  < create_table.sql      //導入表結構                      

mysql -S /home/okooo/apps/schedule-slave/tmp/mysql.sock  < create_table.sql  add_fkey_idx.sql    //創建表索引及FK等



初始化完畢後,就可以開始加載測試數據了


tpcc_load用法



tpcc_load [server] [DB] [user] [pass] [warehouse]

或者

tpcc_load [server] [DB] [user] [pass] [warehouse] [part] [min_wh] [max_wh]

選項 warehouse 意爲指定測試庫下的倉庫數量。


ln -s /home/okooo/apps/schedule-slave/tmp/mysql.sock  /tmp/mysql.sock

./tpcc_load localhost tpcc100 root "" 100  100個再db13上加載了大約3個小時


./tpcc_load  -S /home/okooo/apps/schedule-slave/tmp/mysql.sock  tpcc100  root  ''  100

因此,啓動命令非常簡單


./tpcc_load localhost tpcc1000 root "" 1000

在這裏,需要注意的是 tpcc 默認會讀取 /var/lib/mysql/mysql.sock 這個socket位置,因此如果你的socket不在相應路徑的話,就需要做個軟連接,或者通過TCP/IP的方式連接測試服務器。


也可以修改 load.sh  文件中的數據庫連接路徑


加載測試數據時長視倉庫數量而定,可能會比較久。



      加載數據:

      1、單進程加載:

             shell>./tpcc_load localhost tpcc300 root "" 300

            |主機||數據庫||用戶||密碼||warehouse|

      2、併發加載:(推薦,但需要修改一下)

             shell>./load.sh tpcc300 300

             |數據庫||warehouse|


四、進行測試


tpcc_start的用法也比較簡單



tpcc_start -h server_host -P port -d database_name -u mysql_user -p mysql_password -w warehouses -c connections -r warmup_time -l running_time -i report_interval -f report_file

幾個選項稍微解釋下


-w 指定倉庫數量


-c 指定併發連接數


-r 指定開始測試前進行warmup的時間,進行預熱後,測試效果更好


-l 指定測試持續時間


-I 指定生成報告間隔時長


-f 指定生成的報告文件名


-h:測試主機

-d:測試的數據庫

-u:測試的用戶

-p:測試用戶的密碼

-w:測試的warehouse數

-c:測試的連接線程數

-r:預熱時間

-l:測試時間


現在我們來開啓一個測試案例



tpcc_start  -hlocalhost  -d tpcc1000  -u root  -p '' -w 1000  -c  32  -r 120   -l  3600 -ftpcc_mysql_20120314

#使用tpcc_start 進行16個線程的測試,熱身時間爲60秒, 測試時間爲10分鐘, 可根據自己需要調整


測試結果解讀



time ./tpcc_start -h localhost -d tpcc1000 -u root -p '' -w 1000 -c 32 -r 120 -l 3600 -f tpcc_mysql_20120314


time ./tpcc_start -h localhost -d tpcc100  -w 1000 -c 32 -r 120 -l 3600 -f tpcc_mysql_20131127


***************************************

*** ###easy### TPC-C Load Generator ***

***************************************

option h with value 'localhost'

option d with value 'tpcc1000'

option u with value 'root'

option p with value ''

option w with value '1000'

option c with value '32'

option r with value '120'

option l with value '3600'

option f with value 'tpcc_mysql_20120314'


    [server]: localhost

    [port]: 3306

    [DBname]: tpcc1000

      [user]: root

      [pass]:

 [warehouse]: 1000

[connection]: 32

    [rampup]: 120 (sec.)

   [measure]: 3600 (sec.)


RAMP-UP TIME.(120 sec.)

MEASURING START.


 10, 197(0):1.804|2.188, 205(0):0.435|0.574, 19(0):0.270|0.315, 19(0):1.941|2.253, 19(0):5.906|6.555

 20, 198(0):1.664|1.852, 188(0):0.407|0.440, 20(0):0.209|0.210, 20(0):1.873|1.913, 21(0):5.443|5.498

…...

3600, 308(0):1.876|1.994, 312(0):0.452|0.581, 32(0):0.296|0.309, 30(0):1.924|2.093, 29(0):5.724|5.965


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



 [0] sc:93257  lt:0  rt:0  fl:0

 [1] sc:93265  lt:0  rt:0  fl:0

 [2] sc:9326  lt:0  rt:0  fl:0

 [3] sc:9324  lt:0  rt:0  fl:0

 [4] sc:9323  lt:0  rt:0  fl:0

in 3600 sec.



 [0] sc:93257  lt:0  rt:0  fl:0

 [1] sc:93268  lt:0  rt:0  fl:0

 [2] sc:9326  lt:0  rt:0  fl:0

 [3] sc:9324  lt:0  rt:0  fl:0

 [4] sc:9323  lt:0  rt:0  fl:0


(all must be [OK])

[transaction percentage]

       Payment: 43.48% (>=43.0%) [OK]

  Order-Status: 4.35% (>= 4.0%) [OK]

      Delivery: 4.35% (>= 4.0%) [OK]

   Stock-Level: 4.35% (>= 4.0%) [OK]

[response time (at least 90% passed)]

     New-Order: 100.00%  [OK]

       Payment: 100.00%  [OK]

  Order-Status: 100.00%  [OK]

      Delivery: 100.00%  [OK]

   Stock-Level: 100.00%  [OK]


---- TPCC測試結果

                1554.283 TpmC


real    62m1.975s

user    1m21.824s

sys     1m44.828s



10,197 表示0-10秒,完成了197個transactions

20,198 表示10-20秒,完成了198transactions


最後的TPMC: transactions per minute 表示平均每分鐘完成 22805個transactions



測試結果分析

cd scripts

./analyse.sh /tmp/ mysql_tpcc_20120412 > mysql_tpcc_20120412.res


將mysql_tpcc_20120412.res導入excel,然後就可以進行畫圖。




3,使用gnuplot 繪圖

1> 合併數據文件,以便於畫圖:


paste tpcc-8-data.txt tpcc-512-data.txt tpcc-2g-data.txt > tpcc-graph-data.txt


2> 使用腳本畫圖;


./tpcc-graph.sh tpcc-graph-data.txt  201.jpg



4,附腳本:

[root@localhost shell]# cat tpcc_analyze.sh

#!/bin/bash

TIMESLOT=1

if [ -n "$2" ]

then

TIMESLOT=$2

echo "Defined $2"

fi

cat $1 | grep -v HY000 | grep -v payment | grep -v neword | \

awk -v timeslot=$TIMESLOT ' BEGIN { FS="[,():]"; s=0; cntr=0; aggr=0 } \

/MEASURING START/ { s=1} /STOPPING THREADS/ {s=0} /0/ { if (s==1) { cntr++; aggr+=$2; } \

if ( cntr==timeslot ) { printf ("%d ?\n",$1,aggr) ; cntr=0; aggr=0  }  } '

[root@localhost shell]# cat tpcc-graph.sh

#!/bin/bash

gnuplot << EOP

set style line 1 lt 1 lw 3

set style line 2 lt 5 lw 3

set style line 3 lt 9 lw 3

set terminal jpeg size 640,480

set grid x y

set xlabel "Time(sec)"

set ylabel "Transactions"

set output '$2'

plot "$1" title "PS 5.1.56 buffer pool 8M" ls 1 with lines , \

    "$1" us 3:4 title "PS 5.1.56 buffer pool 512M" ls 2 with lines ,\

    "$1" us 5:6 title "PS 5.1.56 buffer pool 2G" ls 3 with lines axes x1y1

EOP

[root@localhost shell]#



繪圖的腳本 tpcc-graph-build.sh 如下:


#! /bin/bash


### goto user homedir and remove previous file

rm -f '$2'

gnuplot << EOP

### set data source file

datafile = '$1'

### set graph type and size

set terminal jpeg size 640,480

### set titles

set grid x y

set xlabel "Time (sec)"

set ylabel "Transactions"

### set output filename

set output '$2'

### build graph

# plot datafile with lines

plot datafile title "5.6.13, binlog" with lines, \

datafile using 3:4 title "5.6.13, nobinlog" with lines axes x1y1

EOP


[root@yw-0-0 tpcc-mysql]# ./tpcc-graph-build.sh  tpcc-graphic-data.txt  tpcc-graph.jpg


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章