百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

sidekiq-worker-killer

> 后端框架
开源

杀死贪婪的 Sidekiq 进程

174 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

杀死贪婪的 Sidekiq 进程

sidekiq-worker-killer

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.


NOTE

This gem needs to get the used memory of the Sidekiq process. For this we use GetProcessGem, but be aware that if you are running Sidekiq in Heroku(or any container) the memory usage will not be accurate.


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

Install

Use Bundler

ruby
gem "sidekiq-worker-killer"

Usage

Add this to your Sidekiq configuration.

ruby
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 used by the Sidekiq process. 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.
on_shutdown nil Executes a block of code before just before requesting shutdown. This can be used to send custom logs or metrics to external services.

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

ruby
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:

bash
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

Issues· 3 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubyrubyruby-on-railssidekiq

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架