Class: RocketJob::Batch::Performance
- Inherits:
-
Object
- Object
- RocketJob::Batch::Performance
- Defined in:
- lib/rocket_job/batch/performance.rb
Instance Attribute Summary collapse
-
#compress ⇒ Object
Returns the value of attribute compress.
-
#count ⇒ Object
Returns the value of attribute count.
-
#encrypt ⇒ Object
Returns the value of attribute encrypt.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#mongo_config ⇒ Object
Returns the value of attribute mongo_config.
-
#ruby ⇒ Object
Returns the value of attribute ruby.
-
#servers ⇒ Object
Returns the value of attribute servers.
-
#slice_size ⇒ Object
Returns the value of attribute slice_size.
-
#version ⇒ Object
Returns the value of attribute version.
-
#workers ⇒ Object
Returns the value of attribute workers.
Instance Method Summary collapse
- #count_running_workers ⇒ Object
-
#export_results(results) ⇒ Object
Export the Results hash to a CSV file.
-
#initialize ⇒ Performance
constructor
A new instance of Performance.
-
#parse(argv) ⇒ Object
Parse command line options.
- #run_test_case(count = self.count) ⇒ Object
Constructor Details
#initialize ⇒ Performance
Returns a new instance of Performance.
9 10 11 12 13 14 15 16 |
# File 'lib/rocket_job/batch/performance.rb', line 9 def initialize @count = 10_000_000 @environment = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development' @mongo_config = 'config/mongoid.yml' @compress = false @encrypt = false @slice_size = 1000 end |
Instance Attribute Details
#compress ⇒ Object
Returns the value of attribute compress.
7 8 9 |
# File 'lib/rocket_job/batch/performance.rb', line 7 def compress @compress end |
#count ⇒ Object
Returns the value of attribute count.
7 8 9 |
# File 'lib/rocket_job/batch/performance.rb', line 7 def count @count end |
#encrypt ⇒ Object
Returns the value of attribute encrypt.
7 8 9 |
# File 'lib/rocket_job/batch/performance.rb', line 7 def encrypt @encrypt end |
#environment ⇒ Object
Returns the value of attribute environment.
7 8 9 |
# File 'lib/rocket_job/batch/performance.rb', line 7 def environment @environment end |
#mongo_config ⇒ Object
Returns the value of attribute mongo_config.
7 8 9 |
# File 'lib/rocket_job/batch/performance.rb', line 7 def mongo_config @mongo_config end |
#ruby ⇒ Object
Returns the value of attribute ruby.
7 8 9 |
# File 'lib/rocket_job/batch/performance.rb', line 7 def ruby @ruby end |
#servers ⇒ Object
Returns the value of attribute servers.
7 8 9 |
# File 'lib/rocket_job/batch/performance.rb', line 7 def servers @servers end |
#slice_size ⇒ Object
Returns the value of attribute slice_size.
7 8 9 |
# File 'lib/rocket_job/batch/performance.rb', line 7 def slice_size @slice_size end |
#version ⇒ Object
Returns the value of attribute version.
7 8 9 |
# File 'lib/rocket_job/batch/performance.rb', line 7 def version @version end |
#workers ⇒ Object
Returns the value of attribute workers.
7 8 9 |
# File 'lib/rocket_job/batch/performance.rb', line 7 def workers @workers end |
Instance Method Details
#count_running_workers ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/rocket_job/batch/performance.rb', line 86 def count_running_workers self.servers = 0 self.workers = 0 RocketJob::Server.running.each do |server| next if server.zombie? self.servers += 1 self.workers += server.heartbeat.workers end puts "Running: #{workers} workers, distributed across #{servers} servers" end |
#export_results(results) ⇒ Object
Export the Results hash to a CSV file
46 47 48 49 50 51 52 53 54 |
# File 'lib/rocket_job/batch/performance.rb', line 46 def export_results(results) ruby = defined?(JRuby) ? "jruby_#{JRUBY_VERSION}" : "ruby_#{RUBY_VERSION}" version = RocketJob::VERSION CSV.open("job_results_#{ruby}_v#{version}.csv", 'wb') do |csv| csv << results.first.keys results.each { |result| csv << result.values } end end |
#parse(argv) ⇒ Object
Parse command line options
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/rocket_job/batch/performance.rb', line 57 def parse(argv) parser = OptionParser.new do |o| o.on('-c', '--count COUNT', 'Count of records to enqueue') do |arg| self.count = arg.to_i end o.on('-m', '--mongo MONGO_CONFIG_FILE_NAME', 'Location of mongoid.yml config file') do |arg| self.mongo_config = arg end o.on('-e', '--environment ENVIRONMENT', 'The environment to run the app on (Default: RAILS_ENV || RACK_ENV || development)') do |arg| self.environment = arg end o.on('-z', '--compress', 'Turn on compression') do |arg| self.compress = true end o.on('-E', '--encrypt', 'Turn on encryption') do |arg| self.encrypt = true end o.on('-s', '--slice_size COUNT', 'Slice size') do |arg| self.slice_size = arg.to_i end end parser. = 'rocketjob_batch_perf <options>' parser.on_tail '-h', '--help', 'Show help' do puts parser exit 1 end parser.parse! argv end |
#run_test_case(count = self.count) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rocket_job/batch/performance.rb', line 18 def run_test_case(count = self.count) servers = RocketJob::Server.count raise 'Please start workers before starting the performance test' if servers == 0 count_running_workers puts "Loading job with #{count} records/lines" args = {log_level: :warn, slice_size: slice_size} if defined?(::RocketJob::Enterprise) args[:compress] = compress args[:encrypt] = encrypt end job = RocketJob::Jobs::PerformanceJob.new(args) job.upload do |writer| count.times { |i| writer << i } end job.save! puts 'Waiting for job to complete' while (!job.reload.completed?) sleep 3 end duration = job.completed_at - job.started_at {count: count, duration: duration, records_per_second: (count.to_f / duration).round(3), workers: workers, servers: servers, compress: compress, encrypt: encrypt} end |