From 200e59f329f3bbd34744220fa15451e4e07c42ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Pacana?= Date: Mon, 25 May 2026 23:07:55 +0200 Subject: [PATCH] Reuse failure positions in benchmarks - Use the failure result position when retrying conditional append benchmark writes so retries do not need a follow-up read to find the new boundary. - Keep benchmark contention behavior aligned with the public append result API. --- lib/benchmark/append_non_conflicting_tags.rb | 5 +++-- lib/benchmark/concurrent_append_conflicting_tags.rb | 11 +++-------- .../concurrent_append_non_conflicting_tags.rb | 8 +++----- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/lib/benchmark/append_non_conflicting_tags.rb b/lib/benchmark/append_non_conflicting_tags.rb index 038cff4..a8c80de 100644 --- a/lib/benchmark/append_non_conflicting_tags.rb +++ b/lib/benchmark/append_non_conflicting_tags.rb @@ -22,12 +22,13 @@ module En57 .with_tag(tags = ["writer:#{run_id}"]) events = @batch_size.times.map { Event.new(type:, tags:) } + position = 0 measure.call do loop do - case @event_store.append(events, fail_if: scope.after(position = 0)) + case @event_store.append(events, fail_if: scope.after(position)) in Success break - in Failure + in Failure(position:) retries.call end end diff --git a/lib/benchmark/concurrent_append_conflicting_tags.rb b/lib/benchmark/concurrent_append_conflicting_tags.rb index 8e610fe..25f4077 100644 --- a/lib/benchmark/concurrent_append_conflicting_tags.rb +++ b/lib/benchmark/concurrent_append_conflicting_tags.rb @@ -23,19 +23,14 @@ module En57 events = @batch_size.times.map { Event.new(type:, tags:) } barrier.wait + position = 0 measure.call do loop do - case @event_store.append( - events, - fail_if: scope.after(position = 0), - ) + case @event_store.append(events, fail_if: scope.after(position)) in Success break - in Failure + in Failure(position:) retries.call - scope.each_with_position do |_event, event_position| - position = event_position - end end end end diff --git a/lib/benchmark/concurrent_append_non_conflicting_tags.rb b/lib/benchmark/concurrent_append_non_conflicting_tags.rb index 54c94be..e6727d8 100644 --- a/lib/benchmark/concurrent_append_non_conflicting_tags.rb +++ b/lib/benchmark/concurrent_append_non_conflicting_tags.rb @@ -27,15 +27,13 @@ module En57 events = @batch_size.times.map { Event.new(type:, tags:) } barrier.wait + position = 0 measure.call do loop do - case @event_store.append( - events, - fail_if: scope.after(position = 0), - ) + case @event_store.append(events, fail_if: scope.after(position)) in Success break - in Failure + in Failure(position:) retries.call end end -- 2.51.2