自定义脚本
require("../oltp_common")math.randomseed(tostring(os.time()):reverse():sub(1, 7))Names = {}Desc = {}--[[线程启动的时候调用]]function thread_init() drv = sysbench.sql.driver() con = drv:connect() -- con:query("set names utf8mb4") -- 这里可以从文件中取出预设好的值,然后随机作为条件查询 -- -- 初始化测试数据,参数 -- -- 初始化人名数据 -- local names = io.open("./name", "r") -- if names ~= nil then -- for line in names:lines() do -- table.insert(Names, line) -- end -- names:close() -- end -- -- 初始化描述 -- local descs = io.open("./desc", "r") -- if descs ~= nil then -- for line in descs:lines() do -- table.insert(Desc, line) -- end -- descs:close() -- endend--[[线程结束的时候调用]]-- function thread_done()-- Con:disconnect()-- -- print(string.format("stop thread %d", sysbench.tid))-- end-- 随机字符串【中文会乱码】function getRandom(n) local t = "电力业务许可证侣昼碴拖瑞旋想讯牢将汗雾力道瘁策愧啥幻迅民稠胯毋贬康讶殃" -- local t = "ewdsadfasdadadadfwefsfasfa" local s = "" for i =1, n do local rand = math.random(1, #t) s = s .. t:sub(rand,rand) end; return send;-- 压测test_companyfunction test_company() -- 随机范围内的数字 local rand_id = math.random(1, 100000000) -- 走覆盖索引 -- con:query(string.format("Select id from test_company where id = %d", rand_id)) -- 回表所有字段 -- con:query(string.format("Select * from test_company where id = %d", rand_id)) -- 回表单字段 con:query(string.format("Select company_code from test_company where id = %d", rand_id))end-- 压测test_jobsfunction test_jobs() -- 随机范围内的数字 local rand_id = math.random(1, 100000000) -- 走覆盖索引 con:query(string.format("Select company_id from test_jobs where id = %d", rand_id)) -- 回表所有字段 -- con:query(string.format("Select * from test_jobs where company_id = %d", rand_id)) -- 回表单字段 -- con:query(string.format("Select job_type from test_jobs where company_id = %d", rand_id))end--[[执行]]function event() -- test_company() test_jobs()end