-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #190 from SamSaffron/performance-tests
Performance tests
- Loading branch information
Showing
4 changed files
with
151 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
def wait_for(timeout_milliseconds = 2000) | ||
timeout = (timeout_milliseconds + 0.0) / 1000 | ||
finish = Time.now + timeout | ||
|
||
Thread.new do | ||
sleep(0.001) while Time.now < finish && !yield | ||
end.join | ||
end | ||
|
||
def test_config_for_backend(backend) | ||
config = { backend: backend } | ||
case backend | ||
when :redis | ||
config[:url] = ENV['REDISURL'] | ||
when :postgres | ||
config[:backend_options] = { host: ENV['PGHOST'], user: ENV['PGUSER'] || ENV['USER'], password: ENV['PGPASSWORD'], dbname: ENV['PGDATABASE'] || 'message_bus_test' } | ||
end | ||
config | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', '..', 'lib') | ||
require 'logger' | ||
require 'benchmark' | ||
require 'message_bus' | ||
|
||
require_relative "../helpers" | ||
|
||
backends = ENV['MESSAGE_BUS_BACKENDS'].split(",").map(&:to_sym) | ||
channel = "/foo" | ||
iterations = 10_000 | ||
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(60) do |bm| | ||
backends.each do |backend| | ||
benchmark_publication_only.call(bm, backend) | ||
end | ||
|
||
puts | ||
|
||
backends.each do |backend| | ||
benchmark_subscription_no_trimming.call(bm, backend) | ||
end | ||
|
||
results << nil | ||
puts | ||
|
||
backends.each do |backend| | ||
benchmark_subscription_with_trimming.call(bm, backend) | ||
end | ||
end | ||
puts | ||
|
||
results.each do |result| | ||
puts result | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters