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 5, 2018
1 parent 08f10e4 commit 0ed01a0
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 20 deletions.
8 changes: 4 additions & 4 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-12-05 18:37:28 +0000 using RuboCop version 0.60.0.
# on 2018-12-05 18:38:26 +0000 using RuboCop version 0.60.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -382,7 +382,7 @@ Style/NilComparison:
- 'lib/message_bus/backends/redis.rb'
- 'spec/lib/message_bus/distributed_cache_spec.rb'

# Offense count: 6
# Offense count: 8
# Cop supports --auto-correct.
# Configuration parameters: Strict.
Style/NumericLiterals:
Expand Down Expand Up @@ -534,7 +534,7 @@ Style/SpecialGlobalVars:
- 'message_bus.gemspec'
- 'spec/spec_helper.rb'

# Offense count: 668
# Offense count: 670
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Expand Down Expand Up @@ -636,7 +636,7 @@ Style/ZeroLengthPredicate:
- 'lib/message_bus/rack/middleware.rb'
- 'spec/lib/message_bus_spec.rb'

# Offense count: 214
# Offense count: 215
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Expand Down
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 0ed01a0

Please sign in to comment.