Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add benching tests & fix ClientErrors retry #78

Merged
merged 7 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,21 @@ Learn with th [Quick Start](docs/doc.md), which include examples and theory.
Service with go-vshard-router on top of the tarantool example from the original vshard library using raft

## Benchmarks
Topology:
### Go Bench

| Benchmark | Runs | Time (ns/op) | Memory (B/op) | Allocations (allocs/op) |
|-------------------------------------|--------|---------------|----------------|--------------------------|
| BenchmarkCallSimpleInsert_GO-8 | 9844 | 114596 | 1894 | 41 |
| BenchmarkCallSimpleInsert_Lua-8 | 7587 | 156181 | 1101 | 19 |
| BenchmarkCallSimpleSelect_GO-8 | 16350 | 75770 | 2827 | 60 |
| BenchmarkCallSimpleSelect_Lua-8 | 10060 | 116768 | 1610 | 28 |


### [K6](https://github.com/grafana/k6)
Topology:
- 4 replicasets (x2 instances per rs)
- 4 tarantool proxy
- 1 golang service
### [K6](https://github.com/grafana/k6)

constant VUes scenario:
at a load close to production
Expand Down
12 changes: 11 additions & 1 deletion README_ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,22 @@ func main() {
Сервис с go-vshard-router поверх примера тарантула из оригинальной библиотеки vshard с использованием raft.

## Бенчмарки
### Go Bench

| Бенчмарк | Запусков | Время (ns/op) | Память (B/op) | Аллокации (allocs/op) |
|----------------------------------------|----------|----------------|----------------|------------------------|
| BenchmarkCallSimpleInsert_GO-8 | 9844 | 114596 | 1894 | 41 |
| BenchmarkCallSimpleInsert_Lua-8 | 7587 | 156181 | 1101 | 19 |
| BenchmarkCallSimpleSelect_GO-8 | 16350 | 75770 | 2827 | 60 |
| BenchmarkCallSimpleSelect_Lua-8 | 10060 | 116768 | 1610 | 28 |


### [K6](https://github.com/grafana/k6)

Топология:
- 4 репликасета (x2 инстанса на репликасет)
- 4 тарантул прокси
- 1 инстанс гошного сервиса
### [K6](https://github.com/grafana/k6)

сценарий constant VUes:
в нагрузке близкой к продовой
Expand Down
8 changes: 8 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ func (r *Router) RouterCallImpl(ctx context.Context,
r.BucketReset(bucketID)
r.metrics().RetryOnCall("bucket_migrate")

r.log().Debugf(ctx, "retrying cause bucket in migrate state (%s)", vshardErr.Name)

continue
}

Expand Down Expand Up @@ -209,6 +211,12 @@ func (r *Router) RouterCallImpl(ctx context.Context,
err = errorResp
}

if errorResp.Type == "ClientError" || errorResp.Type == "LuajitError" {
return nil, nil, errorResp
}

r.log().Debugf(ctx, "retry cause vhsard response not ok: %s", errorResp)

continue
}

Expand Down
11 changes: 11 additions & 0 deletions tests/tnt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ cluster-down:
kill -9 `cat tmp/$${rsid}/follower/tarantool.pid`; \
((rsid = rsid + 1)) ; \
done
kill -9 `cat tmp/router_work_dir/router.pid`
rm -rf tmp

# run go tests, minus "-" signs before command allows failures, otherwise cluster-down stage won't run.
gotest:
Expand All @@ -67,3 +69,12 @@ gotest:

open-coverage:
go tool cover -html=cover.out

enter:
tarantoolctl connect storage:storage@0.0.0.0:33002

enter-proxy:
tarantoolctl connect 0.0.0.0:12000

bench:
go test -bench=. -benchmem
221 changes: 221 additions & 0 deletions tests/tnt/call_bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
package tnt

import (
"context"
"testing"
"time"

vshardrouter "github.com/KaymeKaydex/go-vshard-router"
"github.com/KaymeKaydex/go-vshard-router/providers/static"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
"github.com/tarantool/go-tarantool/v2"
"github.com/tarantool/go-tarantool/v2/pool"
)

type Product struct {
BucketID uint64 `msgpack:"bucket_id"`
ID string `msgpack:"id"`
Name string `msgpack:"name"`
Count uint64 `msgpack:"count"`
}

func BenchmarkCallSimpleInsert_GO(b *testing.B) {
b.StopTimer()
skipOnInvalidRun(b)

ctx := context.Background()

cfg := getCfg()

router, err := vshardrouter.NewRouter(ctx, vshardrouter.Config{
TopologyProvider: static.NewProvider(cfg),
DiscoveryTimeout: 5 * time.Second,
DiscoveryMode: vshardrouter.DiscoveryModeOn,
TotalBucketCount: totalBucketCount,
User: defaultTntUser,
Password: defaultTntPassword,
})
require.NoError(b, err)

b.StartTimer()
for i := 0; i < b.N; i++ {
id := uuid.New()

bucketID := router.RouterBucketIDStrCRC32(id.String())
_, _, err := router.RouterCallImpl(
ctx,
bucketID,
vshardrouter.CallOpts{VshardMode: vshardrouter.WriteMode, PoolMode: pool.RW, Timeout: time.Second},
"product_add",
[]interface{}{&Product{Name: "test-go", BucketID: bucketID, ID: id.String(), Count: 3}})
require.NoError(b, err)
}

b.ReportAllocs()
}

