Skip to content

Commit

Permalink
feat: adds simple benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladislav Grubov committed Jul 20, 2024
1 parent f3699a5 commit 0b4f318
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 0 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,43 @@ box.space.myqueue:put({ name="xxx"; data="yyy"; }, { delay = 1.5; ttl = 100 })
| S -> D | Task was moved from another tube to be Done |
| S -> B | Task was moved from another tube to be Buried |

## Benchmarks

```bash
❯ .rocks/bin/luabench -d 1000000x
Tarantool version: Tarantool 2.10.7-0-g60f7e18
Tarantool build: Darwin-arm64-RelWithDebInfo (static)
Tarantool build flags: -Wno-unknown-pragmas -fexceptions -funwind-tables -fno-common -Wformat -Wformat-security -Werror=format-security -fstack-protector-strong -fPIC -fmacro-prefix-map=/var/folders/8x/1m5v3n6d4mn62g9w_65vvt_r0000gn/T/tarantool_install1565297302=. -std=c11 -Wall -Wextra -Wno-strict-aliasing -Wno-char-subscripts -Wno-gnu-alignof-expression -Wno-cast-function-type
CPU: Apple M1 @ 8
JIT: Enabled
JIT: fold cse dce fwd dse narrow loop abc sink fuse
Duration: 1000000 iters
--- BENCH: 001_put_take_bench::bench_producer:producer-1
1000000 44046 ns/op 22703 op/s 4137 B/op +3946.04MB
--- BENCH: 001_put_take_bench::bench_producer:producer-2
1000000 27519 ns/op 36339 op/s 4282 B/op +4084.35MB
--- BENCH: 001_put_take_bench::bench_producer:producer-4
1000000 21510 ns/op 46491 op/s 4500 B/op +4291.69MB
--- BENCH: 001_put_take_bench::bench_producer:producer-8
1000000 20804 ns/op 48068 op/s 4379 B/op +4176.26MB
--- BENCH: 001_put_take_bench::bench_producer:producer-12
1000000 20383 ns/op 49062 op/s 4372 B/op +4169.59MB
--- BENCH: 001_put_take_bench::bench_producer:producer-16
1000000 21495 ns/op 46523 op/s 4215 B/op +4019.98MB
--- BENCH: 001_put_take_bench::bench_producer:producer-20
1000000 23676 ns/op 42238 op/s 4258 B/op +4061.49MB
--- BENCH: 001_put_take_bench::bench_producer:producer-24
1000000 24456 ns/op 40891 op/s 4274 B/op +4076.65MB
```

## TODO

* reload/upgrade and feature switch
Expand Down
103 changes: 103 additions & 0 deletions benchmarks/001_put_take_bench.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
local lb = require 'luabench'
local fiber = require 'fiber'
local log = require 'log'
local fun = require 'fun'

local xqueue = require 'xqueue'

box.cfg{ memtx_memory = 2^30, log_level = 4 }
box.schema.space.create('queue', {
if_not_exists = true,
format = {
{ name = 'id', type = 'unsigned' },
{ name = 'status', type = 'string' },
},
})
box.space.queue:create_index('primary', { parts = {'id'}, if_not_exists = true })
box.space.queue:create_index('xq', { parts = {'status', 'id'}, if_not_exists = true })

xqueue.upgrade(box.space.queue, {
fields = {
id = 'id',
status = 'status',
},
features = {
id = 'time64',
keep = false,
delayed = false,
buried = false,
retval = 'tuple',
zombie = false,
ttl = false,
ttr = false,
},
debug = false,
workers = 32,
worker = function(task)
-- pass (auto-ack)
end
})

local queue = box.space.queue --[[@as xqueue.space]]
lb.before_all(function() queue:truncate() end)

local M = {}

local function new_producer_bench_f(num)
local start = fiber.cond()
local limit = 0
local produced = 0

local done = fiber.channel()

for _ = 1, num do
fiber.create(function()
while true do
start:wait()

local empty_tab = {}
while produced < limit do
produced = produced + 1
local ok, err = pcall(queue.put, queue, empty_tab)
if not ok then
log.error(":put() => %s", err)
end
end

-- await everything
while queue:len() > 0 do
for _, task in queue.index.xq:pairs() do
queue:wait(task, 0.1)
end
end

done:put(true)
end
end)
end

---@param sb luabench.B
return function(sb)
limit = sb.N
produced = 0
start:broadcast()

for _ = 1, num do
done:get() -- await all producers to finish
end
end
end

---@param b luabench.B
function M.bench_producer_await(b)
b:run('producer-1', new_producer_bench_f(1))
b:run('producer-2', new_producer_bench_f(2))
b:run('producer-4', new_producer_bench_f(4))
b:run('producer-8', new_producer_bench_f(8))
b:run('producer-12', new_producer_bench_f(12))
b:run('producer-16', new_producer_bench_f(16))
b:run('producer-20', new_producer_bench_f(20))
b:run('producer-24', new_producer_bench_f(24))
end

return M

0 comments on commit 0b4f318

Please sign in to comment.