Run variations on publish benchmark

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
From 255c50bf40fbd96de753208639e0e20fbfa193ab Mon Sep 17 00:00:00 2001
From: Ben Langfeld <blangfeld@powerhrg.com>
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

diff --git a/spec/performance/publish.rb b/spec/performance/publish.rb
index b351131..1cc19dc 100755
--- a/spec/performance/publish.rb
+++ b/spec/performance/publish.rb
@@ -12,28 +12,87 @@ results = []
 
 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

GitHub