worker_killer 0.1.1.39838 → 1.0.0.39839
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +54 -25
- data/lib/worker_killer/delayed_job_plugin.rb +16 -0
- data/lib/worker_killer/middleware.rb +2 -2
- data/lib/worker_killer/version.rb +1 -1
- data/spec/support/logger.rb +2 -2
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c2cabf961e621ef921c3f5d8ce24ef87c49248c0c0c93fa7141431df5e208ce
|
4
|
+
data.tar.gz: 7022f38e793bd749a3ca88d9b3b641c70a5009a00921652322a71e41f0be5df5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e8ff2b3c4dcf2a926160dcee34c4c051565ac9084c8ec8317a84172d0555739121650bda21e2ce4b09b82038bd6cb37f799cd872be7c37d52fab62e3aefb03f
|
7
|
+
data.tar.gz: a443e0c89295e33f85d8563fb3f9fd3fe8e692dd4fc2cfa4ae9d9c378edf7aaefda77b0458c95fb6221b810edd4386c1700af167c0f747a006a33981920a95c0
|
data/README.md
CHANGED
@@ -4,69 +4,98 @@
|
|
4
4
|
[![Gem](https://img.shields.io/gem/dt/worker_killer.svg)](https://rubygems.org/gems/worker_killer/versions)
|
5
5
|
[![YARD](https://badgen.net/badge/YARD/doc/blue)](http://www.rubydoc.info/gems/worker_killer)
|
6
6
|
|
7
|
-
[![Coverage](https://lysander.
|
8
|
-
[![Quality](https://lysander.
|
9
|
-
[![Outdated](https://lysander.
|
10
|
-
[![Vulnerabilities](https://lysander.
|
7
|
+
[![Coverage](https://lysander.rnds.pro/api/v1/badges/wkiller_coverage.svg)](https://lysander.rnds.pro/api/v1/badges/wkiller_coverage.html)
|
8
|
+
[![Quality](https://lysander.rnds.pro/api/v1/badges/wkiller_quality.svg)](https://lysander.rnds.pro/api/v1/badges/wkiller_quality.html)
|
9
|
+
[![Outdated](https://lysander.rnds.pro/api/v1/badges/wkiller_outdated.svg)](https://lysander.rnds.pro/api/v1/badges/wkiller_outdated.html)
|
10
|
+
[![Vulnerabilities](https://lysander.rnds.pro/api/v1/badges/wkiller_vulnerable.svg)](https://lysander.rnds.pro/api/v1/badges/wkiller_vulnerable.html)
|
11
11
|
|
12
12
|
Kill any workers by memory and/or request counts or take custom reaction. Inspired by [unicorn-worker-killer](https://github.com/kzk/unicorn-worker-killer).
|
13
13
|
|
14
|
-
`worker-killer` gem provides automatic restart of Web-server based on 1) max number of requests, and 2) process memory size (RSS). This will greatly improves site's stability by avoiding unexpected memory exhaustion at the application nodes.
|
14
|
+
`worker-killer` gem provides automatic restart of Web-server and/or background job processor based on 1) max number of requests, and 2) process memory size (RSS). This will greatly improves site's stability by avoiding unexpected memory exhaustion at the application nodes.
|
15
15
|
|
16
16
|
Features:
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
Planned:
|
23
|
-
|
24
|
-
* DelayedJob support
|
18
|
+
- generic middleware implementation
|
19
|
+
- Phusion Passenger support(through `passenger-config detach-process <PID>`)
|
20
|
+
- DelayedJob support
|
21
|
+
- custom reaction hook
|
25
22
|
|
26
23
|
# Install
|
27
24
|
|
28
25
|
No external process like `god` is required. Just install one gem: `worker-killer`.
|
26
|
+
|
29
27
|
```ruby
|
30
28
|
gem 'worker-killer'
|
31
29
|
```
|
32
30
|
|
33
31
|
# Usage
|
34
32
|
|
35
|
-
|
33
|
+
## Rack-based Web-server
|
34
|
+
|
35
|
+
Add these lines to your `config.ru` or `application.rb`. (These lines should be added above the `require ::File.expand_path('../config/environment', __FILE__)` line.
|
36
36
|
|
37
37
|
```ruby
|
38
38
|
# self-process killer
|
39
39
|
require 'worker_killer/middleware'
|
40
|
-
|
40
|
+
|
41
|
+
killer = WorkerKiller::Killer::Passenger.new
|
42
|
+
|
41
43
|
# Max requests per worker
|
42
|
-
|
43
|
-
|
44
|
+
middleware.insert_before(
|
45
|
+
Rack::Sendfile,
|
46
|
+
WorkerKiller::Middleware::RequestsLimiter, killer: killer, min: 3072, max: 4096
|
47
|
+
)
|
48
|
+
|
44
49
|
# Max memory size (RSS) per worker
|
45
|
-
|
50
|
+
middleware.insert_before(
|
51
|
+
Rack::Sendfile,
|
52
|
+
WorkerKiller::Middleware::OOMLimiter, killer: killer, min: 500 * (1024**2), max: 600 * (1024**2)
|
53
|
+
)
|
46
54
|
```
|
47
55
|
|
48
|
-
|
56
|
+
## DelayedJob background processor
|
49
57
|
|
50
|
-
|
58
|
+
Add these lines to your `initializers/delayed_job.rb` or `application.rb`.
|
51
59
|
|
52
|
-
|
60
|
+
```ruby
|
61
|
+
# self-process killer
|
62
|
+
require 'worker_killer/delayed_job_plugin'
|
63
|
+
|
64
|
+
Delayed::Worker.plugins.tap do |plugins|
|
65
|
+
plugins << Gorynich::Head::DelayedJob
|
66
|
+
killer = WorkerKiller::Killer::DelayedJob.new
|
67
|
+
|
68
|
+
plugins << WorkerKiller::DelayedJobPlugin::JobsLimiter.new(
|
69
|
+
killer: killer, min: 200, max: 300
|
70
|
+
)
|
71
|
+
|
72
|
+
plugins << WorkerKiller::DelayedJobPlugin::OOMLimiter.new(
|
73
|
+
killer: killer, min: 500 * (1024**2), max: 600 * (1024**2)
|
74
|
+
)
|
75
|
+
end
|
76
|
+
```
|
77
|
+
|
78
|
+
This gem provides two modules: WorkerKiller::CountLimiter and WorkerKiller::MemoryLimiter, some Rack integration and DelayedJob plugin.
|
79
|
+
|
80
|
+
### WorkerKiller::Middleware::RequestsLimiter and WorkerKiller::DelayedJobPlugin::JobsLimiter
|
81
|
+
|
82
|
+
This module automatically restarts/kills the workers, based on the number of requests/jobs which worker processed.
|
53
83
|
|
54
84
|
`min` and `max` specify the min and max of maximum requests per worker. The actual limit is decided by rand() between `min` and `max` per worker, to prevent all workers to be dead at the same time. Once the number exceeds the limit, that worker is automatically restarted.
|
55
85
|
|
56
|
-
If `verbose` is set to true, then after every request, your log will show the requests left before restart.
|
86
|
+
If `verbose` is set to true, then after every request, your log will show the requests left before restart. This logging is done at the `info` level.
|
57
87
|
|
58
|
-
### WorkerKiller::Middleware::OOMLimiter
|
88
|
+
### WorkerKiller::Middleware::OOMLimiter and WorkerKiller::DelayedJobPlugin::OOMLimiter
|
59
89
|
|
60
90
|
This module automatically restarts/kills the workers, based on its memory size.
|
61
91
|
|
62
|
-
`min` and `max` specify the min and max of maximum memory in bytes per worker. The actual limit is decided by rand() between `min` and `max` per worker, to prevent all workers to be dead at the same time.
|
92
|
+
`min` and `max` specify the min and max of maximum memory in bytes per worker. The actual limit is decided by rand() between `min` and `max` per worker, to prevent all workers to be dead at the same time. Once the memory size exceeds `memory_size`, that worker is automatically restarted.
|
63
93
|
|
64
94
|
The memory size check is done in every `check_cycle` requests.
|
65
95
|
|
66
|
-
If `verbose` is set to true, then every memory size check will be shown in your logs.
|
96
|
+
If `verbose` is set to true, then every memory size check will be shown in your logs. This logging is done at the `info` level.
|
67
97
|
|
68
98
|
# Special Thanks
|
69
99
|
|
70
100
|
- [@hotchpotch](http://github.com/hotchpotch/) for the [original idea](https://gist.github.com/hotchpotch/1258681)
|
71
101
|
- [@kzk](http://github.com/kzk/) for the [unicorn-worker-killer](https://github.com/kzk/unicorn-worker-killer)
|
72
|
-
|
@@ -26,6 +26,22 @@ module WorkerKiller
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
class JobsLimiter < ::WorkerKiller::DelayedJobPlugin
|
30
|
+
|
31
|
+
def initialize(**opts)
|
32
|
+
super(klass: ::WorkerKiller::CountLimiter, **opts)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
class OOMLimiter < ::WorkerKiller::DelayedJobPlugin
|
38
|
+
|
39
|
+
def initialize(**opts)
|
40
|
+
super(klass: ::WorkerKiller::MemoryLimiter, **opts)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
29
45
|
end
|
30
46
|
end
|
31
47
|
|
data/spec/support/logger.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
RSpec.configure do |config|
|
2
2
|
config.before(:suite) do
|
3
3
|
$logger = Logger.new(STDOUT).tap do |logger|
|
4
|
-
logger.progname =
|
5
|
-
logger.level =
|
4
|
+
logger.progname = 'WorkerKiller'
|
5
|
+
logger.level = 'ERROR'
|
6
6
|
end
|
7
7
|
WorkerKiller.configure do |cfg|
|
8
8
|
cfg.logger = $logger
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: worker_killer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0.39839
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samoilenko Yuri
|
@@ -169,13 +169,13 @@ signing_key:
|
|
169
169
|
specification_version: 4
|
170
170
|
summary: Kill any workers by memory and request counts or take custom reaction
|
171
171
|
test_files:
|
172
|
-
- spec/
|
173
|
-
- spec/
|
174
|
-
- spec/
|
172
|
+
- spec/support/logger.rb
|
173
|
+
- spec/count_limiter_spec.rb
|
174
|
+
- spec/worker_killer_spec.rb
|
175
175
|
- spec/killer/passenger_spec.rb
|
176
|
-
- spec/killer/signal_spec.rb
|
177
176
|
- spec/killer/delayed_job_spec.rb
|
177
|
+
- spec/killer/signal_spec.rb
|
178
|
+
- spec/middleware_spec.rb
|
179
|
+
- spec/spec_helper.rb
|
178
180
|
- spec/memory_limiter_spec.rb
|
179
|
-
- spec/
|
180
|
-
- spec/worker_killer_spec.rb
|
181
|
-
- spec/count_limiter_spec.rb
|
181
|
+
- spec/killer_spec.rb
|