Skip to content
Snippets Groups Projects
Commit ad830605 authored by Valentin Syrovatskiy's avatar Valentin Syrovatskiy
Browse files

test: benchmark replaces

parent 6379a7e5
No related branches found
No related tags found
No related merge requests found
Pipeline #12250 failed
.PHONY: default fmt lint test check fat clean
.PHONY: default fmt lint test check fat clean benchmark
default: ;
......@@ -57,3 +57,6 @@ clean:
cargo clean || true
git submodule foreach --recursive 'git clean -dxf && git reset --hard'
find . -type d -name __pycache__ | xargs -n 500 rm -rf
benchmark:
pytest test/manual/test_benchmark.py
......@@ -12,6 +12,7 @@ tarantool = "*"
funcy = "*"
mypy = "*"
pytest-clarity = "*"
prettytable = "*"
[requires]
python_version = "3.10"
......
This diff is collapsed.
from this import d
from conftest import Cluster
import json
from prettytable import PrettyTable
def test_benchmark_replace(cluster: Cluster, capsys):
cluster.deploy(instance_count=1)
[i1] = cluster.instances
luacode_init = """
box.schema.space.create('bench', {
if_not_exists = true,
is_local = true,
format = {
{name = 'id', type = 'unsigned', is_nullable = false},
{name = 'value', type = 'unsigned', is_nullable = false}
}
})
box.space.bench:create_index('pk', {
if_not_exists = true,
parts = {{'id'}}
})
clock=require('clock')
fiber=require('fiber')
json=require('json')
function f(n)
for i=1, n do
box.space.bench:replace({1, i})
end
end
function benchmark_replace(n, c)
local fibers = {};
local t1 = clock.monotonic();
for i=1, c do
fibers[i] = fiber.new(f, 1e5)
fibers[i]:set_joinable(true)
end;
for i=1, c do
fibers[i]:join()
end
local t2 = clock.monotonic();
local result = {c=c, nc = n*c, time = t2-t1, rps = n*c/(t2-t1)}
return json.encode(result)
end
"""
i1.assert_raft_status("Leader")
i1.eval(luacode_init)
def b(n: int, c: int):
data = i1.eval("return benchmark_replace(...)", n, c, timeout=60)
return json.loads(data)
def b_retr(n: int, c: int):
return list(map(lambda _: b(n, c), range(0, 4)))
def benchmark():
stats = []
fibers = [1, 2, 3, 5, 10, 50]
for c in fibers:
result = b_retr(100000, c)
key = {"fibers": c}
stats.append((key, result))
return stats
def rps(stat):
return list(map(lambda s: s["rps"], stat))
def avg(x):
return sum(x) / len(x)
def remove_min(x: list):
min_value = min(x)
return list(filter(lambda v: v != min_value, x))
def report(stats):
t = PrettyTable()
t.field_names = ["fibers", "rps"]
for (key, stat) in stats:
t.add_row([key["fibers"], int(avg(remove_min(rps(stat))))])
t.align = "r"
return t
with capsys.disabled():
print(report(benchmark()))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment