From ad327e01d04ef6ac78b98e16988ae803f7a81329 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Fri, 29 Apr 2016 19:58:37 -0700 Subject: [PATCH] mvcc: add benchmark for watch put and improve it --- mvcc/kvstore.go | 2 +- mvcc/watchable_store_bench_test.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/mvcc/kvstore.go b/mvcc/kvstore.go index d960d0ada..3ea286ca0 100644 --- a/mvcc/kvstore.go +++ b/mvcc/kvstore.go @@ -580,7 +580,7 @@ func (s *store) delete(key []byte, rev revision) { func (s *store) getChanges() []mvccpb.KeyValue { changes := s.changes - s.changes = make([]mvccpb.KeyValue, 0, 128) + s.changes = make([]mvccpb.KeyValue, 0, 4) return changes } diff --git a/mvcc/watchable_store_bench_test.go b/mvcc/watchable_store_bench_test.go index 605e01d0f..b659b6d0f 100644 --- a/mvcc/watchable_store_bench_test.go +++ b/mvcc/watchable_store_bench_test.go @@ -23,6 +23,22 @@ import ( "github.com/coreos/etcd/mvcc/backend" ) +func BenchmarkWatchableStorePut(b *testing.B) { + be, tmpPath := backend.NewDefaultTmpBackend() + s := New(be, &lease.FakeLessor{}, nil) + defer cleanup(s, be, tmpPath) + + // arbitrary number of bytes + bytesN := 64 + keys := createBytesSlice(bytesN, b.N) + vals := createBytesSlice(bytesN, b.N) + + b.ResetTimer() + for i := 0; i < b.N; i++ { + s.Put(keys[i], vals[i], lease.NoLease) + } +} + // Benchmarks on cancel function performance for unsynced watchers // in a WatchableStore. It creates k*N watchers to populate unsynced // with a reasonably large number of watchers. And measures the time it