Skip to content

Commit a6727ff

Browse files
committed
test: add benchmark tests
Added benchmarks of large Select and Replace. Added a new target in Makefile for running benchmark tests. Added a new space in config.lua for large Select tests. Added a new target to run ab tests for comparing performance between current changes and master. Fixes #122
1 parent 31ebde8 commit a6727ff

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed

Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,23 @@ coverage:
2525
coveralls: coverage
2626
go get github.com/mattn/goveralls
2727
goveralls -coverprofile=$(COVERAGE_FILE) -service=github
28+
29+
.PHONY: bench
30+
bench:
31+
go clean -testcache
32+
go test -bench=. -benchmem -benchtime=1s
33+
34+
.PHONY: ab-perf
35+
ab-perf:
36+
export TNT_CUR_BRANCH=$(git branch --show-current)
37+
go clean -testcache
38+
go test -bench=. -benchmem -benchtime=1s > b.txt
39+
git stash && git fetch && git checkout master
40+
go clean -testcache
41+
go test -bench=. -benchmem -benchtime=1s > a.txt
42+
go get golang.org/x/tools/cmd/benchcmp
43+
benchcmp a.txt b.txt
44+
echo ${TNT_CUR_BRANCH}
45+
git checkout ${TNT_CUR_BRANCH}
46+
git stash pop
47+
unset TNT_CUR_BRANCH

config.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,32 @@ box.once("init", function()
4040
})
4141
st:truncate()
4242

43+
local s2 = box.schema.space.create('test_perf', {
44+
id = 520,
45+
temporary = true,
46+
if_not_exists = true,
47+
field_count = 3,
48+
wal_mode = 'none',
49+
format = {
50+
{name = "id", type = "unsigned"},
51+
{name = "name", type = "string"},
52+
{name = "arr1", type = "array"},
53+
},
54+
})
55+
s2:create_index('primary', {type = 'tree', unique = true, parts = {1, 'unsigned'}, if_not_exists = true})
56+
s2:create_index('secondary', {id = 5, type = 'tree', unique = false, parts = {2, 'string'}, if_not_exists = true})
57+
arr_data = {}
58+
for i = 1,100 do
59+
arr_data[i] = i
60+
end
61+
for i = 1,100000 do
62+
s2:insert{
63+
i,
64+
'test_name',
65+
arr_data,
66+
}
67+
end
68+
4369
--box.schema.user.grant('guest', 'read,write,execute', 'universe')
4470
box.schema.func.create('box.info')
4571
box.schema.func.create('simple_incr')
@@ -49,6 +75,7 @@ box.once("init", function()
4975
box.schema.user.grant('test', 'execute', 'universe')
5076
box.schema.user.grant('test', 'read,write', 'space', 'test')
5177
box.schema.user.grant('test', 'read,write', 'space', 'schematest')
78+
box.schema.user.grant('test', 'read,write', 'space', 'test_perf')
5279
end)
5380

5481
local function simple_incr(a)

tarantool_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,81 @@ func BenchmarkClientParallelMassiveUntyped(b *testing.B) {
385385
close(limit)
386386
}
387387

388+
func BenchmarkConnection_PointSelect(b *testing.B) {
389+
b.StopTimer()
390+
conn, err := Connect(server, opts)
391+
if err != nil {
392+
b.Errorf("No connection available")
393+
return
394+
}
395+
defer conn.Close()
396+
397+
schema := conn.Schema
398+
rSpaceNo, rIndexNo, err := schema.ResolveSpaceIndex("test_perf", "primary")
399+
if err != nil {
400+
b.Errorf("symbolic space and index params not resolved")
401+
}
402+
b.StartTimer()
403+
b.RunParallel(func(pb *testing.PB) {
404+
for pb.Next() {
405+
_, err := conn.Select(rSpaceNo, rIndexNo, 0, 1, IterEq, []interface{}{uint32(1)})
406+
if err != nil {
407+
b.Errorf("No connection available: %s", err)
408+
return
409+
}
410+
}
411+
})
412+
}
413+
414+
func BenchmarkConnection_Replace(b *testing.B) {
415+
b.StopTimer()
416+
conn, err := Connect(server, opts)
417+
if err != nil {
418+
b.Errorf("No connection available")
419+
return
420+
}
421+
defer conn.Close()
422+
spaceNo = 520
423+
424+
b.StartTimer()
425+
b.RunParallel(func(pb *testing.PB) {
426+
for pb.Next() {
427+
_, err := conn.Replace(spaceNo, []interface{}{uint(1), "hello", []interface{}{}})
428+
if err != nil {
429+
b.Log(err)
430+
b.Errorf("No connection available")
431+
}
432+
}
433+
})
434+
}
435+
436+
func BenchmarkConnection_LargeSelect(b *testing.B) {
437+
b.StopTimer()
438+
conn, err := Connect(server, opts)
439+
if err != nil {
440+
b.Errorf("No connection available")
441+
return
442+
}
443+
defer conn.Close()
444+
445+
schema := conn.Schema
446+
rSpaceNo, rIndexNo, err := schema.ResolveSpaceIndex("test_perf", "secondary")
447+
if err != nil {
448+
b.Errorf("symbolic space and index params not resolved")
449+
}
450+
451+
b.StartTimer()
452+
b.RunParallel(func(pb *testing.PB) {
453+
for pb.Next() {
454+
_, err := conn.Select(rSpaceNo, rIndexNo, 0, 10000000, IterEq, []interface{}{"test_name"})
455+
if err != nil {
456+
b.Errorf("No connection available: %s", err)
457+
return
458+
}
459+
}
460+
})
461+
}
462+
388463
///////////////////
389464

390465
func TestClient(t *testing.T) {

0 commit comments

Comments
 (0)