Skip to content

Commit

Permalink
Deffered reader with criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
fidel committed Jul 12, 2024
1 parent af8119e commit 9f43352
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ruby_event_store-active_record/repository_reader_benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class EventInStream < ::ActiveRecord::Base

Integer(ARGV.first || 1).times do
RubyEventStore::Client.new(repository: RubyEventStore::ActiveRecord::EventRepository.new(serializer: YAML)).append(
(1..1_000).map { RubyEventStore::Event.new },
(1..1_000).map { |i| RubyEventStore::Event.new(metadata: { event_type: %w[a b c d][i % 4] }) },
)
print "."
end
Expand Down Expand Up @@ -81,9 +81,19 @@ class EventInStream < ::ActiveRecord::Base
RubyEventStore::ActiveRecord::BatchEnumerator.new(spec.batch_size, spec.limit, batch_reader).each
end

mk_benchmark = ->(reader) { mk_client[reader].read.each_batch { print "." } }
deffered = ->(spec, stream) do
batch_reader = ->(offset, limit) do
stream.joins(
"INNER JOIN (SELECT id FROM event_store_events WHERE event_type = 'a' LIMIT #{limit} OFFSET #{offset}) AS tmp USING(id)",
).map(&record)
end
RubyEventStore::BatchEnumerator.new(spec.batch_size, spec.limit, batch_reader).each
end

mk_benchmark = ->(reader) { mk_client[reader].read.of_type("a").each {} }

Benchmark.bm(14) do |x|
x.report("offset/limit:") { mk_benchmark[offset_limit] }
x.report("id/limit:") { mk_benchmark[id_limit] }
x.report("deffered:") { mk_benchmark[deffered] }
end

0 comments on commit 9f43352

Please sign in to comment.