From e1ca7dc93db7068ecff58b9c3d41accbdd6047f6 Mon Sep 17 00:00:00 2001 From: Taishi Kasuga Date: Sat, 20 Dec 2025 13:08:20 +0900 Subject: [PATCH] ci: remove minitest benchmark codes --- .github/workflows/test.yaml | 61 ------------------- Rakefile | 10 +-- test/bench_command.rb | 113 ---------------------------------- test/benchmark_helper.rb | 34 ----------- test/benchmark_mixin.rb | 118 ------------------------------------ 5 files changed, 1 insertion(+), 335 deletions(-) delete mode 100644 test/bench_command.rb delete mode 100644 test/benchmark_helper.rb delete mode 100644 test/benchmark_mixin.rb diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5f5fb0c2..551a1b3a 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -133,67 +133,6 @@ jobs: run: bundle exec rake test - name: Stop containers run: docker compose --progress quiet -f $DOCKER_COMPOSE_FILE down || true - benchmark: - if: github.event_name == 'schedule' && github.repository == 'redis-rb/redis-cluster-client' - name: Benchmark - timeout-minutes: 10 - runs-on: ubuntu-latest - env: - REDIS_VERSION: '7.2' - DOCKER_COMPOSE_FILE: 'compose.latency.yaml' - REDIS_REPLICA_SIZE: '2' - REDIS_CLIENT_MAX_THREADS: '10' - DELAY_TIME: '1ms' - steps: - - name: Check out code - uses: actions/checkout@v4 - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: '3.4' - bundler-cache: true - - name: Pull Docker images - run: docker compose --progress quiet -f $DOCKER_COMPOSE_FILE pull - - name: Run containers - run: docker compose --progress quiet -f $DOCKER_COMPOSE_FILE up -d - - name: Wait for Redis cluster to be ready - run: bundle exec rake wait - - name: Print containers - run: docker compose -f $DOCKER_COMPOSE_FILE ps - - name: Rebuild cluster for balancing of replicas - run: bundle exec rake build_cluster_for_bench - env: - DEBUG: '1' - - name: Print topology - run: | - for i in {1..9} - do - echo "node$i: $(docker compose -f $DOCKER_COMPOSE_FILE exec node$i redis-cli cluster nodes | grep myself)" - done - - name: Ping nodes - run: | - for i in {1..9} - do - node_addr="$(docker compose -f $DOCKER_COMPOSE_FILE exec node$i redis-cli cluster nodes | grep myself | awk '{print $2}' | cut -d'@' -f1 | cut -d':' -f1)" - echo "node$i:" - ping -c 5 $node_addr - done - - name: Print cpu info - run: grep 'model name' /proc/cpuinfo - - name: Print memory info - run: free -w - - name: Print disk info - run: df -h - - name: Run minitest - run: bundle exec rake bench | grep BenchCommand | grep -v 'Envoy#bench_pipeline_echo\|Envoy#bench_single_echo' | sort - - name: Reset qdisc - run: | - for i in {5..9..2} - do - docker compose -f $DOCKER_COMPOSE_FILE exec node$i tc qdisc del dev eth0 root netem || true - done - - name: Stop containers - run: docker compose --progress quiet -f $DOCKER_COMPOSE_FILE down || true ips: if: github.event_name == 'schedule' && github.repository == 'redis-rb/redis-cluster-client' name: IPS diff --git a/Rakefile b/Rakefile index 6e9c1a78..8046b863 100644 --- a/Rakefile +++ b/Rakefile @@ -31,7 +31,7 @@ SLUGGISH_TEST_TYPES.each do |type| end end -%i[bench ips prof].each do |k| +%i[ips prof].each do |k| Rake::TestTask.new(k) do |t| t.libs << :lib t.libs << :test @@ -70,11 +70,3 @@ task :build_cluster, %i[addr1 addr2] do |_, args| timeout: 30.0 ).rebuild end - -desc 'Build cluster for benchmark' -task :build_cluster_for_bench do - $LOAD_PATH.unshift(File.expand_path('test', __dir__)) - require 'cluster_controller' - nodes = (6379..6387).map { |port| "redis://127.0.0.1:#{port}" } - ::ClusterController.new(nodes, shard_size: 3, replica_size: 2, timeout: 30.0).rebuild -end diff --git a/test/bench_command.rb b/test/bench_command.rb deleted file mode 100644 index a78d3317..00000000 --- a/test/bench_command.rb +++ /dev/null @@ -1,113 +0,0 @@ -# frozen_string_literal: true - -require 'benchmark_helper' -require 'benchmark_mixin' - -class BenchCommand - class PrimaryOnly < BenchmarkWrapper - include BenchmarkMixin - - private - - def new_test_client - ::RedisClient.cluster( - nodes: TEST_NODE_URIS, - fixed_hostname: TEST_FIXED_HOSTNAME, - **TEST_GENERIC_OPTIONS - ).new_client - end - end - - class ScaleReadRandom < BenchmarkWrapper - include BenchmarkMixin - - private - - def new_test_client - ::RedisClient.cluster( - nodes: TEST_NODE_URIS, - replica: true, - replica_affinity: :random, - fixed_hostname: TEST_FIXED_HOSTNAME, - **TEST_GENERIC_OPTIONS - ).new_client - end - end - - class ScaleReadRandomWithPrimary < BenchmarkWrapper - include BenchmarkMixin - - private - - def new_test_client - ::RedisClient.cluster( - nodes: TEST_NODE_URIS, - replica: true, - replica_affinity: :random_with_primary, - fixed_hostname: TEST_FIXED_HOSTNAME, - **TEST_GENERIC_OPTIONS - ).new_client - end - end - - class ScaleReadLatency < BenchmarkWrapper - include BenchmarkMixin - - private - - def new_test_client - ::RedisClient.cluster( - nodes: TEST_NODE_URIS, - replica: true, - replica_affinity: :latency, - fixed_hostname: TEST_FIXED_HOSTNAME, - **TEST_GENERIC_OPTIONS - ).new_client - end - end - - class Pooled < BenchmarkWrapper - include BenchmarkMixin - - private - - def new_test_client - ::RedisClient.cluster( - nodes: TEST_NODE_URIS, - fixed_hostname: TEST_FIXED_HOSTNAME, - **TEST_GENERIC_OPTIONS - ).new_pool(timeout: TEST_TIMEOUT_SEC, size: 2) - end - end - - class Envoy < BenchmarkWrapper - include BenchmarkMixin - include BenchmarkMixinForProxy - - # https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/other_protocols/redis#supported-commands - def bench_single_echo - skip('Envoy does not support ECHO command.') - end - - def bench_pipeline_echo - skip('Envoy does not support ECHO command.') - end - - private - - def new_test_client - ::RedisClient.config(**TEST_GENERIC_OPTIONS.merge(BENCH_ENVOY_OPTIONS)).new_client - end - end - - class RedisClusterProxy < BenchmarkWrapper - include BenchmarkMixin - include BenchmarkMixinForProxy - - private - - def new_test_client - ::RedisClient.config(**TEST_GENERIC_OPTIONS.merge(BENCH_REDIS_CLUSTER_PROXY_OPTIONS)).new_client - end - end -end diff --git a/test/benchmark_helper.rb b/test/benchmark_helper.rb deleted file mode 100644 index 7a4f5c3c..00000000 --- a/test/benchmark_helper.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -# @see https://ruby-doc.org/stdlib-3.0.1/libdoc/minitest/rdoc/Minitest/Benchmark.html - -require 'minitest/benchmark' -require 'minitest/autorun' -require 'redis_cluster_client' -require 'testing_constants' - -case ENV.fetch('REDIS_CONNECTION_DRIVER', 'ruby') -when 'hiredis' then require 'hiredis-client' -end - -class BenchmarkWrapper < Minitest::Benchmark - private - - def swap_timeout(client, timeout:) - return if client.nil? - - node = client.instance_variable_get(:@router)&.instance_variable_get(:@node) - raise 'The client must be initialized.' if node.nil? - - updater = lambda do |c, t| - c.read_timeout = t - c.config.instance_variable_set(:@read_timeout, t) - end - - regular_timeout = node.first.read_timeout - node.each { |cli| updater.call(cli, timeout) } - result = yield client - node.each { |cli| updater.call(cli, regular_timeout) } - result - end -end diff --git a/test/benchmark_mixin.rb b/test/benchmark_mixin.rb deleted file mode 100644 index 56987358..00000000 --- a/test/benchmark_mixin.rb +++ /dev/null @@ -1,118 +0,0 @@ -# frozen_string_literal: true - -module BenchmarkMixin - MIN_THRESHOLD = 0.95 - MAX_PIPELINE_SIZE = 100 - - def setup - @client = new_test_client - @client.call('flushdb') - wait_for_replication - end - - def teardown - @client&.call('flushdb') - wait_for_replication - @client&.close - end - - def bench_single_echo - assert_performance_linear(MIN_THRESHOLD) do |n| - n.times do - @client.call('echo', 'Hello world') - end - end - end - - def bench_single_set - assert_performance_linear(MIN_THRESHOLD) do |n| - n.times do |i| - @client.call('set', "key#{i}", i) - end - end - end - - def bench_single_get - assert_performance_linear(MIN_THRESHOLD) do |n| - n.times do |i| - @client.call('get', "key#{i}") - end - end - end - - def bench_pipeline_echo - assert_performance_linear(MIN_THRESHOLD) do |n| - (1..n).each_slice(MAX_PIPELINE_SIZE) do |list| - @client.pipelined do |pi| - list.each do - pi.call('echo', 'Hello world') - end - end - end - end - end - - def bench_pipeline_set - assert_performance_linear(MIN_THRESHOLD) do |n| - (1..n).each_slice(MAX_PIPELINE_SIZE) do |list| - @client.pipelined do |pi| - list.each do |i| - pi.call('set', "key#{i}", i) - end - end - end - end - end - - def bench_pipeline_get - assert_performance_linear(MIN_THRESHOLD) do |n| - (1..n).each_slice(MAX_PIPELINE_SIZE) do |list| - @client.pipelined do |pi| - list.each do |i| - pi.call('get', "key#{i}") - end - end - end - end - end - - private - - def wait_for_replication - client_side_timeout = TEST_TIMEOUT_SEC + 1.0 - server_side_timeout = (TEST_TIMEOUT_SEC * 1000).to_i - swap_timeout(@client, timeout: 0.1) do |client| - client&.blocking_call(client_side_timeout, 'wait', TEST_REPLICA_SIZE, server_side_timeout) - end - end -end - -module BenchmarkMixinForProxy - def setup - @client = new_test_client - @cluster_client = new_cluster_client - @cluster_client.call('flushdb') - wait_for_replication - end - - def teardown - @cluster_client&.call('flushdb') - wait_for_replication - @cluster_client&.close - @client&.close - end - - private - - def new_cluster_client - ::RedisClient.cluster(nodes: TEST_NODE_URIS, fixed_hostname: TEST_FIXED_HOSTNAME, **TEST_GENERIC_OPTIONS).new_client - end - - def wait_for_replication - client_side_timeout = TEST_TIMEOUT_SEC + 1.0 - server_side_timeout = (TEST_TIMEOUT_SEC * 1000).to_i - swap_timeout(@cluster_client, timeout: 0.1) do |cluster_client| - cluster_client&.blocking_call(client_side_timeout, 'wait', TEST_REPLICA_SIZE, server_side_timeout) - end - end -end