http://blog.itpub.net/15480802/viewspace-1419930/
1 背景
TPC(Tracsaction Processing Performance Council) 事务处理性能协会是一个评价大型数据库系统软硬件性能的非盈利的组织,TPC-C是TPC协会制定的,用来测试典型的复杂OLTP系统的性能;Tpcc-mysql是percona基于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可用于并行加载;
初始化完毕后,就可以开始加载测试数据了
问1:warehouse的用途?
一般仓库设置为40-100个为cpu bound,400-1000个是为了测试io bound。40以下无论事务多少,锁竞争情况也不太容易发生
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 最高的rt在1.265ms
订单查询 成功的事务数86个,延迟事务0个, 90%的rt是在0.245ms 最高的rt在0.500ms
发货 成功的事务数87个,延迟事务0个,90%的rt是在2.102ms 最高的rt在3.095ms
库存 成功的事务数86个,延迟事务0个,90%的rt是在5.127ms 最高的rt在11.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