tpcc-mysql数据库绘图工具编译安装

获取源码:

yum install bzr  -y 

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

下载tpcc-mysql过程中遇到的问题 

bzr branch lp:~percona-dev/perconatools/tpcc-mysql 
bzr: ERROR: Couldn't import bzrlib and dependencies. 
Please check the directory containing bzrlib is on your PYTHONPATH. 


Traceback (most recent call last): 
File "/usr/bin/bzr", line 102, in <module> 
import bzrlibpython 
ImportError: No module named bzrlib 


提示找不到 bzrlib 模块,因为调用Python,建议升级到2.6版本 

解决方法: 
# find / -name bzrlib -print 
/usr/lib64/python2.4/site-packages/bzrlib 
定义环境变量: 
# export PYTHONPATH=/usr/lib64/python2.4/site-packages 
再次下载ok. 
#bzr branch lp:~percona-dev/perconatools/tpcc-mysql 
You have not informed bzr of your Launchpad ID, and you must do this to 
write to Launchpad or access private data. See "bzr help launchpad-login". 
Branched 48 revision(s). 

下载之后可以看到tpcc-mysql目录
进入这个目录下的src目录,执行make
在上层目录中,可以看到已经有了tpcc_load  tpcc_start命令

如果有如下错误,则可能是源码安装的MySQL,所以它的库不在默认的位置
error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory 
创建软链接可以解决这个问题。

ln -s /home/lihuilin/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18 

make时遇到如下错误:

load.c: In function ‘Error’:
load.c:1242: error: expected declaration specifiers before ‘MYSQL_STMT’
load.c:1248: error: ‘mysql’ undeclared (first use in this function)
make: *** [load.o] Error 1
解决方法:
[root@localhost src]# export C_INCLUDE_PATH=/usr/local/mysql/include/   (具体根据实际MYSQL安装路径填写对应的mysql/include目录路径)
继续make遇到如下错误:

