Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 60 lines (50 sloc) 1.66 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
module Einhorn
  module WorkerPool
    def self.workers
      Einhorn::State.children.keys
    end

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

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

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

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

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

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

    # 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.
    def self.missing_worker_count
      ack_target - modern_workers.length
    end

    def self.ack_count
      acked_unsignaled_modern_workers.length
    end

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

    def self.old_workers
      unsignaled_workers - modern_workers
    end
  end
end
Something went wrong with that request. Please try again.