tpcc-mysql的工作原理

myownstars發表於2015-01-29

 背景

TPC(Tracsaction Processing Performance Council) 事務處理效能協會是一個評價大型資料庫系統軟硬體效能的非盈利的組織,TPC-CTPC協會制定的,用來測試典型的複雜OLTP系統的效能;Tpcc-mysqlpercona基於tpcc衍生出來的產品,專用於mysql基準測試,其原始碼放在bazaar上,因此需要先安裝bazaar客戶端。

 

2  原理

實現了一個完整的訂單系統(建立對應表和外來鍵約束),測試更接近生產例項;


3  安裝

yum install bzr

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

編譯

cd /tmp/tpcc-mysql/src

make

安裝完畢在根目錄下有:

[root@localhost tpcc-mysql]# ls

add_fkey_idx.sql

create_table.sql

load.sh

schema2 –shell指令碼

src  --c檔案, 用於構造表資料   

tpcc_start

count.sql       

drop_cons.sql   

README 

scripts

tpcc_load

 

 

4  建立測試環境

手工建立一個資料庫,然後匯入表和索引結構

mysql> create database tpcc1000

mysql> use tpcc1000

mysql> \. /opt/create_table.sql

mysql> \. /opt/add_fkey_idx.sql

 

生成資料

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

./tpcc_load localhost tpcc1000 root "" 1000

生成測試資料(這步可能需要很長時間,根據機器效能不同而不同),load.sh可用於並行載入;

初始化完畢後,就可以開始載入測試資料了

 

1warehouse的用途?

一般倉庫設定為40-100個為cpu bound,400-1000個是為了測試io bound40以下無論事務多少,鎖競爭情況也不太容易發

 

 

5  測試用例

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 指定生成的報告檔名

 

下列測試分別對 innodb_buffer_pool_size = 8M,512M,2G 進行測試,事務及實際關係結果下如圖1所示:

./tpcc_start -h172.16.0.230 -dtpcc1000 -unigel -p12345 -w20 -c16 -r10 -l1200 > /opt/8m-tpcc-data.log

./tpcc_start -h172.16.0.230 -dtpcc1000 -unigel -p12345 -w20 -c16 -r10 -l1200 > /opt/512m-tpcc-data.log

./tpcc_start -h172.16.0.230 -dtpcc1000 -unigel -p12345 -w20 -c16 -r10 -l1200 > /opt/2g-tpcc-data.log

 

 

6  輸出分析

Count     New-Order           Payment        Order-Status         Delivery        Stock-Level

     sl(l):rt90|max_rt  sl(l):rt90|max_rt  sl(l):rt90|max_rt  sl(l):rt90|max_rt  sl(l):rt90|max_rt

 #,      #(#):#|#,          #(#):#|#,          #(#):#|#,          #(#):#|#,          #(#):#|#

 

 10, 861(0):1.544|2.791, 858(0):0.471|1.265, 86(0):0.245|0.500, 87(0):2.102|3.095, 86(0):5.127|11.375

上述結果標明新訂單 時間間隔內成功的事務數861,延遲事務0,90%rt 小於1.54ms  最高的rt 2.791ms

             支付     成功的事務數858,延遲事務0,90%rt是在0.471ms 最高的rt1.265ms

             訂單查詢 成功的事務數86,延遲事務0,  90%rt是在0.245ms 最高的rt0.500ms

             發貨     成功的事務數87,延遲事務0,90%rt是在2.102ms 最高的rt3.095ms

             庫存     成功的事務數86,延遲事務0,90%rt是在5.127ms 最高的rt11.375ms

 

TPCC-MySQL輸出結果包括五個業務邏輯,這五個業務邏輯構成了TPCC-MySQL測試的整個事務處理過程。

具體如下所示:

New-Order       :新訂單

Payment         :支付

Order-Status    :訂單查詢

Delivery        :發貨

Stock-Level     :庫存

 

預定義變數:

為了能夠清晰的說明以下內容,首先定義一些變數,便於以下的計算和說明。具體如下所示:

success = 執行成功的記錄數

