Sha256: 9e48d7b4823bf7b9bff756c127fec9e09761884a2fd5a3ddbc926dce1bb87ba6

Contents?: true

Size: 711 Bytes

Versions: 1

Compression:

Stored size: 711 Bytes

Contents

require 'delegate'

module PumaAutoTune

  class Memory
    attr_accessor :master, :workers

    def initialize(master = PumaAutoTune::Master.new)
      @master = master
    end

    def name
      "resource_ram_mb"
    end

    def amount
      @mb ||= begin
        worker_memory = workers.map {|w| w.memory }.inject(&:+) || 0
        worker_memory + @master.get_memory
      end
    end

    def largest_worker
      workers.last
    end

    def smallest_worker
      workers.first
    end

    def workers
      workers ||= @master.workers.sort_by! {|w| w.get_memory }
    end

    def reset
      raise "must set master" unless @master
      @workers      = nil
      @mb           = nil
    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/memory.rb