From 9970ded79f068e47415ed42c69f24c0f3af106a8 Mon Sep 17 00:00:00 2001 From: Nikita Vetoshkin Date: Thu, 6 Oct 2016 22:44:25 +0500 Subject: [PATCH] mvcc: add BenchmarkWatchableStoreTxnPut benchmark --- mvcc/watchable_store_bench_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/mvcc/watchable_store_bench_test.go b/mvcc/watchable_store_bench_test.go index b2f0d6bb4..c6eedfe20 100644 --- a/mvcc/watchable_store_bench_test.go +++ b/mvcc/watchable_store_bench_test.go @@ -34,11 +34,37 @@ func BenchmarkWatchableStorePut(b *testing.B) { vals := createBytesSlice(bytesN, b.N) b.ResetTimer() + b.ReportAllocs() for i := 0; i < b.N; i++ { s.Put(keys[i], vals[i], lease.NoLease) } } +// BenchmarkWatchableStoreTxnPut benchmarks the Put operation +// with transaction begin and end, where transaction involves +// some synchronization operations, such as mutex locking. +func BenchmarkWatchableStoreTxnPut(b *testing.B) { + var i fakeConsistentIndex + be, tmpPath := backend.NewDefaultTmpBackend() + s := New(be, &lease.FakeLessor{}, &i) + defer cleanup(s, be, tmpPath) + + // arbitrary number of bytes + bytesN := 64 + keys := createBytesSlice(bytesN, b.N) + vals := createBytesSlice(bytesN, b.N) + + b.ResetTimer() + b.ReportAllocs() + for i := 0; i < b.N; i++ { + id := s.TxnBegin() + if _, err := s.TxnPut(id, keys[i], vals[i], lease.NoLease); err != nil { + plog.Fatalf("txn put error: %v", err) + } + s.TxnEnd(id) + } +} + // BenchmarkWatchableStoreWatchSyncPut benchmarks the case of // many synced watchers receiving a Put notification. func BenchmarkWatchableStoreWatchSyncPut(b *testing.B) {