2019-01-24 20:15:10 +00:00
|
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-09-05 17:10:35 +01:00
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
|
|
package testsuite
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"path"
|
|
|
|
|
"strconv"
|
|
|
|
|
"testing"
|
|
|
|
|
|
2019-08-22 12:40:15 +01:00
|
|
|
|
"golang.org/x/sync/errgroup"
|
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
|
"storj.io/common/testcontext"
|
2018-09-05 17:10:35 +01:00
|
|
|
|
"storj.io/storj/storage"
|
|
|
|
|
)
|
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
|
// RunBenchmarks runs common storage.KeyValueStore benchmarks.
|
2018-09-05 17:10:35 +01:00
|
|
|
|
func RunBenchmarks(b *testing.B, store storage.KeyValueStore) {
|
|
|
|
|
var words = []string{
|
|
|
|
|
"alpha", "beta", "gamma", "delta", "iota", "kappa", "lambda", "mu",
|
|
|
|
|
"άλφα", "βήτα", "γάμμα", "δέλτα", "έψιλον", "ζήτα", "ήτα", "θήτα", "ιώτα", "κάππα", "λάμδα", "μυ",
|
|
|
|
|
"nu", "xi", "omicron", "pi", "rho", "sigma", "tau", "upsilon", "phi", "chi", "psi", "omega",
|
|
|
|
|
"νυ", "ξι", "όμικρον", "πι", "ρώ", "σίγμα", "ταυ", "ύψιλον", "φι", "χι", "ψι", "ωμέγα",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
words = words[:20] // branching factor
|
|
|
|
|
|
|
|
|
|
var items storage.Items
|
|
|
|
|
|
|
|
|
|
k := 0
|
|
|
|
|
for _, a := range words {
|
|
|
|
|
for _, b := range words {
|
|
|
|
|
for _, c := range words {
|
|
|
|
|
items = append(items, storage.ListItem{
|
|
|
|
|
Key: storage.Key(path.Join(a, b, c)),
|
|
|
|
|
Value: storage.Value(strconv.Itoa(k)),
|
|
|
|
|
})
|
|
|
|
|
k++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-24 19:06:22 +01:00
|
|
|
|
ctx := testcontext.New(b)
|
|
|
|
|
defer ctx.Cleanup()
|
2019-12-17 14:16:38 +00:00
|
|
|
|
|
2019-09-24 19:06:22 +01:00
|
|
|
|
defer cleanupItems(b, ctx, store, items)
|
2018-09-05 17:10:35 +01:00
|
|
|
|
|
|
|
|
|
b.Run("Put", func(b *testing.B) {
|
|
|
|
|
b.SetBytes(int64(len(items)))
|
|
|
|
|
for k := 0; k < b.N; k++ {
|
2019-08-22 12:40:15 +01:00
|
|
|
|
var group errgroup.Group
|
2018-09-05 17:10:35 +01:00
|
|
|
|
for _, item := range items {
|
2019-05-06 21:47:12 +01:00
|
|
|
|
key := item.Key
|
|
|
|
|
value := item.Value
|
|
|
|
|
|
2019-08-22 12:40:15 +01:00
|
|
|
|
group.Go(func() error {
|
|
|
|
|
return store.Put(ctx, key, value)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := group.Wait(); err != nil {
|
|
|
|
|
b.Fatalf("Put: %v", err)
|
2018-09-05 17:10:35 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
b.Run("Get", func(b *testing.B) {
|
|
|
|
|
b.SetBytes(int64(len(items)))
|
|
|
|
|
for k := 0; k < b.N; k++ {
|
|
|
|
|
for _, item := range items {
|
2019-06-05 15:23:10 +01:00
|
|
|
|
_, err := store.Get(ctx, item.Key)
|
2018-09-05 17:10:35 +01:00
|
|
|
|
if err != nil {
|
|
|
|
|
b.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
b.Run("ListV2 5", func(b *testing.B) {
|
|
|
|
|
b.SetBytes(int64(len(items)))
|
|
|
|
|
for k := 0; k < b.N; k++ {
|
2019-06-05 15:23:10 +01:00
|
|
|
|
_, _, err := storage.ListV2(ctx, store, storage.ListOptions{
|
2018-09-05 17:10:35 +01:00
|
|
|
|
StartAfter: storage.Key("gamma"),
|
|
|
|
|
Limit: 5,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
b.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|