Giter VIP home page Giter VIP logo

sidekiq-worker-killer's Introduction

sidekiq-worker-killer

Gem Version CircleCI

Sidekiq is probably the best background processing framework today. At the same time, memory leaks are very hard to tackle in Ruby and we often find ourselves with growing memory consumption. Instead of spending herculean effort fixing leaks, why not kill your processes when they got to be too large?

Highly inspired by Gitlab Sidekiq MemoryKiller and Noxa Sidekiq killer.

quick-refs: install | usage | available options | development

Install

Use Bundler

gem "sidekiq-worker-killer"

Usage

Add this to your Sidekiq configuration.

require 'sidekiq/worker_killer'

Sidekiq.configure_server do |config|
  config.server_middleware do |chain|
    chain.add Sidekiq::WorkerKiller, max_rss: 480
  end
end

Available options

The following options can be overridden.

Option Defaults Description
max_rss 0 MB (disabled) Max RSS in megabytes. Above this, shutdown will be triggered.
grace_time 900 seconds When shutdown is triggered, the Sidekiq process will not accept new job and wait at most 15 minutes for running jobs to finish. If Float::INFINITY specified, will wait forever.
shutdown_wait 30 seconds When the grace time expires, still running jobs get 30 seconds to stop. After that, kill signal is triggered.
kill_signal SIGKILL Signal to use to kill Sidekiq process if it doesn't stop.
gc true Try to run garbage collection before Sidekiq process stops in case of exceeded max_rss.
skip_shutdown_if proc {false} Executes a block of code after max_rss exceeds but before requesting shutdown.

skip_shutdown_if is expected to return anything other than false or nil to skip shutdown.

require 'sidekiq/worker_killer'

Sidekiq.configure_server do |config|
  config.server_middleware do |chain|
    chain.add Sidekiq::WorkerKiller, max_rss: 480, skip_shutdown_if: ->(worker, job, queue) do
      worker.to_s == 'LongWorker'
    end
  end
end

Development

Pull Requests are very welcome!

There are tasks that may help you along the way in a makefile:

make console # Loads the whole stack in an IRB session.
make test # Run tests.
make lint # Run rubocop linter.

Please make sure that you have tested your code carefully before opening a PR, and make sure as well that you have no style issues.

Authors

See the list of contributors who participated in this project.

License

Please see LICENSE

sidekiq-worker-killer's People

Contributors

ccyrille avatar buonomo avatar briansfma avatar msxavi avatar igel avatar ben-j69 avatar corerabbit avatar maximeflips avatar leemour avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.