func BenchmarkCallSimpleInsert_Lua(b *testing.B) {
b.StopTimer()

skipOnInvalidRun(b)

ctx := context.Background()
dialer := tarantool.NetDialer{
Address: "0.0.0.0:12000",
}

instances := []pool.Instance{{
Name: "router",
Dialer: dialer,
}}

p, err := pool.Connect(ctx, instances)
require.NoError(b, err)
require.NotNil(b, p)

b.StartTimer()
for i := 0; i < b.N; i++ {
id := uuid.New()
req := tarantool.NewCallRequest("api.add_product").
Context(ctx).
Args([]interface{}{&Product{Name: "test-lua", ID: id.String(), Count: 3}})

feature := p.Do(req, pool.ANY)
faces, err := feature.Get()

require.NoError(b, err)
require.NotNil(b, faces)
}

b.ReportAllocs()
}

func BenchmarkCallSimpleSelect_GO(b *testing.B) {
b.StopTimer()
skipOnInvalidRun(b)

ctx := context.Background()

cfg := getCfg()

router, err := vshardrouter.NewRouter(ctx, vshardrouter.Config{
TopologyProvider: static.NewProvider(cfg),
DiscoveryTimeout: 5 * time.Second,
DiscoveryMode: vshardrouter.DiscoveryModeOn,
TotalBucketCount: totalBucketCount,
User: defaultTntUser,
Password: defaultTntPassword,
})
require.NoError(b, err)

ids := make([]uuid.UUID, b.N)

for i := 0; i < b.N; i++ {
id := uuid.New()
ids[i] = id

bucketID := router.RouterBucketIDStrCRC32(id.String())
_, _, err := router.RouterCallImpl(
ctx,
bucketID,
vshardrouter.CallOpts{VshardMode: vshardrouter.WriteMode, PoolMode: pool.RW},
"product_add",
[]interface{}{&Product{Name: "test-go", BucketID: bucketID, ID: id.String(), Count: 3}})
require.NoError(b, err)
}

type Request struct {
ID string `msgpack:"id"`
}

b.StartTimer()
for i := 0; i < b.N; i++ {
id := ids[i]

bucketID := router.RouterBucketIDStrCRC32(id.String())
faces, _, err := router.RouterCallImpl(
ctx,
bucketID,
vshardrouter.CallOpts{VshardMode: vshardrouter.ReadMode, PoolMode: pool.ANY, Timeout: time.Second},
"product_get",
[]interface{}{&Request{ID: id.String()}})
b.StopTimer()
require.NoError(b, err)
require.NotEmpty(b, faces)
b.StartTimer()
}

b.ReportAllocs()
}

func BenchmarkCallSimpleSelect_Lua(b *testing.B) {
b.StopTimer()
skipOnInvalidRun(b)

ctx := context.Background()

cfg := getCfg()

router, err := vshardrouter.NewRouter(ctx, vshardrouter.Config{
TopologyProvider: static.NewProvider(cfg),
DiscoveryTimeout: 5 * time.Second,
DiscoveryMode: vshardrouter.DiscoveryModeOn,
TotalBucketCount: totalBucketCount,
User: defaultTntUser,
Password: defaultTntPassword,
})
require.NoError(b, err)

ids := make([]uuid.UUID, b.N)

for i := 0; i < b.N; i++ {
id := uuid.New()
ids[i] = id

bucketID := router.RouterBucketIDStrCRC32(id.String())
_, _, err := router.RouterCallImpl(
ctx,
bucketID,
vshardrouter.CallOpts{VshardMode: vshardrouter.WriteMode, PoolMode: pool.RW},
"product_add",
[]interface{}{&Product{Name: "test-go", BucketID: bucketID, ID: id.String(), Count: 3}})
require.NoError(b, err)
}

type Request struct {
ID string `msgpack:"id"`
}

dialer := tarantool.NetDialer{
Address: "0.0.0.0:12000",
}

instances := []pool.Instance{{
Name: "router",
Dialer: dialer,
}}

p, err := pool.Connect(ctx, instances)
require.NoError(b, err)
require.NotNil(b, p)

b.StartTimer()
for i := 0; i < b.N; i++ {
id := ids[i]

req := tarantool.NewCallRequest("api.get_product").
Context(ctx).
Args([]interface{}{&Request{ID: id.String()}})

feature := p.Do(req, pool.ANY)
faces, err := feature.Get()

b.StopTimer()
require.NoError(b, err)
require.NotNil(b, faces)
b.StartTimer()
}

b.ReportAllocs()
}
26 changes: 25 additions & 1 deletion tests/tnt/router.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,32 @@ local clustercfg = cfgmaker.clustercfg(start_port, nreplicasets)

clustercfg['bucket_count'] = 100

clustercfg.listen = "0.0.0.0:12000"
clustercfg.background = true
clustercfg.log="router"..".log"
clustercfg.pid_file="router"..".pid"

local router = vshard.router.new('router', clustercfg)

box.once('access:v1', function()
box.schema.user.grant('guest', 'read,write,execute', 'universe')
end)

router:bootstrap({timeout = 4, if_not_bootstrapped = true})

os.exit(0)
local api = {}

function api.add_product(product)
local bucket_id = router:bucket_id_strcrc32(product.id)
product.bucket_id = bucket_id

return router:call(bucket_id, 'write', 'product_add', {product})
end

function api.get_product(req)
local bucket_id = router:bucket_id_strcrc32(req.id)

return router:call(bucket_id, 'read', 'product_get', {req})
end

rawset(_G, 'api', api)
Loading
Loading