From 52cd3e4757ba556b4f7da7f4e45fcc73583ed90b Mon Sep 17 00:00:00 2001 From: Ben Sheldon Date: Thu, 21 Jan 2021 19:45:18 -0800 Subject: [PATCH] Add scripts directory for benchmarking and dev tasks --- Gemfile | 2 ++ Gemfile.lock | 7 +++++++ scripts/benchmark_scheduler.rb | 23 +++++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 scripts/benchmark_scheduler.rb diff --git a/Gemfile b/Gemfile index c17c221b6..1aa5929ef 100644 --- a/Gemfile +++ b/Gemfile @@ -15,6 +15,8 @@ gem 'activerecord-jdbcpostgresql-adapter', platforms: [:jruby] gem 'pg', platforms: [:mri, :mingw, :x64_mingw] platforms :ruby do + gem "memory_profiler" + gem "pry-byebug" gem "rbtrace" group :lint do diff --git a/Gemfile.lock b/Gemfile.lock index fa4caa351..e2e59a861 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -60,6 +60,7 @@ GEM parser (>= 2.4) smart_properties builder (3.2.4) + byebug (11.1.3) capybara (3.34.0) addressable mini_mime (>= 0.1.3) @@ -123,6 +124,7 @@ GEM mixlib-cli (~> 2.1, >= 2.1.1) mixlib-config (>= 2.2.1, < 4) mixlib-shellout + memory_profiler (1.0.0) method_source (1.0.0) mini_mime (1.0.2) mini_portile2 (2.5.0) @@ -157,6 +159,9 @@ GEM coderay (~> 1.1) method_source (~> 1.0) spoon (~> 0.0) + pry-byebug (3.9.0) + byebug (~> 11.0) + pry (~> 0.13.0) pry-rails (0.3.9) pry (>= 0.10.4) public_suffix (4.0.6) @@ -271,7 +276,9 @@ DEPENDENCIES kramdown kramdown-parser-gfm mdl + memory_profiler pg + pry-byebug pry-rails puma rbtrace diff --git a/scripts/benchmark_scheduler.rb b/scripts/benchmark_scheduler.rb new file mode 100644 index 000000000..bb0d975b6 --- /dev/null +++ b/scripts/benchmark_scheduler.rb @@ -0,0 +1,23 @@ +# +# $ bundle exec ruby scripts/benchmark_scheduler.rb +# +require 'memory_profiler' +require_relative '../lib/good_job' + +class Performer + def name + '' + end + + def next + sleep 0.1 + end +end + +scheduler = GoodJob::Scheduler.new(Performer.new, max_threads: 5) + +report = MemoryProfiler.report do + 10_000.times { scheduler.create_thread } +end + +report.pretty_print