### Puma Worker Killer Debug Output Example Source: https://github.com/zombocom/puma_worker_killer/blob/main/README.md This is an example of the debug output you should see when Puma Worker Killer is enabled and functioning correctly. Ensure you are running with multiple workers. ```text [77773] Puma starting in cluster mode... [77773] * Version 3.1.0 (ruby 2.3.1-p112), codename: El NiƱo Winter Wonderland [77773] * Min threads: 0, max threads: 16 [77773] * Environment: development [77773] * Process workers: 2 [77773] * Phased restart available [77773] * Listening on tcp://0.0.0.0:9292 [77773] Use Ctrl-C to stop [77773] PumaWorkerKiller: Consuming 54.34765625 mb with master and 2 workers. ``` -------------------------------- ### Configure PumaWorkerKiller with a block Source: https://github.com/zombocom/puma_worker_killer/blob/main/README.md Configure PumaWorkerKiller settings like RAM limits, frequency, and custom pre-termination actions using a configuration block before starting the killer. ```ruby PumaWorkerKiller.config do |config| config.ram = 1024 # mb config.frequency = 5 # seconds config.percent_usage = 0.98 config.rolling_restart_frequency = 12 * 3600 # 12 hours in seconds, or 12.hours if using Rails config.reaper_status_logs = true # setting this to false will not log lines like: # PumaWorkerKiller: Consuming 54.34765625 mb with master and 2 workers. config.pre_term = -> (worker) { puts "Worker #{worker.inspect} being killed" } config.rolling_pre_term = -> (worker) { puts "Worker #{worker.inspect} being killed by rolling restart" } end PumaWorkerKiller.start ``` -------------------------------- ### Enable Puma Worker Killer Source: https://github.com/zombocom/puma_worker_killer/blob/main/README.md Place this code in your `config/puma.rb` file to enable the Puma Worker Killer. It starts the killer before forking Puma workers. ```ruby # config/puma.rb before_fork do require 'puma_worker_killer' PumaWorkerKiller.start end ``` -------------------------------- ### Enable Rolling Restarts with Custom Frequency Source: https://github.com/zombocom/puma_worker_killer/blob/main/README.md Customize the rolling restart frequency by passing the desired interval in seconds to `PumaWorkerKiller.enable_rolling_restart`. This example sets the restart interval to 12 hours. ```ruby PumaWorkerKiller.enable_rolling_restart(12 * 3600) # 12 hours in seconds ``` -------------------------------- ### Configure Puma Worker Killer in puma.rb Source: https://github.com/zombocom/puma_worker_killer/blob/main/README.md Integrate PumaWorkerKiller configuration directly into your puma.rb file using the before_fork block. This ensures settings are applied before worker processes are spawned. ```ruby before_fork do PumaWorkerKiller.config do |config| config.ram = 1024 # mb config.frequency = 5 # seconds config.percent_usage = 0.98 config.rolling_restart_frequency = 12 * 3600 # 12 hours in seconds, or 12.hours if using Rails end PumaWorkerKiller.start end ``` -------------------------------- ### Set Available RAM for Puma Worker Killer Source: https://github.com/zombocom/puma_worker_killer/blob/main/README.md Specify the total RAM available to your system in megabytes. This is crucial for the killer to accurately assess memory usage. The default is 512 MB. ```ruby PumaWorkerKiller.ram = 1024 # mb ``` -------------------------------- ### Enable Rolling Restarts in Puma Configuration Source: https://github.com/zombocom/puma_worker_killer/blob/main/README.md Configure Puma to enable rolling restarts using PumaWorkerKiller. This is done in the `config/puma.rb` file before forking workers. The default restart frequency is every 6 hours. ```ruby # config/puma.rb before_fork do require 'puma_worker_killer' PumaWorkerKiller.enable_rolling_restart # Default is every 6 hours end ``` -------------------------------- ### Add Puma Worker Killer to Gemfile Source: https://github.com/zombocom/puma_worker_killer/blob/main/README.md Add this line to your Gemfile to include the puma_worker_killer gem in your project. ```ruby gem 'puma_worker_killer' ``` -------------------------------- ### Set Percent Usage Threshold for Puma Worker Killer Source: https://github.com/zombocom/puma_worker_killer/blob/main/README.md Define the memory utilization percentage that triggers the worker killer. The default is 99%, meaning processes are killed when nearing full RAM capacity to prevent swapping. ```ruby PumaWorkerKiller.percent_usage = 0.98 ``` -------------------------------- ### Configure Rolling Restart Frequency for Puma Worker Killer Source: https://github.com/zombocom/puma_worker_killer/blob/main/README.md Set the interval for periodically restarting all worker processes. This can be specified in seconds or using Rails' time helpers (e.g., 12.hours). The default is every 6 hours. Set to `false` to disable. ```ruby PumaWorkerKiller.rolling_restart_frequency = 12 * 3600 # 12 hours in seconds, or 12.hours if using Rails ``` -------------------------------- ### Puma Worker Count Indicator Source: https://github.com/zombocom/puma_worker_killer/blob/main/README.md This output indicates that Puma is running with multiple workers, which is a prerequisite for Puma Worker Killer to function. ```text [77773] * Process workers: 2 ``` -------------------------------- ### Adjust Puma Worker Killer Check Frequency Source: https://github.com/zombocom/puma_worker_killer/blob/main/README.md Control how often the worker killer checks for memory usage. Set this value in seconds to tune how frequently the killer runs. ```ruby PumaWorkerKiller.frequency = 20 # seconds ``` -------------------------------- ### Disable Puma Worker Killer Status Logs Source: https://github.com/zombocom/puma_worker_killer/blob/main/README.md Control whether log lines indicating memory consumption by PumaWorkerKiller are displayed. Set to `false` to hide these logs; they are `true` by default. ```ruby PumaWorkerKiller.reaper_status_logs = false ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.