Class: TheMechanic2::RailsRunnerService

Inherits:
Object
  • Object
show all
Defined in:
lib/the_mechanic_2/rails_runner_service.rb

Overview

Service for spawning Rails runner processes to execute benchmark code Each benchmark runs in a completely isolated Rails environment

Defined Under Namespace

Classes: BenchmarkError, BenchmarkTimeout

Instance Method Summary collapse

Instance Method Details

#execute(code:, shared_setup: nil, timeout: 30) ⇒ Hash

Executes benchmark code in a separate Rails runner process

Parameters:

  • code (String)

    The Ruby code to benchmark

  • shared_setup (String) (defaults to: nil)

    Optional setup code to run before benchmark

  • timeout (Integer) (defaults to: 30)

    Maximum execution time in seconds

Returns:

  • (Hash)

    Benchmark results with IPS, memory, and other metrics



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/the_mechanic_2/rails_runner_service.rb', line 20

def execute(code:, shared_setup: nil, timeout: 30)
  script_file = create_script(code, shared_setup)
  
  begin
    stdout, stderr, status = spawn_runner(script_file.path, timeout)
    parse_output(stdout, stderr, status)
  ensure
    script_file.close
    script_file.unlink
  end
end