[unistore] Add benchmark for write throughput (#101345)

* Add generic benchmark

* address comments
This commit is contained in:
Georges Chaudy
2025-02-26 17:17:35 +02:00
committed by GitHub
parent 4270bf742a
commit 8c935c8f4a
3 changed files with 231 additions and 10 deletions
+19 -10
View File
@@ -40,6 +40,9 @@ type BackendOptions struct {
PollingInterval time.Duration
WatchBufferSize int
IsHA bool
// testing
SimulatedNetworkLatency time.Duration // slows down the create transactions by a fixed amount
}
func NewBackend(opts BackendOptions) (Backend, error) {
@@ -58,15 +61,16 @@ func NewBackend(opts BackendOptions) (Backend, error) {
opts.WatchBufferSize = defaultWatchBufferSize
}
return &backend{
isHA: opts.IsHA,
done: ctx.Done(),
cancel: cancel,
log: log.New("sql-resource-server"),
tracer: opts.Tracer,
dbProvider: opts.DBProvider,
pollingInterval: opts.PollingInterval,
watchBufferSize: opts.WatchBufferSize,
batchLock: &batchLock{running: make(map[string]bool)},
isHA: opts.IsHA,
done: ctx.Done(),
cancel: cancel,
log: log.New("sql-resource-server"),
tracer: opts.Tracer,
dbProvider: opts.DBProvider,
pollingInterval: opts.PollingInterval,
watchBufferSize: opts.WatchBufferSize,
batchLock: &batchLock{running: make(map[string]bool)},
simulatedNetworkLatency: opts.SimulatedNetworkLatency,
}, nil
}
@@ -95,6 +99,9 @@ type backend struct {
pollingInterval time.Duration
watchBufferSize int
notifier eventNotifier
// testing
simulatedNetworkLatency time.Duration
}
func (b *backend) Init(ctx context.Context) error {
@@ -249,7 +256,9 @@ func (b *backend) create(ctx context.Context, event resource.WriteEvent) (int64,
return fmt.Errorf("update resource rv: %w", err)
}
newVersion = rv
if b.simulatedNetworkLatency > 0 {
time.Sleep(b.simulatedNetworkLatency)
}
return nil
})