-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEBUG-2647 Run multiple Ruby micro-benchmark files (#3810)
- Loading branch information
Showing
14 changed files
with
166 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# `datadog` Benchmarks | ||
|
||
## Adding a New Benchmark File | ||
|
||
1. Use one of the following prefixes: | ||
|
||
- `library_` | ||
- `profiling_` | ||
- `tracing_` | ||
|
||
2. Add the new file to `run_all.sh` in this directory. | ||
|
||
3. Depending on the prefix, add the new file to the correct | ||
`validate_benchmarks_spec.rb` as follows: | ||
|
||
- `library_` prefix: `spec/validate_benchmarks_spec.rb` | ||
- `profiling_` prefix: `./spec/datadog/profiling/validate_benchmarks_spec.rb` | ||
- `tracing_` prefix: `./spec/datadog/tracing/validate_benchmarks_spec.rb` | ||
|
||
## Adding Benchmarks For a New Product | ||
|
||
1. Create a `validate_benchmarks_spec.rb` test in the product subdirectory, | ||
using the existing files as a template. | ||
|
||
2. Update this README to add the new product in the previous section. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Used to quickly run benchmark under RSpec as part of the usual test suite, to validate it didn't bitrot | ||
VALIDATE_BENCHMARK_MODE = ENV['VALIDATE_BENCHMARK'] == 'true' | ||
|
||
return unless __FILE__ == $PROGRAM_NAME || VALIDATE_BENCHMARK_MODE | ||
|
||
require 'open3' | ||
|
||
class GemLoadingBenchmark | ||
def benchmark_gem_loading | ||
# This benchmark needs to be run in a clean environment where datadog is | ||
# not loaded yet. | ||
# | ||
# Now that this benchmark is in its own file, it does not need | ||
# to spawn a subprocess IF we would always execute this benchmark | ||
# file by itself. | ||
output, status = Open3.capture2e('bundle', 'exec', 'ruby', stdin_data: <<-RUBY) | ||
raise "Datadog is already loaded" if defined?(::Datadog::Core) | ||
lib = File.expand_path('../lib', '#{__dir__}') | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
VALIDATE_BENCHMARK_MODE = #{VALIDATE_BENCHMARK_MODE} | ||
require 'benchmark/ips' | ||
Benchmark.ips do |x| | ||
# Gem loading is quite slower than the other microbenchmarks | ||
benchmark_time = VALIDATE_BENCHMARK_MODE ? { time: 0.001, warmup: 0 } : { time: 60, warmup: 5 } | ||
x.config(**benchmark_time) | ||
x.report("Gem loading") do | ||
pid = fork { require 'datadog' } | ||
_, status = Process.wait2(pid) | ||
raise unless status.success? | ||
end | ||
x.save! "#{__FILE__}-results.json" unless VALIDATE_BENCHMARK_MODE | ||
x.compare! | ||
end | ||
RUBY | ||
|
||
print output | ||
|
||
raise "Benchmark failed with status #{status}: #{output}" unless status.success? | ||
end | ||
end | ||
|
||
puts "Current pid is #{Process.pid}" | ||
|
||
GemLoadingBenchmark.new.instance_exec do | ||
benchmark_gem_loading | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/sh | ||
|
||
# This script is invoked by benchmarking-platform shell scripts | ||
# to run all of the benchmarks defined in the tracer. | ||
|
||
set -ex | ||
|
||
for file in \ | ||
`dirname "$0"`/library_gem_loading.rb \ | ||
`dirname "$0"`/profiler_allocation.rb \ | ||
`dirname "$0"`/profiler_gc.rb \ | ||
`dirname "$0"`/profiler_hold_resume_interruptions.rb \ | ||
`dirname "$0"`/profiler_http_transport.rb \ | ||
`dirname "$0"`/profiler_memory_sample_serialize.rb \ | ||
`dirname "$0"`/profiler_sample_loop_v2.rb \ | ||
`dirname "$0"`/profiler_sample_serialize.rb \ | ||
`dirname "$0"`/tracing_trace.rb; | ||
do | ||
bundle exec ruby "$file" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe 'Library benchmarks' do | ||
before { skip('Spec requires Ruby VM supporting fork') unless PlatformHelpers.supports_fork? } | ||
|
||
around do |example| | ||
ClimateControl.modify('VALIDATE_BENCHMARK' => 'true') do | ||
example.run | ||
end | ||
end | ||
|
||
benchmarks_to_validate = %w[ | ||
library_gem_loading | ||
] | ||
|
||
benchmarks_to_validate.each do |benchmark| | ||
describe benchmark do | ||
it 'runs without raising errors' do | ||
expect_in_fork do | ||
load "./benchmarks/#{benchmark}.rb" | ||
end | ||
end | ||
end | ||
end | ||
|
||
# This test validates that we don't forget to add new benchmarks to benchmarks_to_validate | ||
it 'tests all expected benchmarks in the benchmarks folder' do | ||
all_benchmarks = Dir['./benchmarks/library_*'].map { |it| it.gsub('./benchmarks/', '').gsub('.rb', '') } | ||
|
||
expect(benchmarks_to_validate).to contain_exactly(*all_benchmarks) | ||
end | ||
end |