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萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章