Skip to content

Commit

Permalink
ci: add async-redis to iterations per second for a benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
supercaracal committed Aug 24, 2024
1 parent f04a4cd commit fca4f05
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
source 'https://rubygems.org'
gemspec name: 'redis-cluster-client'

gem 'async-redis'
gem 'benchmark-ips'
gem 'hiredis-client', '~> 0.6'
gem 'memory_profiler'
Expand Down
27 changes: 27 additions & 0 deletions test/ips_single.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require 'async/redis/cluster_client'
require 'benchmark/ips'
require 'redis_cluster_client'
require 'testing_constants'
Expand All @@ -20,6 +21,7 @@ def run
envoy: envoy,
cproxy: cluster_proxy
)
async_bench(make_async_client)
end

def make_client
Expand All @@ -44,6 +46,11 @@ def make_client_for_cluster_proxy
).new_client
end

def make_async_client
endpoints = TEST_NODE_URIS.map { |e| ::Async::Redis::Endpoint.parse(e) }
::Async::Redis::ClusterClient.new(endpoints)
end

def print_letter(title)
print "################################################################################\n"
print "# #{title}\n"
Expand Down Expand Up @@ -75,6 +82,26 @@ def bench(**kwargs)
x.compare!
end
end

def async_bench(cluster)
Benchmark.ips do |x|
x.time = 5
x.warmup = 1

x.report('single: async') do
Async do
ATTEMPTS.times do |i|
key = "key#{i}"
slot = cluster.slot_for(key)
client = cluster.client_for(slot)
client.get(key)
end
end
end

x.compare!
end
end
end

IpsSingle.run

0 comments on commit fca4f05

Please sign in to comment.