Skip to content

Commit

Permalink
Merge pull request #403 from jlledom/THREESCALE-11232-pipeline-benchm…
Browse files Browse the repository at this point in the history
…arks

THREESCALE-11232: Add benchmark to pipeline
  • Loading branch information
jlledom authored Sep 6, 2024
2 parents 3c79396 + 32dd860 commit 385ea14
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 20 deletions.
24 changes: 22 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ commands:
- run:
name: Run tests
command: bundle exec script/test
run_benchmark:
steps:
- run:
name: Run benchmark
command: bundle exec script/benchmark

workflows:
version: 2
Expand All @@ -124,8 +129,11 @@ workflows:
requires:
- install_dependencies
- test_twemproxy:
requires:
- install_dependencies
requires:
- install_dependencies
- benchmark:
requires:
- install_dependencies

jobs:
install_ruby:
Expand Down Expand Up @@ -221,3 +229,15 @@ jobs:
- start_services:
services: redis-master twemproxy redis-shard1 redis-shard2 redis-shard3
- run_tests
benchmark:
executor:
name: ubuntu_vm
working_directory: ~/project
environment:
CONFIG_QUEUES_MASTER_NAME: redis://localhost:6379
CONFIG_REDIS_PROXY: redis://localhost:6379
steps:
- *attach-to-workspace
- start_services:
services: redis-master
- run_benchmark
43 changes: 27 additions & 16 deletions bench/worker/worker_bench.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class WorkerBenchmark
def initialize
super
@async = ThreeScale::Backend.configuration.redis.async
@nreports = ENV.fetch('NUM_REPORTS', "100000")
end

def async?
Expand Down Expand Up @@ -55,6 +56,28 @@ def dup_resque_redis
end

def run
n_reports = @nreports.split(',').map(&:strip).map(&:to_i)

# Warming up...
run_benchark(10000)

reports = n_reports.map { run_benchark(_1) }

print_reports reports
end

def print_reports(reports)
warn "=" * 70
warn Benchmark::CAPTION

reports.each do |res, rss|
warn res.format(Benchmark::Tms::FORMAT).chop + " #{rss}KB" + " (#{res.label})"
end

warn "=" * 70
end

def run_benchark(n_reports)
new_worker # initialize worker to configure logging, good to improve that one day
orig_log_level = Worker.logger.level
Worker.logger.warn!
Expand All @@ -63,26 +86,14 @@ def run
storage(true).flushdb
seed_data

create_reports(10_000)
Benchmark.measure('10k reports') do |x|
clear_queue
end

res = []
create_reports(100_000)
res << Benchmark.measure('100k reports') do |x|
create_reports(n_reports)
res = Benchmark.measure( "#{n_reports} reports") do |x|
clear_queue
end

create_reports(1_000_000)
res << Benchmark.measure('1m reports') do |x|
clear_queue
end
rss = `ps -o rss #{Process.pid}`.lines.last.to_i

warn "=" * 70
warn Benchmark::CAPTION
res.each { warn _1.format(Benchmark::Tms::FORMAT).chop + " (#{_1.label})" }
warn "=" * 70
[res, rss]
ensure
Worker.logger.level = orig_log_level if orig_log_level
end
Expand Down
7 changes: 5 additions & 2 deletions lib/3scale/tasks/connectivity.rake
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ namespace :connectivity do
Async { ping(redis_instance, storage_type) }
end

def ping(redis_instance, storage_type)
def ping(redis_instance, storage_type, attempts = 3)
attempts -= 1
redis_instance.ping
rescue => e
warn "Error connecting to Redis #{storage_type}: #{e}"
exit(false)
exit(false) unless attempts > 0
sleep 1
retry
else
puts "Connection to Redis #{storage_type} performed successfully"
end
Expand Down
38 changes: 38 additions & 0 deletions script/benchmark
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

function wait_redis()
{
bundle exec rake connectivity:redis_storage_check
bundle exec rake connectivity:redis_storage_queue_check
}

function do_benchmark()
{
case $1 in
sync)
echo "==================== Running tests using the SYNC Redis driver ===================="
CONFIG_REDIS_ASYNC=false bundle exec rake bench[worker/worker_bench.rb]
;;
async)
echo "==================== Running tests using the ASYNC Redis driver ===================="
CONFIG_REDIS_ASYNC=true bundle exec rake bench[worker/worker_bench.rb]
;;
*)
echo "Invalid Redis driver option: $1"
exit 1
esac
}

function run_benchmark()
{
export RACK_ENV=test

wait_redis

do_benchmark "sync" && do_benchmark "async"
}

if ! run_benchmark; then
echo "Tests failed" >&2
exit 1
fi

0 comments on commit 385ea14

Please sign in to comment.