Sha256: fd774ee8ee4f1d47d6950707ee105101fc93a35e848f313026f32d7b4881cf09

Contents?: true

Size: 946 Bytes

Versions: 1

Compression:

Stored size: 946 Bytes

Contents

module PumaAutoTune
  class Master
  def initialize(master = nil)
      @master = master || get_master
    end

    def running?
      @master && workers.any?
    end

    # https://github.com/puma/puma/blob/master/docs/signals.md#puma-signals
    def remove_worker
      send_signal("TTOU")
    end

    # https://github.com/puma/puma/blob/master/docs/signals.md#puma-signals
    def add_worker
      send_signal("TTIN")
    end

    # less cryptic interface
    def send_signal(signal, pid = Process.pid)
      Process.kill(signal, pid)
    end

    def memory
      @memory
    end
    alias :mb :memory

    def get_memory
      @memory = ::GetProcessMem.new(Process.pid).mb
    end

    def workers
      @master.instance_variable_get("@workers").map {|w| PumaAutoTune::Worker.new(w) }
    end

    private

    def get_master
      ObjectSpace.each_object(Puma::Cluster).map { |obj| obj }.first if defined?(Puma::Cluster)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
puma_auto_tune-0.0.1 lib/puma_auto_tune/master.rb