From fca4f05cd761586a799991b3a2146d072afd85af Mon Sep 17 00:00:00 2001 From: Taishi Kasuga Date: Sat, 24 Aug 2024 14:05:00 +0900 Subject: [PATCH] ci: add async-redis to iterations per second for a benchmark --- Gemfile | 1 + test/ips_single.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/Gemfile b/Gemfile index 584b7cfe..cffaff10 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/test/ips_single.rb b/test/ips_single.rb index f082a8d6..17959792 100644 --- a/test/ips_single.rb +++ b/test/ips_single.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require 'async/redis/cluster_client' require 'benchmark/ips' require 'redis_cluster_client' require 'testing_constants' @@ -20,6 +21,7 @@ def run envoy: envoy, cproxy: cluster_proxy ) + async_bench(make_async_client) end def make_client @@ -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" @@ -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