{"id":16643405,"url":"https://github.com/sonots/resque-worker-killer","last_synced_at":"2025-03-21T15:32:31.293Z","repository":{"id":56891999,"uuid":"66023243","full_name":"sonots/resque-worker-killer","owner":"sonots","description":"Automatically kill a child of reque worker based on max memory","archived":false,"fork":false,"pushed_at":"2024-03-13T13:36:52.000Z","size":12,"stargazers_count":11,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-14T23:14:24.820Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sonots.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-08-18T19:01:24.000Z","updated_at":"2024-03-15T16:46:15.000Z","dependencies_parsed_at":"2024-10-31T23:45:14.565Z","dependency_job_id":null,"html_url":"https://github.com/sonots/resque-worker-killer","commit_stats":{"total_commits":9,"total_committers":1,"mean_commits":9.0,"dds":0.0,"last_synced_commit":"5230bb1b7f94787f6d89b0c3b74905a2a4115817"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonots%2Fresque-worker-killer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonots%2Fresque-worker-killer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonots%2Fresque-worker-killer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonots%2Fresque-worker-killer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sonots","download_url":"https://codeload.github.com/sonots/resque-worker-killer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244822738,"owners_count":20516156,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-12T08:08:24.201Z","updated_at":"2025-03-21T15:32:30.990Z","avatar_url":"https://github.com/sonots.png","language":"Ruby","readme":"# Resque::Worker::Killer\n\n[Resque](https://github.com/resque/resque) is widely used Redis-backed Ruby library for creating background jobs. One thing we thought Resque missed, is killing a forked child of Resque worker based on consumed memories.\n\nresque-worker-killer gem provides automatic kill of a forked child of Resque worker based on process memory size (RSS) not to exceed the maximum allowed memory size.\n\nThe name was inspired by [unicorn-worker-killer](https://github.com/kzk/unicorn-worker-killer) :-p\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'resque-worker-killer'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install resque-worker-killer\n\n## Usage\n\nUse the plugin:\n\n```ruby\nrequire 'resque'\nrequire 'resque-worker-killer'\n\nclass MyJob\n  extend Resque::Plugins::WorkerKiller\n  @queue = :example_queue\n\n  extend Resque::Plugins::WorkerKiller\n  @worker_killer_monitor_interval = 0.5 # sec\n  @worker_killer_mem_limit = 300_000 # KB\n  @worker_killer_max_term = 10 # try TERM 10 times, then KILL\n  @worker_killer_verbose = false # verbose log\n  @worker_killer_logger = Resque.logger\n\n  def self.perform(*args)\n    puts 'started'\n    sleep 10\n    puts 'finished'\n  rescue Resque::TermException =\u003e e # env TERM_CHILD=1\n    puts 'terminated'\n  end\nend\n```\n\n### TERM_CHILD=1\n\nResque requires to set `TERM_CHILD` environment variable to accept killing a forked child with SIGTERM.\n\n```\n$ TERM_CHILD=1 bundle exec rake resque:work\n```\nThus,\n\n* Without `TERM_CHILD=1`, set `@worker_killter_max_term = 0` to send SIGKILL immediately\n* With `TERM_CHILD=1`, set `@worker_killer_max_term \u003e 0` to try SIGTERM first, then SIGKILL\n\nWith `TERM_CHILD=1`, `Resque::TermException` is raised if a forked child is killed by SIGTERM.\n\n## Options\n\nOptions are:\n\n* `@worker_killer_monitor_interval`: Monotring interval to check RSS size (default: 1.0 sec)\n* `@worker_killer_mem_limit`: RSS usage limit, in killobytes (default: 300MB)\n* `@worker_killer_max_term`: Try kiling child process with SIGTERM in `max_term` times, then SIGKILL if it still does not die. \n  Please note that setting `TERM_CHILD` environment variable is required to accept killing the child with SIGTERM.\n  The default is, 10 with `TERM_CHILD=1`, 0 without `TERM_CHILD=1`.\n* `@worker_killer_verbose`: Verbose log\n* `@worker_killer_logger`: Logger instance (default: Resque.logger)\n\n## NOTE\n\nIt is known that this gem has somewhat poor compatibility with [resque-jobs-per-fork](https://github.com/samgranieri/resque-jobs-per-fork), which enables to have workers perform more than one job, before terminating \n\nThink of JOBS_PER_FORK=3, it usually works as follows:\n\n```\n10:00:00.40000 PID-14056 1st JOB: Started\n10:00:00.60000 PID-14056 1st JOB: Finished\n10:00:00.60000 PID-14056 2nd JOB: Started\n10:00:01.30000 PID-14056 2nd JOB: Finished\n10:00:01.30000 PID-14056 3rd JOB: Started\n10:00:01.60000 PID-14056 3rd JOB: Finished\n10:00:01.60000 PID-14057 4th JOB: Started\n10:00:01.70000 PID-14057 4th JOB: Finished\n```\n\nThink of Resque::Worker::Killer with `@worker_killer_monitor_interval = 1.0`, it would work as follows:\n\n```\n10:00:00.40000 PID-14056 1st JOB: Started\n10:00:00.60000 PID-14056 1st JOB: Finished\n10:00:00.60000 PID-14056 2nd JOB: Started\n10:00:01.30000 PID-14056 2nd JOB: Finished \u003c= 2nd Job consumed lots of memory\n10:00:01.30000 PID-14056 3rd JOB: Started\n10:00:01.40000 PID-14056 WorkerKiller: Monitors memory size, and kill\n```\n\nThe 2nd job consumed lots of memory, but 3rd job is killed.\nTo avoid such situation, just stop using resque-jobs-per-fork with this plugin.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/sonots/resque-worker-killer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n## ChangeLog\n\n[CHANGELOG.md](./CHANGELOG.md)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsonots%2Fresque-worker-killer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsonots%2Fresque-worker-killer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsonots%2Fresque-worker-killer/lists"}