Skip to content

Commit

Permalink
Run variations on publish benchmark
Browse files Browse the repository at this point in the history
* Strictly publishing only, without subscribing
* Publishing and subscribing with max backlog length large enough to not have to trim backlogs during the benchmark
* Publishing and subscribing backlogs with approximately 10% of the capacity of the benchmark
  • Loading branch information
benlangfeld committed Dec 6, 2018
1 parent 79cba6d commit 255c50b
Showing 1 changed file with 75 additions and 16 deletions.
91 changes: 75 additions & 16 deletions spec/performance/publish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,87 @@

puts "Running publication benchmark with #{iterations} iterations on backends: #{backends.inspect}"

benchmark_publication_only = lambda do |bm, backend|
bus = MessageBus::Instance.new
bus.configure(test_config_for_backend(backend))

bm.report("#{backend} - publication only") do
iterations.times { bus.publish(channel, "Hello world") }
end

bus.reset!
bus.destroy
end

benchmark_subscription_no_trimming = lambda do |bm, backend|
test_title = "#{backend} - subscription no trimming"

bus = MessageBus::Instance.new
bus.configure(test_config_for_backend(backend))

bus.reliable_pub_sub.max_backlog_size = iterations
bus.reliable_pub_sub.max_global_backlog_size = iterations

messages_received = 0
bus.after_fork
bus.subscribe(channel) do |_message|
messages_received += 1
end

bm.report(test_title) do
iterations.times { bus.publish(channel, "Hello world") }
wait_for(60000) { messages_received == iterations }
end

results << "[#{test_title}]: #{iterations} messages sent, #{messages_received} received, rate of #{(messages_received.to_f / iterations.to_f) * 100}%"

bus.reset!
bus.destroy
end

benchmark_subscription_with_trimming = lambda do |bm, backend|
test_title = "#{backend} - subscription with trimming"

bus = MessageBus::Instance.new
bus.configure(test_config_for_backend(backend))

bus.reliable_pub_sub.max_backlog_size = (iterations / 10)
bus.reliable_pub_sub.max_global_backlog_size = (iterations / 10)

messages_received = 0
bus.after_fork
bus.subscribe(channel) do |_message|
messages_received += 1
end

bm.report(test_title) do
iterations.times { bus.publish(channel, "Hello world") }
wait_for(60000) { messages_received == iterations }
end

results << "[#{test_title}]: #{iterations} messages sent, #{messages_received} received, rate of #{(messages_received.to_f / iterations.to_f) * 100}%"

bus.reset!
bus.destroy
end

puts
Benchmark.bm(10) do |bm|
Benchmark.bm(60) do |bm|
backends.each do |backend|
messages_received = 0

bus = MessageBus::Instance.new
bus.configure(test_config_for_backend(backend))
benchmark_publication_only.call(bm, backend)
end

bus.after_fork
bus.subscribe(channel) do |_message|
messages_received += 1
end
puts

bm.report(backend) do
iterations.times { bus.publish(channel, "Hello world") }
wait_for(2000) { messages_received == iterations }
end
backends.each do |backend|
benchmark_subscription_no_trimming.call(bm, backend)
end

results << "[#{backend}]: #{iterations} messages sent, #{messages_received} received, rate of #{(messages_received.to_f / iterations.to_f) * 100}%"
results << nil
puts

bus.reset!
bus.destroy
backends.each do |backend|
benchmark_subscription_with_trimming.call(bm, backend)
end
end
puts
Expand Down

0 comments on commit 255c50b

Please sign in to comment.