centos下安裝和使用mysql測試工具super-smack

若是想看super-smack的發展歷史的話,請看:http://mysqldatabaseadministration.blogspot.com/2006/10/mysql-benchmarking-4-compiling-super.htmlhtml

環境介紹:mysql

centos5.4sql

[root@26 super-smack-1.3]# uname -a
Linux 26 2.6.18-164.el5 #1 SMP Thu Sep 3 03:28:30 EDT 2009 x86_64 x86_64 x86_64 GNU/Linuxshell

1.前提步驟數據庫

 

1 yum -y install mysql-devel
2 yum -y install flex
3 yum -y install byacc
4 yum -y install bisoncentos

 

2.安裝super-smack併發

[object Object]

解決辦法:app

修改文件super-smack-1.3/src/query.cc
dom

第193行:
< int len = 0, num_recs = 0;
修改爲:
> long len = 0; int num_recs = 0;
第199,200行
< int str_len = (*i).first.length();
< if((unsigned)p + str_len + 3 *sizeof(int) < (unsigned)p_end )
修改爲:
> long str_len = (*i).first.length();
> if((long)p + str_len + 3 *sizeof(int) < (long)p_end )
第219行
< len = (unsigned)p - (unsigned)buf;
修改爲:
> len = (long)p - (long)buf;
socket

附改造後的文件:

query.rar

3.下面就來看看如何使用吧

測試命令 
  super-smack -d mysql select-key.smack n m 
  其中super-smack近似於一個解釋執行器,解釋執行select-key.smack中的內容,n爲該次測試的併發線程數,m爲每一個線程執行數據庫操做的次數 
  smack文件,近似於一個c源文件,詳細包含如下幾個內容 
  1.client,定義始於毗連用到的參量,包孕host,user,passwd,port,socket。包孕兩種client,admin client和普通client,admin須要具備辦理職權範圍,須要始於表以及load數據等操做 
  2.表定義,自定義測試表的表結構,須要指定由哪一個client始於表,以及表的記載數,以及填充數據文件的位置,若是數據文件不存在,須要天生數據文件,能夠自定義數據天生劇本 
  3.dictionary,定義了一批可選的字段,源碼實現患上比較簡略,只供給了幾種next要領,讀取下一行數據,若是改行數據用逗點分隔,只取第一個逗點前的字段,其餘符號分隔則取整行數據。因此若是一個查詢裏有幾個字段須要從外部獲取數據,就應該始於幾個dictionary 
  4.查詢,能夠自定義查詢的語句,查詢類型(主要用於分類計數的做用),查詢語句也能夠爲更新操做,如update。若是是查詢語句,has_result_set選項應該定義爲y,不然會出現Commands out of sync錯誤,感受這裏是super-smack的一個bug 
  5.main,測試運行的入口,通常改動不大,主要是一些client名稱的改動 
  測試歷程中始於的毗連數包含: 
  1.表數據分析毗連(select count(*) from test_table),判斷表是否是已經裝載了數據 
  2.線程數,每一個線程執行的查詢都只打開一個毗連,與執行的次數以及每一個線程執行的幾多條語句無關

咱們到安裝路徑看下,

[root@sunss-26 ~]# ll /usr/local/super-smack/bin/
gen-data     super-smack

有連個命令,從名字咱們就能夠看出gen-data是用來生成測試數據的,咱們使用幫助命令看下:

[root@sunss-26 ~]# gen-data --help
gen-data version 1.1 
MySQL AB, by Sasha Pachev
Prints lines random data to stdout in given format
Usage: gen-data [options]
-?, --help - this message
-V, --version - show version
-n, --num-rows=num - number of rows
-f, --format=fmt_str - format string
Format can contain any character + % followed by
a format specifier. Valid format specifiers: 
 s - string 
 d - integer

Additionally, you can prefix a format speficier with: 
 n - generate exactly n characters 
 m-n - generate between m and n  characters

命令及參數都簡單易懂:

-n選項:指定生成數據行的行數

-f選項:指定格式字符串

例如:

gen-data -n 90000 -f %12-12s%n,%25-25s,%n,%d>words.data
[root@sunss-26 ~]# super-smack --help
super-smack version 1.1 
MySQL AB, by Sasha Pachev and Jeremy Cole
Runs multi-threaded benchmarks on database engines.

The following engines are supported:

Id      Handle          Name            Version         Author
--      ------          ----            -------         ------
1       mysql           MySQL           1.0             Sasha Pachev

