|
@@ -28,9 +28,6 @@ import (
|
|
|
// TODO: k is an arbitrary constant. We need to figure out what factor
|
|
// TODO: k is an arbitrary constant. We need to figure out what factor
|
|
|
// we should put to simulate the real-world use cases.
|
|
// we should put to simulate the real-world use cases.
|
|
|
func BenchmarkWatchableStoreUnsyncedCancel(b *testing.B) {
|
|
func BenchmarkWatchableStoreUnsyncedCancel(b *testing.B) {
|
|
|
- const k int = 2
|
|
|
|
|
- benchSampleSize := b.N
|
|
|
|
|
- watcherSize := k * benchSampleSize
|
|
|
|
|
// manually create watchableStore instead of newWatchableStore
|
|
// manually create watchableStore instead of newWatchableStore
|
|
|
// because newWatchableStore periodically calls syncWatchersLoop
|
|
// because newWatchableStore periodically calls syncWatchersLoop
|
|
|
// method to sync watchers in unsynced map. We want to keep watchers
|
|
// method to sync watchers in unsynced map. We want to keep watchers
|
|
@@ -39,9 +36,6 @@ func BenchmarkWatchableStoreUnsyncedCancel(b *testing.B) {
|
|
|
store: newStore(tmpPath),
|
|
store: newStore(tmpPath),
|
|
|
unsynced: make(map[*watching]struct{}),
|
|
unsynced: make(map[*watching]struct{}),
|
|
|
|
|
|
|
|
- // For previous implementation, use:
|
|
|
|
|
- // unsynced: make([]*watching, 0),
|
|
|
|
|
-
|
|
|
|
|
// to make the test not crash from assigning to nil map.
|
|
// to make the test not crash from assigning to nil map.
|
|
|
// 'synced' doesn't get populated in this test.
|
|
// 'synced' doesn't get populated in this test.
|
|
|
synced: make(map[string]map[*watching]struct{}),
|
|
synced: make(map[string]map[*watching]struct{}),
|
|
@@ -62,8 +56,12 @@ func BenchmarkWatchableStoreUnsyncedCancel(b *testing.B) {
|
|
|
|
|
|
|
|
w := s.NewWatcher()
|
|
w := s.NewWatcher()
|
|
|
|
|
|
|
|
- cancels := make([]CancelFunc, watcherSize)
|
|
|
|
|
- for i := 0; i < watcherSize; i++ {
|
|
|
|
|
|
|
+ const k int = 2
|
|
|
|
|
+ benchSampleN := b.N
|
|
|
|
|
+ watcherN := k * benchSampleN
|
|
|
|
|
+
|
|
|
|
|
+ cancels := make([]CancelFunc, watcherN)
|
|
|
|
|
+ for i := 0; i < watcherN; i++ {
|
|
|
// non-0 value to keep watchers in unsynced
|
|
// non-0 value to keep watchers in unsynced
|
|
|
_, cancel := w.Watch(testKey, true, 1)
|
|
_, cancel := w.Watch(testKey, true, 1)
|
|
|
cancels[i] = cancel
|
|
cancels[i] = cancel
|
|
@@ -71,13 +69,13 @@ func BenchmarkWatchableStoreUnsyncedCancel(b *testing.B) {
|
|
|
|
|
|
|
|
// random-cancel N watchers to make it not biased towards
|
|
// random-cancel N watchers to make it not biased towards
|
|
|
// data structures with an order, such as slice.
|
|
// data structures with an order, such as slice.
|
|
|
- ix := rand.Perm(watcherSize)
|
|
|
|
|
|
|
+ ix := rand.Perm(watcherN)
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
b.ResetTimer()
|
|
|
b.ReportAllocs()
|
|
b.ReportAllocs()
|
|
|
|
|
|
|
|
// cancel N watchers
|
|
// cancel N watchers
|
|
|
- for _, idx := range ix[:benchSampleSize] {
|
|
|
|
|
|
|
+ for _, idx := range ix[:benchSampleN] {
|
|
|
cancels[idx]()
|
|
cancels[idx]()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -97,10 +95,10 @@ func BenchmarkWatchableStoreSyncedCancel(b *testing.B) {
|
|
|
w := s.NewWatcher()
|
|
w := s.NewWatcher()
|
|
|
|
|
|
|
|
// put 1 million watchers on the same key
|
|
// put 1 million watchers on the same key
|
|
|
- const watcherSize = 1000000
|
|
|
|
|
|
|
+ const watcherN = 1000000
|
|
|
|
|
|
|
|
- cancels := make([]CancelFunc, watcherSize)
|
|
|
|
|
- for i := 0; i < watcherSize; i++ {
|
|
|
|
|
|
|
+ cancels := make([]CancelFunc, watcherN)
|
|
|
|
|
+ for i := 0; i < watcherN; i++ {
|
|
|
// 0 for startRev to keep watchers in synced
|
|
// 0 for startRev to keep watchers in synced
|
|
|
_, cancel := w.Watch(testKey, true, 0)
|
|
_, cancel := w.Watch(testKey, true, 0)
|
|
|
cancels[i] = cancel
|
|
cancels[i] = cancel
|
|
@@ -108,7 +106,7 @@ func BenchmarkWatchableStoreSyncedCancel(b *testing.B) {
|
|
|
|
|
|
|
|
// randomly cancel watchers to make it not biased towards
|
|
// randomly cancel watchers to make it not biased towards
|
|
|
// data structures with an order, such as slice.
|
|
// data structures with an order, such as slice.
|
|
|
- ix := rand.Perm(watcherSize)
|
|
|
|
|
|
|
+ ix := rand.Perm(watcherN)
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
b.ResetTimer()
|
|
|
b.ReportAllocs()
|
|
b.ReportAllocs()
|