Class: Perfgate::Execution::ProcessRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/perfgate/execution/process_runner.rb

Overview

Runs a workload's warmup + samples inside a fresh child process (spec section 12.1: default "process_per_workload" isolation). The child relays its result to the parent as JSON over a pipe -- Marshal is deliberately avoided per the project's cross-process serialization policy (data crossing a process boundary must not be able to instantiate arbitrary Ruby objects).

Note for database-backed workloads: an in-memory SQLite database does not survive fork (each child effectively starts with an empty database), so process isolation requires a file-based or server-based test database. This mirrors an existing constraint on Rails' own parallel test runners and isn't specific to Baseline.

Instance Method Summary collapse

Constructor Details

#initialize(workload, runner_class: Runner) ⇒ ProcessRunner

Returns a new instance of ProcessRunner.



21
22
23
24
# File 'lib/perfgate/execution/process_runner.rb', line 21

def initialize(workload, runner_class: Runner)
  @workload = workload
  @runner_class = runner_class
end

Instance Method Details

#callObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/perfgate/execution/process_runner.rb', line 26

def call
  ensure_fork_supported!

  reader, writer = IO.pipe
  pid = fork_child(reader, writer)
  writer.close
  payload = reader.read
  reader.close
  _pid, status = Process.waitpid2(pid)

  parse_result(payload, status)
end