Usage: super-smack [options] [smack_source]
Valid options are:  -h, --help               Display this message
  -V, --version            Show version
  -d, --db-type=handle     Select database type
  -D, --datadir=path       Path to super-smack datadir

[root@sunss-26 ~]#

如今命令所在路徑是:/usr/local/super-smack/bin/super-smack,若是不想輸入路徑的話,添加一個鏈接:

ln -s /usr/local/super-smack/bin/super-smack /usr/bin/super-smack

咱們在數據庫裏建一個表:

複製代碼

1 CREATE TABLE `http_auth` (
2  `username` char(255) NOT NULL,
3  `pass` char(25) DEFAULT NULL,
4  `uid` int(11) DEFAULT NULL,
5  `gid` int(11) DEFAULT NULL,
6  PRIMARY KEY (`username`)
7 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;

複製代碼

導入數據:

1.mysqlimport -L -usmack -psmack -h192.168.0.26 smack /var/smack-data/http_auth.dat

2.在mysql命令行,執行 Loading data from file '/var/smack-data/http_auth.dat' into table 'http_auth' terminated by ','

測試結果

輸出的結果較爲簡略,只包含了查詢的次數,最大耗時,最小耗時,每秒執行的查詢,會按照查詢類型進行分類計數以後輸出

附修改後的select-key.smack文件:


複製代碼

1 // this is will be used in the table section
2 client "admin"
3 {
4 user "root";
5 host "192.168.0.24";
6 db "test";
7 pass "123456";
8 port "3306";
9  // socket "/tmp/mysql.sock"; // this only applies to MySQL and is
10  // ignored for PostgreSQL
11 }
12
13 // ensure the table exists and meets the conditions
14 table "http_auth"
15 {
16  client "admin"; // connect with this client
17 // if the table is not found or does not pass the checks, create it
18 // with the following, dropping the old one if needed
19  create "create table http_auth
20    (username char(25) not null primary key,
21     pass char(25),
22     uid integer not null,
23     gid integer not null
24    )";
25  min_rows "90000"; // the table must have at least that many rows
26  data_file "words.dat"; // if the table is empty, load the data from
27 //this file
28  gen_data_file "gen-data -n 90000 -f %12-12s%n,%25-25s,%n,%d";
29 // if the file above does not exist, generate it with the above shell command
30 // you can replace this command with anything that prints comma-delimited
31 // data to stdout, just make sure you have the right number of columns
32 }
33
34
35 //define a dictionary
36 dictionary "word"
37 {
38  type "rand"; // words are retrieved in random order
39  source_type "file"; // words come from a file
40  source "words.dat"; // file location
41  delim ","; // take the part of the line before ,
42  file_size_equiv "45000"; // if the file is greater than this
43 //divive the real file size by this value obtaining N and take every Nth
44 //line skipping others. This is needed to be able to target a wide key
45 // range without using up too much memory with test keys
46 }
47
48 //define a query
49 query "select_by_username"
50 {
51  query "select * from http_auth where username = '$word'";
52 // $word will be substitute with the read from the 'word' dictionary
53  type "select_index";
54 // query stats will be grouped by type
55  has_result_set "y";
56 // the query is expected to return a result set
57  parsed "y";
58 // the query string should be first processed by super-smack to do
59 // dictionary substitution
60 }
61
62 // define database client type
63 client "smacker1"
64 {
65 user "root"; // connect as this user
66 pass "123456"; // use this password
67 host "192.168.0.24"; // connect to this host
68 db "test"; // switch to this database
69 port "3306";
70 // socket "/tmp/mysql.sock"; // this only applies to MySQL and is
71 // ignored for PostgreSQL
72 query_barrel "2 select_by_username"; // on each round,
73 // run select_by_username query 2 times
74 }
75
76 main
77 {
78  smacker1.init(); // initialize the client
79  smacker1.set_num_rounds($2); // second arg on the command line defines
80 // the number of rounds for each client
81  smacker1.create_threads($1);
82 // first argument on the command line defines how many client instances
83 // to fork. Anything after this will be done once for each client until
84 // you collect the threads
85  smacker1.connect();
86 // you must connect after you fork
87  smacker1.unload_query_barrel(); // for each client fire the query barrel
88 // it will now do the number of rounds specified by set_num_rounds()
89 // on each round, query_barrel of the client is executed
90
91  smacker1.collect_threads();
92 // the master thread waits for the children, each child reports the stats
93 // the stats are printed
94  smacker1.disconnect();
95 // the children now disconnect and exit
96 }
97

複製代碼

相關文章
相關標籤/搜索