Skip to content

Commit

Permalink
tweak more things to get it all to work
Browse files Browse the repository at this point in the history
  • Loading branch information
jamis committed Jan 23, 2024
1 parent 555a843 commit 8d561e6
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,10 @@ functions:
working_dir: "src"
script: |
${PREPARE_SHELL}
TEST_CMD="bundle exec rake driver_bench" .evergreen/run-tests.sh
TEST_CMD="bundle exec rake driver_bench" PERFORMANCE_RESULTS_FILE="$PROJECT_DIRECTORY/perf.json" .evergreen/run-tests.sh
- command: perf.send
params:
file: ./results.json
file: "${PROJECT_DIRECTORY}/perf.json"

"run tests":
- command: shell.exec
Expand Down
4 changes: 2 additions & 2 deletions .evergreen/config/common.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,10 @@ functions:
working_dir: "src"
script: |
${PREPARE_SHELL}
TEST_CMD="bundle exec rake driver_bench" .evergreen/run-tests.sh
TEST_CMD="bundle exec rake driver_bench" PERFORMANCE_RESULTS_FILE="$PROJECT_DIRECTORY/perf.json" .evergreen/run-tests.sh
- command: perf.send
params:
file: ./results.json
file: "${PROJECT_DIRECTORY}/perf.json"

"run tests":
- command: shell.exec
Expand Down
16 changes: 11 additions & 5 deletions profile/driver_bench/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def run_benchmark

loop do
before_task
timing = without_gc { Benchmark.realtime { debug_mode? ? sleep(0.1) : do_task } }
timing = consider_gc { Benchmark.realtime { debug_mode? ? sleep(0.1) : do_task } }
after_task

iteration_count += 1
Expand All @@ -111,12 +111,18 @@ def new_client(uri = ENV['MONGODB_URI'])
Mongo::Client.new(uri)
end

# Runs a given block with GC disabled.
def without_gc
GC.disable
# Takes care of garbage collection considerations before
# running the block.
#
# Set BENCHMARK_NO_GC environment variable to suppress GC during
# the core benchmark tasks; note that this may result in obscure issues
# due to memory pressures on larger benchmarks.
def consider_gc
GC.start
GC.disable if ENV['BENCHMARK_NO_GC']
yield
ensure
GC.enable
GC.enable if ENV['BENCHMARK_NO_GC']
end

# By default, the file name is assumed to be relative to the
Expand Down
7 changes: 5 additions & 2 deletions profile/driver_bench/multi_doc/find_many.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ def file_name
def setup
super

docs = Array.new(10_000) { dataset.first }
@collection.insert_many(docs)
prototype = dataset.first
10.times do
docs = Array.new(1000, prototype)
@collection.insert_many(docs)
end
end

def do_task
Expand Down
6 changes: 4 additions & 2 deletions profile/driver_bench/single_doc/find_one_by_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ def file_name
def setup
super

docs = Array.new(10_000) { |i| dataset.merge(_id: i + 1) }
@collection.insert_many(docs)
10.times do |i|
docs = Array.new(1000) { |j| dataset.merge(_id: (i * 1000) + j + 1) }
@collection.insert_many(docs)
end
end

def do_task
Expand Down
34 changes: 22 additions & 12 deletions profile/driver_bench/suite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,21 @@ def run_benchmark(klass)
end

def compile_perf_data(result)
percentile_data = PERCENTILES.each_with_object({}) do |n, hash|
hash["time-#{n}%"] = result[:percentiles][n]
percentile_data = PERCENTILES.map do |percentile|
{ 'name' => "time-#{percentile}%",
'value' => result[:percentiles][percentile] }
end

{
'info' => {
'test_name' => result[:name],
'args' => {},
},
'metrics' => percentile_data.merge('score' => result[:score]),
'metrics' => [
{ 'name' => 'score',
'value' => result[:score] },
*percentile_data
]
}
end

Expand All @@ -105,27 +110,32 @@ def compile_benchmarks(benches)
'test_name' => bench,
'args' => {}
},
'metrics' => {
'score' => score
}
'metrics' => [
{ 'name' => 'score',
'value' => score }
]
}
end
end

# rubocop:disable Metrics/AbcSize
def summarize_perf_data(data)
puts '===== Performance Results ====='
data.each do |item|
puts format('%s : %4.4g', item['info']['test_name'], item['metrics']['score'])
next unless item['metrics']['time-10%']
puts format('%s : %4.4g', item['info']['test_name'], item['metrics'][0]['value'])
next unless item['metrics'].length > 1

PERCENTILES.each do |n|
puts format(' %d%% : %4.4g', n, item['metrics']["time-#{n}%"])
item['metrics'].each do |metric|
next if metric['name'] == 'score'

puts format(' %s : %4.4g', metric['name'], metric['value'])
end
end
end
# rubocop:enable Metrics/AbcSize

def save_perf_data(data)
File.write('results.json', data.to_json)
def save_perf_data(data, file_name: ENV['PERFORMANCE_RESULTS_FILE'] || 'results.json')
File.write(file_name, data.to_json)
end
end
end
Expand Down

0 comments on commit 8d561e6

Please sign in to comment.