worker_killer 0.0.9.19836 → 0.1.0.19839
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -16
- data/lib/worker-killer.rb +2 -1
- data/lib/worker_killer/version.rb +5 -2
- data/spec/middleware_spec.rb +2 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87ac13b4bd486015cd2e99a580fa311878b094b2dd621351c7b8997c476a50ff
|
4
|
+
data.tar.gz: 5635186d2b8cf8d7b25d72c639733ca603afea7406f3d0bb7e172ff7d52d941d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e72c3f683cc72d7e18937ec6cc2ae66281149418dad1dc26f1649a6a62f92009d15f643c292cb79a445b867d2305fae5198a8721a1a2b92350346f7f6d070bd
|
7
|
+
data.tar.gz: 85c8cd4872a38b99d2aed420ba52c69f14746e86d2ff12d61103c79b96c40fc35fb46770ac79f15f3b6d672d4857f2c15d44388efc052b0017bb494d3ea644e7
|
data/README.md
CHANGED
@@ -1,43 +1,52 @@
|
|
1
|
-
#
|
1
|
+
# worker-killer
|
2
2
|
|
3
|
-
|
3
|
+
Kill any workers by memory and request counts or take custom reaction. Inspired by [unicorn-worker-killer](https://github.com/kzk/unicorn-worker-killer).
|
4
4
|
|
5
|
-
`
|
5
|
+
`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.
|
6
|
+
|
7
|
+
Features:
|
8
|
+
|
9
|
+
* generic middleware implementation
|
10
|
+
* custom reactin hook
|
11
|
+
|
12
|
+
Planned:
|
13
|
+
|
14
|
+
* DelayedJob support
|
6
15
|
|
7
16
|
# Install
|
8
17
|
|
9
|
-
No external process like `god` is required. Just install one gem: `
|
18
|
+
No external process like `god` is required. Just install one gem: `worker-killer`.
|
10
19
|
|
11
|
-
gem '
|
20
|
+
gem 'worker-killer'
|
12
21
|
|
13
22
|
# Usage
|
14
23
|
|
15
|
-
Add these lines to your `config.ru`. (These lines should be added above the `require ::File.expand_path('../config/environment', __FILE__)` line.
|
24
|
+
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.
|
16
25
|
|
17
|
-
#
|
18
|
-
require '
|
26
|
+
# self-process killer
|
27
|
+
require 'worker_killer/middleware'
|
19
28
|
|
20
29
|
# Max requests per worker
|
21
|
-
|
30
|
+
config.middleware.insert_before(Rack::Sendfile, WorkerKiller::Middleware::RequestsLimiter, min: 4096, max: 5120)
|
22
31
|
|
23
32
|
# Max memory size (RSS) per worker
|
24
|
-
|
33
|
+
config.middleware.insert_before(Rack::Sendfile, WorkerKiller::Middleware::OOMLimiter, min: 300 * (1024**2), max: 400 * (1024**2))
|
25
34
|
|
26
|
-
This gem provides two modules.
|
35
|
+
This gem provides two modules: WorkerKiller::CountLimiter and WorkerKiller::MemoryLimiter and some Rack integration.
|
27
36
|
|
28
|
-
### `
|
37
|
+
### `WorkerKiller::Middleware::RequestsLimiter`
|
29
38
|
|
30
|
-
This module automatically restarts the
|
39
|
+
This module automatically restarts the kill workers, based on the number of requests which worker processed.
|
31
40
|
|
32
|
-
`
|
41
|
+
`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.
|
33
42
|
|
34
43
|
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.
|
35
44
|
|
36
|
-
### `
|
45
|
+
### `WorkerKiller::Middleware::OOMLimiter`
|
37
46
|
|
38
47
|
This module automatically restarts the Unicorn workers, based on its memory size.
|
39
48
|
|
40
|
-
`
|
49
|
+
`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.
|
41
50
|
|
42
51
|
The memory size check is done in every `check_cycle` requests.
|
43
52
|
|
@@ -46,4 +55,5 @@ If `verbose` is set to true, then every memory size check will be shown in your
|
|
46
55
|
# Special Thanks
|
47
56
|
|
48
57
|
- [@hotchpotch](http://github.com/hotchpotch/) for the [original idea](https://gist.github.com/hotchpotch/1258681)
|
58
|
+
- [@kzk](http://github.com/kzk/) for the [unicorn-worker-killer](https://github.com/kzk/unicorn-worker-killer)
|
49
59
|
|
data/lib/worker-killer.rb
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
require 'worker_killer'
|
1
|
+
require 'worker_killer'
|
2
|
+
|
data/spec/middleware_spec.rb
CHANGED
@@ -19,7 +19,7 @@ RSpec.describe WorkerKiller::Middleware do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
describe WorkerKiller::Middleware::RequestsLimiter do
|
22
|
-
let(:options){ {reaction: reaction, min: 1111 } }
|
22
|
+
let(:options){ { reaction: reaction, min: 1111 } }
|
23
23
|
subject{ described_class.new(app, options) }
|
24
24
|
|
25
25
|
it 'is expected to be initialized with reaction' do
|
@@ -31,7 +31,7 @@ RSpec.describe WorkerKiller::Middleware do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
describe WorkerKiller::Middleware::OOMLimiter do
|
34
|
-
let(:options){ {reaction: reaction, min: 2222 } }
|
34
|
+
let(:options){ { reaction: reaction, min: 2222 } }
|
35
35
|
subject{ described_class.new(app, options) }
|
36
36
|
|
37
37
|
it 'is expected to be initialized with reaction' do
|
@@ -41,6 +41,5 @@ RSpec.describe WorkerKiller::Middleware do
|
|
41
41
|
expect(subject.limiter.reaction).to eq(reaction)
|
42
42
|
end
|
43
43
|
end
|
44
|
-
|
45
44
|
end
|
46
45
|
|