storj/storage/testsuite/bench.go
paul cannon 94651921c3 storage/testsuite: pass ctx in to bulk setup methods
to make them cancelable. Also,

* rename BulkDelete->BulkDeleteAll

this leaves room for a new method `BulkDelete(items storage.Items)` that
does a bulk deletion of a specified list of items, as opposed to
deleting _everything_. such a method would be used in the
`cleanupItems()` function found in utils.go, because when individual
deletes are fairly slow, that step takes way too long during tests.

* use BulkDelete method if available

nothing currently provides `BulkDelete(items storage.Items) error`,
but we made use of it with the Bigtable testing and code, and may make
use of it again when adding new kv backends.

* and eliminate the global context in test_iterate.go

Change-Id: I171c7a3818beffbad969b131e98b9bbe3f324bf2
2019-12-10 20:22:08 +00:00

91 lines
2.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package testsuite
import (
"path"
"strconv"
"testing"
"golang.org/x/sync/errgroup"
"storj.io/storj/private/testcontext"
"storj.io/storj/storage"
)
// RunBenchmarks runs common storage.KeyValueStore benchmarks
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++
}
}
}
ctx := testcontext.New(b)
defer ctx.Cleanup()
defer cleanupItems(b, ctx, store, items)
b.Run("Put", func(b *testing.B) {
b.SetBytes(int64(len(items)))
for k := 0; k < b.N; k++ {
var group errgroup.Group
for _, item := range items {
key := item.Key
value := item.Value
group.Go(func() error {
return store.Put(ctx, key, value)
})
}
if err := group.Wait(); err != nil {
b.Fatalf("Put: %v", err)
}
}
})
b.Run("Get", func(b *testing.B) {
b.SetBytes(int64(len(items)))
for k := 0; k < b.N; k++ {
for _, item := range items {
_, err := store.Get(ctx, item.Key)
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++ {
_, _, err := storage.ListV2(ctx, store, storage.ListOptions{
StartAfter: storage.Key("gamma"),
Limit: 5,
})
if err != nil {
b.Fatal(err)
}
}
})
}