late = 執行延遲的記錄數

pre_success=上一次執行成功的記錄數

pre_late =  上一次執行失敗的記錄數

 

late定義:

根據不同的業務,late的定義也不同,五種業務邏輯分別對操作延遲定義的界限值如下所示:

New-Order       5ms

Payment         5ms

Order-Status    5ms

Delivery        80ms

Stock-Level     20ms

 

計算:

   根據以上定義的變數,計算相應欄位的結果和說明相應欄位的含義。

1、時間間隔內成功的事務(包括成功和延遲的事務)  :sl=success+late-pre_success-pre_late

2、時間間隔內延遲的事務                        :l=late-pre_late

3、時間間隔內前90%記錄(實際為99%)的平均 rt     :rt90

4、時間間隔內最大的rt                          :max_rt

http://blog.itpub.net/22664653/viewspace-757735

 

 

 

 

附錄1

gnuplot繪圖

生成測試資料檔案:

./tpcc_analyze.sh /opt/8m-tpcc-data.log > tpcc-8-data.txt

./tpcc_analyze.sh /opt/512m-tpcc-data.log > tpcc-512-data.txt

./tpcc_analyze.sh /opt/2g-tpcc-data.log > tpcc-2g-data.txt

使用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


 

[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

http://blog.sina.com.cn/s/blog_445e807b0101fz06.html 

 

 

附錄2

建表指令碼

Create_table.sql

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;

SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;

 

drop table if exists warehouse;

 

create table warehouse (

w_id smallint not null,

w_name varchar(10),

w_street_1 varchar(20),

w_street_2 varchar(20),

w_city varchar(20),

w_state char(2),

w_zip char(9),

w_tax decimal(4,2),

w_ytd decimal(12,2),

primary key (w_id) ) Engine=InnoDB;

 

drop table if exists district;

 

create table district (

d_id tinyint not null,

d_w_id smallint not null,

d_name varchar(10),

d_street_1 varchar(20),

d_street_2 varchar(20),

d_city varchar(20),

d_state char(2),

d_zip char(9),

d_tax decimal(4,2),

d_ytd decimal(12,2),

d_next_o_id int,

primary key (d_w_id, d_id) ) Engine=InnoDB;

 

drop table if exists customer;

 

create table customer (

c_id int not null,

c_d_id tinyint not null,

c_w_id smallint not null,

c_first varchar(16),

c_middle char(2),

c_last varchar(16),

c_street_1 varchar(20),

c_street_2 varchar(20),

c_city varchar(20),

c_state char(2),

c_zip char(9),

c_phone char(16),

c_since datetime,

c_credit char(2),

c_credit_lim bigint,

c_discount decimal(4,2),

c_balance decimal(12,2),

c_ytd_payment decimal(12,2),

c_payment_cnt smallint,

c_delivery_cnt smallint,

c_data text,

PRIMARY KEY(c_w_id, c_d_id, c_id) ) Engine=InnoDB;

 

drop table if exists history;

 

create table history (

h_c_id int,

h_c_d_id tinyint,

h_c_w_id smallint,

h_d_id tinyint,

h_w_id smallint,

h_date datetime,

h_amount decimal(6,2),

h_data varchar(24) ) Engine=InnoDB;

 

drop table if exists new_orders;

 

create table new_orders (

no_o_id int not null,

no_d_id tinyint not null,

no_w_id smallint not null,

PRIMARY KEY(no_w_id, no_d_id, no_o_id)) Engine=InnoDB;

 

drop table if exists orders;

 

create table orders (

o_id int not null,

o_d_id tinyint not null,

o_w_id smallint not null,

o_c_id int,

o_entry_d datetime,

o_carrier_id tinyint,

o_ol_cnt tinyint,

o_all_local tinyint,

PRIMARY KEY(o_w_id, o_d_id, o_id) ) Engine=InnoDB ;

 

drop table if exists order_line;

 

create table order_line (

ol_o_id int not null,

ol_d_id tinyint not null,

ol_w_id smallint not null,

ol_number tinyint not null,

ol_i_id int,

ol_supply_w_id smallint,

ol_delivery_d datetime,

ol_quantity tinyint,

ol_amount decimal(6,2),

ol_dist_info char(24),

PRIMARY KEY(ol_w_id, ol_d_id, ol_o_id, ol_number) ) Engine=InnoDB ;

 

drop table if exists item;

 

create table item (

i_id int not null,

i_im_id int,

i_name varchar(24),

i_price decimal(5,2),

i_data varchar(50),

PRIMARY KEY(i_id) ) Engine=InnoDB;

 

drop table if exists stock;

 

create table stock (

s_i_id int not null,

s_w_id smallint not null,

s_quantity smallint,

s_dist_01 char(24),

s_dist_02 char(24),

s_dist_03 char(24),

s_dist_04 char(24),

s_dist_05 char(24),

s_dist_06 char(24),

s_dist_07 char(24),

s_dist_08 char(24),

s_dist_09 char(24),

s_dist_10 char(24),

s_ytd decimal(8,0),

s_order_cnt smallint,

s_remote_cnt smallint,

s_data varchar(50),

PRIMARY KEY(s_w_id, s_i_id) ) Engine=InnoDB ;

 

SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;

SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

 

 

Add_fkey.indx.sql

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;

SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;

 

CREATE INDEX idx_customer ON customer (c_w_id,c_d_id,c_last,c_first);

CREATE INDEX idx_orders ON orders (o_w_id,o_d_id,o_c_id,o_id);

CREATE INDEX fkey_stock_2 ON stock (s_i_id);

CREATE INDEX fkey_order_line_2 ON order_line (ol_supply_w_id,ol_i_id);

 

ALTER TABLE district  ADD CONSTRAINT fkey_district_1 FOREIGN KEY(d_w_id) REFERENCES warehouse(w_id);

ALTER TABLE customer ADD CONSTRAINT fkey_customer_1 FOREIGN KEY(c_w_id,c_d_id) REFERENCES district(d_w_id,d_id);

ALTER TABLE history  ADD CONSTRAINT fkey_history_1 FOREIGN KEY(h_c_w_id,h_c_d_id,h_c_id) REFERENCES customer(c_w_id,c_d_id,c_id);

ALTER TABLE history  ADD CONSTRAINT fkey_history_2 FOREIGN KEY(h_w_id,h_d_id) REFERENCES district(d_w_id,d_id);

ALTER TABLE new_orders ADD CONSTRAINT fkey_new_orders_1 FOREIGN KEY(no_w_id,no_d_id,no_o_id) REFERENCES orders(o_w_id,o_d_id,o_id);

ALTER TABLE orders ADD CONSTRAINT fkey_orders_1 FOREIGN KEY(o_w_id,o_d_id,o_c_id) REFERENCES customer(c_w_id,c_d_id,c_id);

ALTER TABLE order_line ADD CONSTRAINT fkey_order_line_1 FOREIGN KEY(ol_w_id,ol_d_id,ol_o_id) REFERENCES orders(o_w_id,o_d_id,o_id);

ALTER TABLE order_line ADD CONSTRAINT fkey_order_line_2 FOREIGN KEY(ol_supply_w_id,ol_i_id) REFERENCES stock(s_w_id,s_i_id);

ALTER TABLE stock ADD CONSTRAINT fkey_stock_1 FOREIGN KEY(s_w_id) REFERENCES warehouse(w_id);

ALTER TABLE stock ADD CONSTRAINT fkey_stock_2 FOREIGN KEY(s_i_id) REFERENCES item(i_id);

 

SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;

SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

 

 

刪除外來鍵約束 drop_cons.sql

預熱資料 count.sql  對所有表執行 count(PK)

 

 

 

參考連結

http://blog.chinaunix.net/uid-26896862-id-3188313.html

http://blog.chinaunix.net/uid-25266990-id-4080103.html

http://www.imysql.cn/2012/08/04/tpcc-for-mysql-manual.html

http://d.hatena.ne.jp/sh2/20090212
















來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15480802/viewspace-1419930/,如需轉載,請註明出處,否則將追究法律責任。