#!/usr/bin/sysbench require("account_common") -- 初始化数据库 第一个调用的lua函数 function thread_init() print("thread_init ID:" .. thread_id .. " max:" .. sysbench.opt.threads) drv = sysbench.sql.driver() con = drv:connect() end function thread_done() print("thread_done ID:" .. thread_id) con:disconnect() end -- 每个db 1万个账号 local account_map = { } local insert_index = 1; function insert_one_data() local one_thread_count = account_table_max / sysbench.opt.threads; local db_start = thread_id * one_thread_count; local cur_start = (insert_index-1) % one_thread_count + 1; local db_index = db_start + cur_start; -- print("insert_one_data insert_index:" .. insert_index .. " thread_id:" .. thread_id .. " db_index:" .. db_index) insert_index = insert_index + 1; account_map[db_index] = account_map[db_index] or 1; if (account_map[db_index] > 10000) then -- 1万就停止 return end con:query(insert_account_cmd(db_index, account_map[db_index])); account_map[db_index] = account_map[db_index] + 1; end function event() insert_one_data(); end