add Store Open benchmark test
parent
31bb8e70a9
commit
938ad2ef85
|
@ -10,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
func TestShardWriteAndIndex(t *testing.T) {
|
||||
tmpDir, _ := ioutil.TempDir("", "")
|
||||
tmpDir, _ := ioutil.TempDir("", "shard_test")
|
||||
defer os.RemoveAll(tmpDir)
|
||||
tmpShard := path.Join(tmpDir, "shard")
|
||||
|
||||
|
@ -97,6 +97,11 @@ func BenchmarkWritePoints_ExistingSeries_1M(b *testing.B) {
|
|||
benchmarkWritePointsExistingSeries(b, 320, 5, 5, 1)
|
||||
}
|
||||
|
||||
// benchmarkWritePoints benchmarks writing new series to a shard.
|
||||
// mCnt - measurmeent count
|
||||
// tkCnt - tag key count
|
||||
// tvCnt - tag value count (values per tag)
|
||||
// pntCnt - points per series. # of series = mCnt * (tvCnt ^ tkCnt)
|
||||
func benchmarkWritePoints(b *testing.B, mCnt, tkCnt, tvCnt, pntCnt int) {
|
||||
// Generate test series (measurements + unique tag sets).
|
||||
series := genTestSeries(mCnt, tkCnt, tvCnt)
|
||||
|
@ -117,7 +122,7 @@ func benchmarkWritePoints(b *testing.B, mCnt, tkCnt, tvCnt, pntCnt int) {
|
|||
|
||||
// Run the benchmark loop.
|
||||
for n := 0; n < b.N; n++ {
|
||||
tmpDir, _ := ioutil.TempDir("", "")
|
||||
tmpDir, _ := ioutil.TempDir("", "shard_test")
|
||||
tmpShard := path.Join(tmpDir, "shard")
|
||||
shard := NewShard(index, tmpShard)
|
||||
shard.Open()
|
||||
|
@ -132,6 +137,11 @@ func benchmarkWritePoints(b *testing.B, mCnt, tkCnt, tvCnt, pntCnt int) {
|
|||
}
|
||||
}
|
||||
|
||||
// benchmarkWritePointsExistingSeries benchmarks writing to existing series in a shard.
|
||||
// mCnt - measurmeent count
|
||||
// tkCnt - tag key count
|
||||
// tvCnt - tag value count (values per tag)
|
||||
// pntCnt - points per series. # of series = mCnt * (tvCnt ^ tkCnt)
|
||||
func benchmarkWritePointsExistingSeries(b *testing.B, mCnt, tkCnt, tvCnt, pntCnt int) {
|
||||
// Generate test series (measurements + unique tag sets).
|
||||
series := genTestSeries(mCnt, tkCnt, tvCnt)
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestStoreOpen(t *testing.T) {
|
||||
|
@ -160,3 +161,71 @@ func TestStoreOpenShardBadShardPath(t *testing.T) {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
func BenchmarkStoreOpen_200KSeries_100Shards(b *testing.B) { benchmarkStoreOpen(b, 64, 5, 5, 1, 100) }
|
||||
|
||||
func benchmarkStoreOpen(b *testing.B, mCnt, tkCnt, tvCnt, pntCnt, shardCnt int) {
|
||||
// Generate test series (measurements + unique tag sets).
|
||||
series := genTestSeries(mCnt, tkCnt, tvCnt)
|
||||
// Generate point data to write to the shards.
|
||||
points := []Point{}
|
||||
for _, s := range series {
|
||||
for val := 0.0; val < float64(pntCnt); val++ {
|
||||
p := NewPoint(s.Measurement, s.Series.Tags, map[string]interface{}{"value": val}, time.Now())
|
||||
points = append(points, p)
|
||||
}
|
||||
}
|
||||
// Create a temporary directory for the test data.
|
||||
dir, _ := ioutil.TempDir("", "store_test")
|
||||
// Create the store.
|
||||
store := NewStore(dir)
|
||||
// Open the store.
|
||||
if err := store.Open(); err != nil {
|
||||
b.Fatalf("benchmarkStoreOpen: %s", err)
|
||||
}
|
||||
// Create requested number of shards in the store & write points.
|
||||
for shardID := 0; shardID < shardCnt; shardID++ {
|
||||
if err := store.CreateShard("mydb", "myrp", uint64(shardID)); err != nil {
|
||||
b.Fatalf("benchmarkStoreOpen: %s", err)
|
||||
}
|
||||
// Write points to the shard.
|
||||
chunkedWriteStoreShard(store, shardID, points)
|
||||
}
|
||||
// Close the store.
|
||||
if err := store.Close(); err != nil {
|
||||
b.Fatalf("benchmarkStoreOpen: %s", err)
|
||||
}
|
||||
|
||||
// Run the benchmark loop.
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
store := NewStore(dir)
|
||||
if err := store.Open(); err != nil {
|
||||
b.Fatalf("benchmarkStoreOpen: %s", err)
|
||||
}
|
||||
|
||||
b.StopTimer()
|
||||
store.Close()
|
||||
b.StartTimer()
|
||||
}
|
||||
}
|
||||
|
||||
func chunkedWriteStoreShard(store *Store, shardID int, points []Point) {
|
||||
nPts := len(points)
|
||||
chunkSz := 10000
|
||||
start := 0
|
||||
end := chunkSz
|
||||
|
||||
for {
|
||||
if end > nPts {
|
||||
end = nPts
|
||||
}
|
||||
if end-start == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
store.WriteToShard(uint64(shardID), points[start:end])
|
||||
start = end
|
||||
end += chunkSz
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue