Class: Master::Process

Inherits:
Base
  • Object
show all
Defined in:
lib/spark/worker/master.rb

Overview

Worker::Process

Constant Summary

Constants included from Spark::Constant

Spark::Constant::ACCUMULATOR_ACK, Spark::Constant::CREATE_WORKER, Spark::Constant::DATA_EOF, Spark::Constant::KILL_WORKER, Spark::Constant::KILL_WORKER_AND_WAIT, Spark::Constant::SUCCESSFULLY_KILLED, Spark::Constant::UNSUCCESSFUL_KILLING, Spark::Constant::WORKER_DONE, Spark::Constant::WORKER_ERROR

Instance Method Summary collapse

Methods inherited from Base

#initialize, #kill_worker_and_wait, #receive_message, #run

Constructor Details

This class inherits a constructor from Master::Base

Instance Method Details

#_fork?Boolean

Returns:

  • (Boolean)


98
99
100
101
102
103
104
105
106
# File 'lib/spark/worker/master.rb', line 98

def _fork?
  return false if !::Process.respond_to?(:fork)

  pid = ::Process.fork
  exit unless pid # exit the child immediately
  true
rescue NotImplementedError
  false
end

#create_workerObject



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/spark/worker/master.rb', line 74

def create_worker
  if fork?
    pid = ::Process.fork do
      Worker::Process.new(@port).run
    end
  else
    pid = ::Process.spawn("ruby #{@worker_arguments} worker.rb #{@port}")
  end

  # Detach child from master to avoid zombie process
  ::Process.detach(pid)
end

#fork?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/spark/worker/master.rb', line 94

def fork?
  @can_fork ||= _fork?
end

#kill_workerObject



87
88
89
90
91
92
# File 'lib/spark/worker/master.rb', line 87

def kill_worker
  worker_id = @socket.read_long
  ::Process.kill('TERM', worker_id)
rescue
  nil
end