Skip to content

Commit 60faf62

Browse files
committed
gossip: add callback parallelism benchmark
This commit benchmarks the parallelism of the callback worker. It registers multiple callbacks, and executes a fake workload that sleeps for a short duration to simulate work done in the callback. If we implement a parallel execution of the callback workers, we should see a significant speedup. References: #125084 Release note: None
1 parent e2d8fc5 commit 60faf62

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

pkg/gossip/infostore_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,3 +684,37 @@ func TestCallbacksCalledSequentially(t *testing.T) {
684684
}
685685
wg.Wait()
686686
}
687+
688+
// BenchmarkCallbackParallelism benchmarks the parallelism of the callback
689+
// worker. It registers multiple callbacks, and executes a fake workload
690+
// that sleeps for a short duration to simulate work done in the callback.
691+
// If we implement a parallel execution of the callback workers, we should
692+
// see a significant speedup.
693+
func BenchmarkCallbackParallelism(b *testing.B) {
694+
ctx := context.Background()
695+
is, stopper := newTestInfoStore()
696+
defer stopper.Stop(ctx)
697+
wg := &sync.WaitGroup{}
698+
699+
callback := func(key string, val roachpb.Value) {
700+
// Sleep for a short duration to simulate work done in callback.
701+
time.Sleep(time.Millisecond)
702+
wg.Done()
703+
}
704+
705+
// Register 5 callbacks.
706+
numCallbacks := 5
707+
callbacks := make([]func(), numCallbacks)
708+
for i := range numCallbacks {
709+
callbacks[i] = is.registerCallback("key.*", callback)
710+
}
711+
712+
b.ResetTimer()
713+
b.ReportAllocs()
714+
for i := 0; i < b.N; i++ {
715+
wg.Add(numCallbacks)
716+
require.NoError(b, is.addInfo(fmt.Sprintf("key%d", i), is.newInfo(nil, time.Second)))
717+
// Wait for all the callback executions to finish before the next iteration.
718+
wg.Wait()
719+
}
720+
}

0 commit comments

Comments
 (0)