Skip to content

Commit 2b2a0d9

Browse files
committed
test: add benchmark tests
Added benchmarking 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. Fixes #122
1 parent 31ebde8 commit 2b2a0d9

File tree

3 files changed

+115
-2
lines changed

3 files changed

+115
-2
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ 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

config.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,31 @@ 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+
format = {
49+
{name = "id", type = "unsigned"},
50+
{name = "name", type = "string"},
51+
{name = "arr1", type = "array"},
52+
},
53+
})
54+
s2:create_index('primary', {type = 'tree', unique = true, parts = {1, 'unsigned'}, if_not_exists = true})
55+
s2:create_index('secondary', {id=5, type = 'tree', unique = false, parts = {2, 'string'}, if_not_exists = true})
56+
arr_data = {}
57+
for i = 1,100 do
58+
arr_data[i] = i
59+
end
60+
for i = 1,100000 do
61+
s2:insert{
62+
i,
63+
'test_name',
64+
arr_data,
65+
}
66+
end
67+
4368
--box.schema.user.grant('guest', 'read,write,execute', 'universe')
4469
box.schema.func.create('box.info')
4570
box.schema.func.create('simple_incr')
@@ -49,6 +74,7 @@ box.once("init", function()
4974
box.schema.user.grant('test', 'execute', 'universe')
5075
box.schema.user.grant('test', 'read,write', 'space', 'test')
5176
box.schema.user.grant('test', 'read,write', 'space', 'schematest')
77+
box.schema.user.grant('test', 'read,write', 'space', 'test_perf')
5278
end)
5379

5480
local function simple_incr(a)

tarantool_test.go

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tarantool_test
22

33
import (
44
"fmt"
5+
"github.com/tarantool/go-tarantool/test_helpers"
56
"log"
67
"os"
78
"strings"
@@ -10,7 +11,6 @@ import (
1011
"time"
1112

1213
. "github.com/tarantool/go-tarantool"
13-
"github.com/tarantool/go-tarantool/test_helpers"
1414
"gopkg.in/vmihailenco/msgpack.v2"
1515
)
1616

@@ -104,19 +104,22 @@ func BenchmarkClientSerial(b *testing.B) {
104104

105105
conn, err := Connect(server, opts)
106106
if err != nil {
107+
b.Error(err)
107108
b.Errorf("No connection available")
108109
return
109110
}
110111
defer conn.Close()
111112

112113
_, err = conn.Replace(spaceNo, []interface{}{uint(1111), "hello", "world"})
113114
if err != nil {
115+
b.Error(err)
114116
b.Errorf("No connection available")
115117
}
116118

117119
for i := 0; i < b.N; i++ {
118120
_, err = conn.Select(spaceNo, indexNo, 0, 1, IterEq, []interface{}{uint(1111)})
119121
if err != nil {
122+
b.Error(err)
120123
b.Errorf("No connection available")
121124
}
122125
}
@@ -188,6 +191,7 @@ func BenchmarkClientFutureTyped(b *testing.B) {
188191

189192
_, err = conn.Replace(spaceNo, []interface{}{uint(1111), "hello", "world"})
190193
if err != nil {
194+
b.Error(err)
191195
b.Errorf("No connection available")
192196
}
193197

@@ -221,6 +225,7 @@ func BenchmarkClientFutureParallel(b *testing.B) {
221225

222226
_, err = conn.Replace(spaceNo, []interface{}{uint(1111), "hello", "world"})
223227
if err != nil {
228+
b.Error(err)
224229
b.Errorf("No connection available")
225230
}
226231

@@ -351,13 +356,15 @@ func BenchmarkClientParallelMassive(b *testing.B) {
351356
func BenchmarkClientParallelMassiveUntyped(b *testing.B) {
352357
conn, err := Connect(server, opts)
353358
if err != nil {
354-
b.Errorf("No connection available")
359+
b.Error(err)
360+
//b.Errorf("No connection available")
355361
return
356362
}
357363
defer conn.Close()
358364

359365
_, err = conn.Replace(spaceNo, []interface{}{uint(1111), "hello", "world"})
360366
if err != nil {
367+
b.Error(err)
361368
b.Errorf("No connection available")
362369
}
363370

@@ -385,6 +392,81 @@ func BenchmarkClientParallelMassiveUntyped(b *testing.B) {
385392
close(limit)
386393
}
387394

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

390472
func TestClient(t *testing.T) {

0 commit comments

Comments
 (0)