Sha256: f84b26577bb51fc7127a9eb7c28d7f7dcde741d5277edb0596675c194428db29

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

require 'get_process_mem'

module PumaWorkerKiller
  extend self

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

  def config
    yield self
  end

  def reaper(ram = self.ram, percent = self.percent_usage, reaper_status_logs = self.reaper_status_logs)
    Reaper.new(ram * percent_usage, nil, reaper_status_logs)
  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

1 entries across 1 versions & 1 rubygems

Version Path
puma_worker_killer-0.0.7 lib/puma_worker_killer.rb