|
| 1 | +local lb = require 'luabench' |
| 2 | +local fiber = require 'fiber' |
| 3 | +local fun = require 'fun' |
| 4 | + |
| 5 | +local M = {} |
| 6 | + |
| 7 | +local STATUS = { 'R', 'T', 'W', 'B', 'Z', 'D' } |
| 8 | + |
| 9 | +lb.before_all(function() |
| 10 | + box.cfg{ memtx_memory = 2^30 } |
| 11 | + |
| 12 | + box.schema.space.create('q1', { |
| 13 | + if_not_exists = true, |
| 14 | + format = { |
| 15 | + { name = 'id', type = 'unsigned' }, |
| 16 | + { name = 'status', type = 'string' }, |
| 17 | + }, |
| 18 | + }) |
| 19 | + |
| 20 | + box.space.q1:create_index('primary', { parts = {'id'}, if_not_exists = true }) |
| 21 | + box.space.q1:create_index('xq', { parts = {'status', 'id'}, if_not_exists = true }) |
| 22 | + |
| 23 | + if fiber.extend_slice then |
| 24 | + fiber.extend_slice({ err = 3600, warn = 3600 }) |
| 25 | + end |
| 26 | + |
| 27 | + box.begin() |
| 28 | + local tab = {} |
| 29 | + for no = 1, 4e6 do |
| 30 | + tab[1], tab[2] = no, STATUS[math.random(#STATUS)] |
| 31 | + box.space.q1:replace(tab) |
| 32 | + end |
| 33 | + box.commit() |
| 34 | +end) |
| 35 | + |
| 36 | +lb.after_all(function() |
| 37 | + box.space.q1:drop() |
| 38 | + box.snapshot() |
| 39 | +end) |
| 40 | + |
| 41 | +function M.bench_iterate_all(b) |
| 42 | + local limit = b.N |
| 43 | + local scanned = 0 |
| 44 | + local stats = {} |
| 45 | + for _, t in box.space.q1:pairs({}, { iterator = "ALL" }) do |
| 46 | + stats[t.status] = (stats[t.status] or 0ULL) + 1 |
| 47 | + scanned = scanned + 1 |
| 48 | + if limit == scanned then break end |
| 49 | + end |
| 50 | + b.N = scanned |
| 51 | +end |
| 52 | + |
| 53 | +function M.bench_count(b) |
| 54 | + local total = 0 |
| 55 | + for _, s in pairs(STATUS) do |
| 56 | + total = total + box.space.q1.index.xq:count(s) |
| 57 | + if b.N < total then break end |
| 58 | + end |
| 59 | + b.N = total |
| 60 | +end |
| 61 | + |
| 62 | +return M |
0 commit comments