测试软件:sysbench-oltp(1)

1、数据库基准测试OLTP,在sysbench 0.5版本中,可使用了lua脚本进行测试,也可以根据业务需求自定义lua脚本进行测试。
2、在测试之前先查看oltp.lua脚本

  1. dofile(pathtest .. "common.lua")
从oltp.lua脚本看,首先就要去执行common.lua脚本。
3、common.lua脚本

  1. function create_insert(table_id)

       local index_name
       local i
       local j
       local query

       if (oltp_secondary) then
         index_name = "KEY xid"
       else
         index_name = "PRIMARY KEY"
       end

       i = table_id

       print("Creating table 'sbtest" .. i .. "'...")
       if ((db_driver == "mysql") or (db_driver == "attachsql")) then
          query = [[
  2. if ((db_driver == "mysql") or (db_driver == "attachsql")) then
  3.       query = [[
  4. CREATE TABLE sbtest]] .. i .. [[ (
  5. id INTEGER UNSIGNED NOT NULL ]] ..
  6. ((oltp_auto_inc and "AUTO_INCREMENT") or "") .. [[,
  7. k INTEGER UNSIGNED DEFAULT '0' NOT NULL,
  8. c CHAR(120) DEFAULT '' NOT NULL,
  9. pad CHAR(60) DEFAULT '' NOT NULL,
  10. ]] .. index_name .. [[ (id)
  11. ) /*! ENGINE = ]] .. mysql_table_engine ..
  12. " MAX_ROWS = " .. myisam_max_rows .. " */ " ..
  13.    (mysql_table_options or "")
我的测试数据库是MySQL,这里就查看MySQL的脚本。
1、创建表sbtest;
2、列id是自增长列,且id列定义为主键;
3、可根据mysql_table_engine自定义存储引擎;
4、可设定myisam_max_rows的最大行数;

  1. db_query("CREATE INDEX k_" .. i .. " on sbtest" .. i .. "(k)")

  2.    print("Inserting " .. oltp_table_size .. " records into 'sbtest" .. i .. "'")

  3.    if (oltp_auto_inc) then
  4.       db_bulk_insert_init("INSERT INTO sbtest" .. i .. "(k, c, pad) VALUES")
  5.    else
  6.       db_bulk_insert_init("INSERT INTO sbtest" .. i .. "(id, k, c, pad) VALUES")
  7.    end

  8.    local c_val
  9.    local pad_val


  10.    for j = 1,oltp_table_size do

  11.    c_val = sb_rand_str([[
  12. ###########-###########-###########-###########-###########-###########-###########-###########-###########-###########]])
  13.    pad_val = sb_rand_str([[
  14. ###########-###########-###########-###########-###########]])

  15.       if (oltp_auto_inc) then
  16.          db_bulk_insert_next("(" .. sb_rand(1, oltp_table_size) .. ", '".. c_val .."', '" .. pad_val .. "')")
  17.       else
  18.          db_bulk_insert_next("("..j.."," .. sb_rand(1, oltp_table_size) .. ",'".. c_val .."', '" .. pad_val .. "' )")
  19.       end
  20.    end

  21.    db_bulk_insert_done()


  22. end
5、在k列上创建索引,且值为oltp_table_size定义的随机值
6、列c和pad为字符型随机值

  1. function prepare()
  2.    local query
  3.    local i
  4.    local j

  5.    set_vars()

  6.    db_connect()


  7.    for i = 1,oltp_tables_count do
  8.      create_insert(i)
  9.    end

  10.    return 0
  11. end

  12. function cleanup()
  13.    local i

  14.    set_vars()

  15.    for i = 1,oltp_tables_count do
  16.    print("Dropping table 'sbtest" .. i .. "'...")
  17.    db_query("DROP TABLE sbtest".. i )
  18.    end
  19. end
7、定义prepare过程中,需设定表oltp_tables_count的数值,默认为1
8、定义cleanup的过程

  1. function set_vars()
  2.    oltp_table_size = oltp_table_size or 10000
  3.    oltp_range_size = oltp_range_size or 100
  4.    oltp_tables_count = oltp_tables_count or 1
  5.    oltp_point_selects = oltp_point_selects or 10
  6.    oltp_simple_ranges = oltp_simple_ranges or 1
  7.    oltp_sum_ranges = oltp_sum_ranges or 1
  8.    oltp_order_ranges = oltp_order_ranges or 1
  9.    oltp_distinct_ranges = oltp_distinct_ranges or 1
  10.    oltp_index_updates = oltp_index_updates or 1
  11.    oltp_non_index_updates = oltp_non_index_updates or 1

  12.    if (oltp_auto_inc == 'off') then
  13.       oltp_auto_inc = false
  14.    else
  15.       oltp_auto_inc = true
  16.    end

  17.    if (oltp_read_only == 'on') then
  18.       oltp_read_only = true
  19.    else
  20.       oltp_read_only = false
  21.    end

  22.    if (oltp_skip_trx == 'on') then
  23.       oltp_skip_trx = true
  24.    else
  25.       oltp_skip_trx = false
  26.    end

  27. end
10、这里是在创建表时设置的参数值,可根据需求自定义。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12219480/viewspace-1758335/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/12219480/viewspace-1758335/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值