From 0ed01a0ae2b4e1424bb336fa14d9b0fe067f1974 Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Wed, 5 Dec 2018 16:39:39 -0200 Subject: [PATCH] Run variations on publish benchmark * 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 --- .rubocop_todo.yml | 8 ++-- spec/performance/publish.rb | 91 ++++++++++++++++++++++++++++++------- 2 files changed, 79 insertions(+), 20 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f24482b7..45af66e7 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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 @@ -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: @@ -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 @@ -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: diff --git a/spec/performance/publish.rb b/spec/performance/publish.rb index b3511311..1cc19dc8 100755 --- a/spec/performance/publish.rb +++ b/spec/performance/publish.rb @@ -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