`
asyty
  • 浏览: 345735 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

super smack使用经验(与sysbench简单比较)

阅读更多

super smack和sysbench都是可以测试数据库性能的简单工具,但是两者有很大的不同,各有所长。相比来说,我觉得super smack更小巧配置上更加灵活,个人使用了下还是可以的,sysbench功能上则更加丰富一些。

 

贴两篇详细的使用介绍,懒得再写,如果看不懂就自己动手试,试不出来就出去撞几次墙再回来试

 

sysbench使用的介绍 http://hi.baidu.com/arongdy/blog/item/f220a5d45616aa0ba18bb70d.html

 

super smack使用介绍 http://blog.csdn.net/historyasamirror/article/details/6539706

 

几个说明:

 

1. 安装super smack需要yacc以及lex支持,安装报错找不到 lex和yacc啊啥的,linux下使用flex及bison代替,先apt-get install bison flex 或类似的命令安装

 

安装过程中提示缺少libmysqlclient.so之类的,装客户端mysql-client就好了,apt-get或者yum一下就完了,如果mysql是源码编译安装的话是自带这个库的

 

2. super smack配置中需要定义min_row,如果数据库中的数据没有达到这个数据量,则执行gen-data进行插入,如果不想使用这个东西,设置成0

 

3. super smack安装完后bin目录下有个gen-data文件,可以使用gen-data脚本生成测试数据,例如

shell> ./gen-data -n 9000 -f %n > words.dat

shell> cp words.dat /usr/share/super-smack //(默认的数据目录是/usr/share/super-smack)

 

或者在执行super-smack时通过-D指定数据目录,不然会出现找不到words.dat的错误提示

 

在words.dat里生成1~9000的自然数,就可以作为测试语句里的字典值,可以随机从中取出来当做查询参数,如下

 

配置文件

dictionary "userid"
{
  type "rand"; // words are retrieved in random order
  source_type "file"; // words come from a file
  source "words.dat"; // file location
}  

query "select_by_userid"
{
  query "select * from user where user_id = '$userid'";
  type "select_index";
  has_result_set "y";
  parsed "y";
} 

 这样就能随机从word.dat中取出整数作为user_id了

 

4. 关于min_row,在测试select/update等定义在query里的语句时,super smack会自动执行一次count(*)操作,用于判断min_row是否符合,这个是写死在super smack源代码的。

 

在这种情况下,如果是测试海量数据,比如几千万,几亿的数据时,是非常痛苦的,没执行一遍都会执行一次count(*),一次count在mysql中可能就需要十几分钟。。。。

 

于是乎,可以修改源代码

 

// 源码中 src/mysql-client.cc 文件中有这么个函数

int Mysql_client::get_table_info(Table& t)
{
  MYSQL_RES* res;
  string query = "select count(*) from ";
  query += t.name;
  if(safe_query(query.c_str(), 0))
    return 1;
  if(!(res = mysql_store_result(&con)))
    die(0, "Error in mysql_store_result()");
  MYSQL_ROW row = mysql_fetch_row(res);
  if(!row)
  {
    mysql_free_result(res);
    die(0, "No results from select count(*) query ");
  }
  t.num_rows = atoi(row[0]);
  mysql_free_result(res);
  return 0;
}

可以将上面的都注释掉 留下一句 t.num_rows = xxxxx;(很大的某个值)或者count(*)改成 count(1)再把min_row设为0

 

或者更直接,找到src目录下parse.cc,将调用get_table_info函数来判断min_row的这些语句注释掉

 

void Table_def::validate_table(string& name)
{
  Client* c = client_pool[client];
  if(!c)
    die(0, "Missing or undefined client in the table section on line %d",
	yylineno);
  Table t;
  bool do_create = 0, do_drop = 0;
  int min_rows_lim = atoi(min_rows.c_str());
  c->connect();
  t.name = name;
/*************直接把这段注释掉****/
  if(c->get_table_info(t))				
    {										
      do_create = 1;					
    }								
  else							
    {								
      if(t.num_rows < min_rows_lim)		
	{							
	  do_drop = 1;					
	  do_create = 1;				
	}							
    }			
/*******************************/
  if(do_drop)
    {
      cout << "Table '" << name <<
	"' does not meet condtions, will be dropped" << endl;
      string query = "drop table ";
      query += name;
      c->safe_query(query.c_str());
    }
	……………其他代码……………

 

与sysbench比较

优点:可以针对某个数据库指定某张表,自定义SQL语句进行测试

缺点:功能简单

 

sysbench:

优点:功能稍微强大,更偏向于整个系统的测试,包括CUP、内存、数据库整体性能等的测试

缺点:不能灵活配置,只支持数据库级别(databases)不支持表级别(table)的测试

 

总结:两个配合起来用比较好,但是嫌看说明麻烦,就自己写代码测吧!

 

 

转载注明源 http://asyty.iteye.com/blog/1487331

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics