Sha256: bcd58c4e8eb9b382698391037af04b85c7c42bb977045f1815921e06b9e3b133

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

require 'get_process_mem'

module PumaWorkerKiller
  extend self

  attr_accessor :ram, :frequency, :percent_usage, :rolling_restart_frequency
  self.ram           = 512  # mb
  self.frequency     = 10   # seconds
  self.percent_usage = 0.99 # percent of RAM to use
  self.rolling_restart_frequency = 6 * 3600

  def config
    yield self
  end

  def reaper(ram = self.ram, percent = self.percent_usage)
    Reaper.new(ram * percent_usage)
  end

  def start(frequency = self.frequency, reaper = self.reaper)
    AutoReap.new(frequency, reaper).start
    enable_rolling_restart(rolling_restart_frequency) if rolling_restart_frequency
  end

  def enable_rolling_restart(frequency = self.rolling_restart_frequency)
    frequency = frequency + rand(0..10.0) # so all workers don't restart at the exact same time across multiple machines
    AutoReap.new(frequency, RollingRestart.new).start
  end
end

require 'puma_worker_killer/puma_memory'
require 'puma_worker_killer/reaper'
require 'puma_worker_killer/rolling_restart'
require 'puma_worker_killer/auto_reap'
require 'puma_worker_killer/version'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
puma_worker_killer-0.0.5 lib/puma_worker_killer.rb
puma_worker_killer-0.0.4 lib/puma_worker_killer.rb