load.o:/home/happy/Downloads/tpcc-mysql/src/load.c:225: more undefined references to `mysql_stmt_prepare' follow
load.o: In function `main':
/home/happy/Downloads/tpcc-mysql/src/load.c:273: undefined reference to `mysql_commit'
/home/happy/Downloads/tpcc-mysql/src/load.c:276: undefined reference to `mysql_stmt_close'
/home/happy/Downloads/tpcc-mysql/src/load.c:281: undefined reference to `mysql_close'
collect2: ld returned 1 exit status
make: *** [../tpcc_load] Error 1
解决方法:
[root@localhost src]# export PATH=/usr/local/mysql/bin:$PATH (具体根据实际mysql安装目录路径)
[root@localhost src]# export LD_LIBRARY_PATH=/usr/local/mysql/lib(具体根据实际mysql安装目录路径)
然后执行make出现如下提示信息说明安装成功:

[root@localhost src]# make
cc load.o support.o `mysql_config --libs_r` -lrt -o ../tpcc_load
cc -w -O2 -g -I. `mysql_config --include`  -c main.c
cc -w -O2 -g -I. `mysql_config --include`  -c spt_proc.c
cc -w -O2 -g -I. `mysql_config --include`  -c driver.c
cc -w -O2 -g -I. `mysql_config --include`  -c sequence.c
cc -w -O2 -g -I. `mysql_config --include`  -c rthist.c
cc -w -O2 -g -I. `mysql_config --include`  -c neword.c
cc -w -O2 -g -I. `mysql_config --include`  -c payment.c
cc -w -O2 -g -I. `mysql_config --include`  -c ordstat.c
cc -w -O2 -g -I. `mysql_config --include`  -c delivery.c
cc -w -O2 -g -I. `mysql_config --include`  -c slev.c
cc main.o spt_proc.o driver.o support.o sequence.o rthist.o neword.o payment.o ordstat.o delivery.o slev.o `mysql_config --libs_r` -lrt -o ../tpcc_start


初始化测试库环境 :
make命令会在tpcc-mysql目录下生成 tpcc 命令行工具 tpcc_load ,tpcc_start 
tpcc_load  提供初始化数据的功能 
tpcc_start 进行压力测试 


用法:  
# ./tpcc_load --help 
tpcc_load [server] [DB] [user] [pass] [warehouse] 
Server: 服务器名 
DB: 数据库名 
user: 用户名 
pass: 密码 
Warehouse: 仓库的数量 


#./tpcc_start --help 
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 
介绍一下各个参数的用法 
-h server_host: 服务器名 
-P port : 端口号,默认为3306 
-d database_name: 数据库名 
-u mysql_user : 用户名 
-p mysql_password : 密码 
-w warehouses: 仓库的数量 
-c connections : 线程数,默认为1 
-r warmup_time : 热身时间,单位:s,默认为10s ,热身是为了将数据加载到内存。 
-l running_time: 测试时间,单位:s,默认为20s 
-i report_interval: 指定生成报告间隔时长 
-f report_file: 测试结果输出文件 

如果遇到如下错误 则建立一个mysql.sock的软连接到/tmp/mysqld.sock 即可
[root@localhost tpcc-mysql]# ./tpcc_load localhost tpcc root "root" 5
*************************************
*** ###easy### TPC-C Data Loader  ***
*************************************
<Parameters>
     [server]: localhost
     [port]: 3306
     [DBname]: tpcc
       [user]: root
       [pass]: root
  [warehouse]: 5


2002, HY000, Can't connect to local MySQL server through socket '/tmp/mysqld.sock' (2)
注意 

tpcc 默认会读取/var/lib/mysql/mysql.sock或者'/tmp/mysqld.sock' 这个socket位置,如果你的测试环境的mysql socket不在相应路径的话,就需要做个软连接,或者通过TCP/IP的方式连接测试服务器,我的tpcc_mysql是默认寻找'/tmp/mysqld.sock'这个位置的,所以就ln -s /usr/local/mysql/data/mysql.sock  /tmp/mysqld.sock 软连接到了'/tmp/mysqld.sock'
准备工作:           

#mysql -uroot  -p  -e "create database tpcc" # 创建测试用的数据库 
#mysql -uroot -p tpcc < create_table.sql # 创建测试用的表 
#mysql -uroot -p tpcc < add_fkey_idx.sql # 创建FK和索引 

进行测试

使用tpcc_start 进行5个线程的测试,热身时间为120测试时间为300秒 !


  1. # ./tpcc_start -hlocalhost -d tpcc -u root -p "123456" -w 5 -c 5 -r 120 -l 300 - >tpcc-output-log

生成图表

首先写一个脚本获取数据源(mysql高性能第三本 里有讲到这个):


  1. # cat tpcc-output-analyze.sh
  2. #!/bin/sh
  3. TIMESLOT=1
  4. if [ -n "$2" ]
  5. then
  6. TIMESLOT=$2
  7. fi
  8. 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 %3d\n",$1,(aggr/timeslot)) ; cntr=0; aggr=0 } }'
  1. # cat tpcc-output-analyze.sh
  2. #!/bin/sh
  3. TIMESLOT=1
  4. if [ -n "$2" ]
  5. then
  6. TIMESLOT=$2
  7. fi
  8. 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 %3d\n",$1,(aggr/timeslot)) ; cntr=0; aggr=0 } }'

这个脚本就是对 tpcc-output-nobinlog 的第一列与第二列进行运算。


  1. #./tpcc-output-analyze.sh tpcc-output-nobinlog > tpcc-graphic-data.txt

绘图过程:


  1. #cat log.conf
  2. set terminal gif small size 480,360 #指定输出成gif图片,且图片大小为550×25
  3. set output "tcpp.gif" #指定输出gif图片的文件名
  4. set title "MySQL Performance" #图片标题
  5. set style data lines #显示网格
  6. set xlabel "Time/s" #X轴标题
  7. set ylabel "Data" #Y轴标题
  8. set grid #显示网格
  9. plot \
  10. "tpcc-graphic-data.txt" using 1:2 title "Total throughput" with lines #从tpcc-graphic-data.txt文件中读取第一列和第二列作为X轴和Y轴数据,示例名"Total throughput"

  1. #cat log.conf
  2. set terminal gif small size 480,360 #指定输出成gif图片,且图片大小为550×25
  3. set output "tcpp.gif" #指定输出gif图片的文件名
  4. set title "MySQL Performance" #图片标题
  5. set style data lines #显示网格
  6. set xlabel "Time/s" #X轴标题
  7. set ylabel "Data" #Y轴标题
  8. set grid #显示网格
  9. plot \
  10. "tpcc-graphic-data.txt" using 1:2 title "Total throughput" with lines #从tpcc-graphic-data.txt文件中读取第一列和第二列作为X轴和Y轴数据,示例名"Total throughput"

运行生成tcpp.gif


  1. #cat log.conf | gnuplot


示例:

 

 


例如得到文件类似如下:


  1. 11:23 28 15
  2. 11:24 10 7
  3. 11:25 224 37 13
  4. 11:26 470 192
  5. 11:27 344 187 1
  6. 11:28 441 77 2
  7. 11:29 419 8


然后创建gnuplot.conf如下:


  1. set terminal png xFFEEDD size 2048,512
  2. set output "log.png"
  3. set autoscale
  4. set xdata time
  5. set timefmt "%H:%M"
  6. set format x "%H:%M"
  7. set xtics 10
  8. set mxtics 4
  9. set style data lines
  10. set datafile missing "0″
  11. set xlabel "time per day"
  12. set ylabel "purge"
  13. set title "DPD expires"
  14. set grid
  15. plot "log" using 1:2 title "html/min","log" using 1:3 title "js/min","log" using 1:4 title "css/min"


运行cat gnuplot.conf|gnuplot就得到log.png了,如下:


参考文章:

http://raocl.wordpress.com/2010/11/25/inotify-purge%E5%90%8E%E7%BB%AD%E5%88%86%E6%9E%90/

http://www.tuicool.com/articles/zMRF7r


发布了166 篇原创文章 · 获赞 208 · 访问量 132万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章