Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shayonj/sidekiq_process_killer
SidekiqProcessKiller plugs into Sidekiq's middleware and kills a process (by sending SIGTERM) if its processing beyond the supplied RSS threshold.
https://github.com/shayonj/sidekiq_process_killer
Last synced: 16 days ago
JSON representation
SidekiqProcessKiller plugs into Sidekiq's middleware and kills a process (by sending SIGTERM) if its processing beyond the supplied RSS threshold.
- Host: GitHub
- URL: https://github.com/shayonj/sidekiq_process_killer
- Owner: shayonj
- License: mit
- Created: 2017-10-26T06:32:08.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-28T19:03:10.000Z (over 5 years ago)
- Last Synced: 2024-04-25T07:01:16.958Z (7 months ago)
- Language: Ruby
- Homepage:
- Size: 20.5 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# SidekiqProcessKiller
[![Build Status](https://travis-ci.org/shayonj/sidekiq_process_killer.svg?branch=master)](https://travis-ci.org/shayonj/sidekiq_process_killer)
When you have memory leaks or "bloats" in your ruby application, identifying and fixing them can at times be a nightmare. Instead, an _"acceptable"_ mitigation is to re-spin the workers. Its a common technique that can be found in [Puma Worker Killer](https://github.com/schneems/puma_worker_killer) or [Unicorn Worker Killer](https://github.com/kzk/unicorn-worker-killer). Though, its neater and good practice to find and fix your leaks.
SidekiqProcessKiller plugs into Sidekiq's middleware and kills a process (by sending `SIGTERM`) if its processing beyond the supplied [RSS](https://en.wikipedia.org/wiki/Resident_set_size) threshold. Since this plugs into the middleware, the check is performed after each job.
## Installation
```ruby
gem "sidekiq_process_killer"
```## Usage
### Configuration
```ruby
memory_threshold: 250.0 # mb
silent_mode: false
statsd_klass: nil
```| Config name | Description |
|------------------------- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `silent_mode` | When set to `true`, no signal will be sent to running process. This is helpful if you are planning to launch this, but want to first do a dry run.
| `memory_threshold` | When current RSS is above this threshold, the respective Sidekiq worker will be instructed for termination (via `TERM` signal, which sidekiq gracefully exits). |
| `statsd_klass` | This is a class object which responds to an `increment`. If present, the `increment` function will be called with a single argument of type `Hash` which contains, `metric_name`, `worker_name` and `current_memory_usage`. This class is called when attempting to terminate a process or if the process had to be forcefully be terminated. |### Updating default configuration:
```ruby
class CustomMetric
...def increment(params)
StatsD.count(
params[:metric_name],
tags: {
worker_name: params[:worker_name]
}
)
end...
endSidekiqProcessKiller.config do |con|
con.memory_threshold = 1024.0
con.silent_mode = false
con.statsd_klass = CustomMetric.new # your custom statsd class object
end
```### Turn on SidekiqProcessKiller
Just plugin the Middleware
```ruby
Sidekiq.configure_server do |config|
config.server_middleware do |chain|
chain.add SidekiqProcessKiller::Middleware
end
end
```The class tries to log as much as possible, as best as possible.