Module: Einhorn::WorkerPool

Defined in:
lib/einhorn/worker_pool.rb

Class Method Summary collapse

Class Method Details

.ack_countObject



48
49
50
# File 'lib/einhorn/worker_pool.rb', line 48

def self.ack_count
  acked_unsignaled_modern_workers.length
end

.ack_targetObject



52
53
54
# File 'lib/einhorn/worker_pool.rb', line 52

def self.ack_target
  Einhorn::State.config[:number]
end

.acked_modern_workersObject



27
28
29
# File 'lib/einhorn/worker_pool.rb', line 27

def self.acked_modern_workers
  acked_modern_workers_with_state.map {|pid, _| pid}
end

.acked_modern_workers_with_stateObject



19
20
21
# File 'lib/einhorn/worker_pool.rb', line 19

def self.acked_modern_workers_with_state
  modern_workers_with_state.select {|pid, spec| spec[:acked]}
end

.acked_unsignaled_modern_workersObject



31
32
33
34
35
# File 'lib/einhorn/worker_pool.rb', line 31

def self.acked_unsignaled_modern_workers
  acked_modern_workers_with_state.select do |_, spec|
    spec[:signaled].length == 0
  end.map {|pid, _| pid}
end

.missing_worker_countObject

Use the number of modern workers, rather than unsignaled modern workers. This means if e.g. we do bunch of decs and then incs, any workers which haven’t died yet will count towards our number of workers. Since workers really should be dying shortly after they are USR2’d, that indicates a bad state and we shouldn’t make it worse by spinning up more processes. Once they die, order will be restored.



44
45
46
# File 'lib/einhorn/worker_pool.rb', line 44

def self.missing_worker_count
  ack_target - modern_workers.length
end

.modern_workersObject



23
24
25
# File 'lib/einhorn/worker_pool.rb', line 23

def self.modern_workers
  modern_workers_with_state.map {|pid, _| pid}
end

.modern_workers_with_stateObject



13
14
15
16
17
# File 'lib/einhorn/worker_pool.rb', line 13

def self.modern_workers_with_state
  Einhorn::State.children.select do |pid, spec|
    spec[:version] == Einhorn::State.version
  end
end

.old_workersObject



56
57
58
# File 'lib/einhorn/worker_pool.rb', line 56

def self.old_workers
  unsignaled_workers - modern_workers
end

.unsignaled_workersObject



7
8
9
10
11
# File 'lib/einhorn/worker_pool.rb', line 7

def self.unsignaled_workers
  Einhorn::State.children.select do |pid, spec|
    spec[:signaled].length == 0
  end.map {|pid, _| pid}
end

.workersObject



3
4
5
# File 'lib/einhorn/worker_pool.rb', line 3

def self.workers
  Einhorn::State.children.keys
end