Skip to content

Commit ebf75ac

Browse files
authored
ci: add async-redis to iterations per second for a benchmark (#371)
1 parent f04a4cd commit ebf75ac

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
source 'https://rubygems.org'
44
gemspec name: 'redis-cluster-client'
55

6+
gem 'async-redis', platform: :mri
67
gem 'benchmark-ips'
78
gem 'hiredis-client', '~> 0.6'
89
gem 'memory_profiler'

test/ips_single.rb

+27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
require 'async/redis/cluster_client'
34
require 'benchmark/ips'
45
require 'redis_cluster_client'
56
require 'testing_constants'
@@ -20,6 +21,7 @@ def run
2021
envoy: envoy,
2122
cproxy: cluster_proxy
2223
)
24+
async_bench(make_async_client)
2325
end
2426

2527
def make_client
@@ -44,6 +46,11 @@ def make_client_for_cluster_proxy
4446
).new_client
4547
end
4648

49+
def make_async_client
50+
endpoints = TEST_NODE_URIS.map { |e| ::Async::Redis::Endpoint.parse(e) }
51+
::Async::Redis::ClusterClient.new(endpoints)
52+
end
53+
4754
def print_letter(title)
4855
print "################################################################################\n"
4956
print "# #{title}\n"
@@ -75,6 +82,26 @@ def bench(**kwargs)
7582
x.compare!
7683
end
7784
end
85+
86+
def async_bench(cluster)
87+
Benchmark.ips do |x|
88+
x.time = 5
89+
x.warmup = 1
90+
91+
x.report('single: async') do
92+
Async do
93+
ATTEMPTS.times do |i|
94+
key = "key#{i}"
95+
slot = cluster.slot_for(key)
96+
client = cluster.client_for(slot)
97+
client.get(key)
98+
end
99+
end
100+
end
101+
102+
x.compare!
103+
end
104+
end
78105
end
79106

80107
IpsSingle.run

0 commit comments

Comments
 (0)