Skip to content

Commit 385ea14

Browse files
authored
Merge pull request #403 from jlledom/THREESCALE-11232-pipeline-benchmarks
THREESCALE-11232: Add benchmark to pipeline
2 parents 3c79396 + 32dd860 commit 385ea14

File tree

4 files changed

+92
-20
lines changed

4 files changed

+92
-20
lines changed

.circleci/config.yml

+22-2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ commands:
102102
- run:
103103
name: Run tests
104104
command: bundle exec script/test
105+
run_benchmark:
106+
steps:
107+
- run:
108+
name: Run benchmark
109+
command: bundle exec script/benchmark
105110

106111
workflows:
107112
version: 2
@@ -124,8 +129,11 @@ workflows:
124129
requires:
125130
- install_dependencies
126131
- test_twemproxy:
127-
requires:
128-
- install_dependencies
132+
requires:
133+
- install_dependencies
134+
- benchmark:
135+
requires:
136+
- install_dependencies
129137

130138
jobs:
131139
install_ruby:
@@ -221,3 +229,15 @@ jobs:
221229
- start_services:
222230
services: redis-master twemproxy redis-shard1 redis-shard2 redis-shard3
223231
- run_tests
232+
benchmark:
233+
executor:
234+
name: ubuntu_vm
235+
working_directory: ~/project
236+
environment:
237+
CONFIG_QUEUES_MASTER_NAME: redis://localhost:6379
238+
CONFIG_REDIS_PROXY: redis://localhost:6379
239+
steps:
240+
- *attach-to-workspace
241+
- start_services:
242+
services: redis-master
243+
- run_benchmark

bench/worker/worker_bench.rb

+27-16
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class WorkerBenchmark
77
def initialize
88
super
99
@async = ThreeScale::Backend.configuration.redis.async
10+
@nreports = ENV.fetch('NUM_REPORTS', "100000")
1011
end
1112

1213
def async?
@@ -55,6 +56,28 @@ def dup_resque_redis
5556
end
5657

5758
def run
59+
n_reports = @nreports.split(',').map(&:strip).map(&:to_i)
60+
61+
# Warming up...
62+
run_benchark(10000)
63+
64+
reports = n_reports.map { run_benchark(_1) }
65+
66+
print_reports reports
67+
end
68+
69+
def print_reports(reports)
70+
warn "=" * 70
71+
warn Benchmark::CAPTION
72+
73+
reports.each do |res, rss|
74+
warn res.format(Benchmark::Tms::FORMAT).chop + " #{rss}KB" + " (#{res.label})"
75+
end
76+
77+
warn "=" * 70
78+
end
79+
80+
def run_benchark(n_reports)
5881
new_worker # initialize worker to configure logging, good to improve that one day
5982
orig_log_level = Worker.logger.level
6083
Worker.logger.warn!
@@ -63,26 +86,14 @@ def run
6386
storage(true).flushdb
6487
seed_data
6588

66-
create_reports(10_000)
67-
Benchmark.measure('10k reports') do |x|
68-
clear_queue
69-
end
70-
71-
res = []
72-
create_reports(100_000)
73-
res << Benchmark.measure('100k reports') do |x|
89+
create_reports(n_reports)
90+
res = Benchmark.measure( "#{n_reports} reports") do |x|
7491
clear_queue
7592
end
7693

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

82-
warn "=" * 70
83-
warn Benchmark::CAPTION
84-
res.each { warn _1.format(Benchmark::Tms::FORMAT).chop + " (#{_1.label})" }
85-
warn "=" * 70
96+
[res, rss]
8697
ensure
8798
Worker.logger.level = orig_log_level if orig_log_level
8899
end

lib/3scale/tasks/connectivity.rake

+5-2
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@ namespace :connectivity do
3030
Async { ping(redis_instance, storage_type) }
3131
end
3232

33-
def ping(redis_instance, storage_type)
33+
def ping(redis_instance, storage_type, attempts = 3)
34+
attempts -= 1
3435
redis_instance.ping
3536
rescue => e
3637
warn "Error connecting to Redis #{storage_type}: #{e}"
37-
exit(false)
38+
exit(false) unless attempts > 0
39+
sleep 1
40+
retry
3841
else
3942
puts "Connection to Redis #{storage_type} performed successfully"
4043
end

script/benchmark

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
function wait_redis()
4+
{
5+
bundle exec rake connectivity:redis_storage_check
6+
bundle exec rake connectivity:redis_storage_queue_check
7+
}
8+
9+
function do_benchmark()
10+
{
11+
case $1 in
12+
sync)
13+
echo "==================== Running tests using the SYNC Redis driver ===================="
14+
CONFIG_REDIS_ASYNC=false bundle exec rake bench[worker/worker_bench.rb]
15+
;;
16+
async)
17+
echo "==================== Running tests using the ASYNC Redis driver ===================="
18+
CONFIG_REDIS_ASYNC=true bundle exec rake bench[worker/worker_bench.rb]
19+
;;
20+
*)
21+
echo "Invalid Redis driver option: $1"
22+
exit 1
23+
esac
24+
}
25+
26+
function run_benchmark()
27+
{
28+
export RACK_ENV=test
29+
30+
wait_redis
31+
32+
do_benchmark "sync" && do_benchmark "async"
33+
}
34+
35+
if ! run_benchmark; then
36+
echo "Tests failed" >&2
37+
exit 1
38+
fi

0 commit comments

Comments
 (0)