您的位置:首页 > 数据库 > SQL

TPCC-MySQL使用手册

2013-12-10 09:58 387 查看
一、 下载工具包
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: