sidekiq_process_killer 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +9 -12
- data/lib/sidekiq_process_killer/middleware.rb +5 -29
- data/lib/sidekiq_process_killer/version.rb +1 -1
- data/lib/sidekiq_process_killer.rb +1 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e33b6c981e60c62cb2d759e7477282962d48e20
|
4
|
+
data.tar.gz: be03799031354434d562e4095dc31b4fc31d7572
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b87f6986e8ce7f86ee9410cbd1346aa7aa0fc86d9f46906704ae6cacb65669d5635559740ca7e881b9f99674108b1d957abdfc39beafd2ae36fd550dd259dd1
|
7
|
+
data.tar.gz: 42b3a2cfab92aff9b5c08dc28035589360571cdf0b99aab7efd4e0c5ab3ea928d9c0bf404fbd4dbe377c4b849163ef4cbc05418ed0c53432c5e4282f616a1e76
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
When you have memory leaks or "bloats" in your ruby application, identifying and fixing them can at times be a nightmare. Instead, an _"acceptable"_ mitigation is to re-spin the workers. Its a common technique that can be found in [Puma Worker Killer](https://github.com/schneems/puma_worker_killer) or [Unicorn Worker Killer](https://github.com/kzk/unicorn-worker-killer). Though, its neater and good practice to find and fix your leaks.
|
6
6
|
|
7
|
-
SidekiqProcessKiller plugs into Sidekiq's middleware and kills a process if its processing beyond the supplied [RSS](https://en.wikipedia.org/wiki/Resident_set_size) threshold. Since this plugs into the middleware, the check is performed after each job.
|
7
|
+
SidekiqProcessKiller plugs into Sidekiq's middleware and kills a process (by sending `SIGTERM`) if its processing beyond the supplied [RSS](https://en.wikipedia.org/wiki/Resident_set_size) threshold. Since this plugs into the middleware, the check is performed after each job.
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -20,22 +20,21 @@ Add the following to your Gemfile
|
|
20
20
|
|
21
21
|
### Configuration
|
22
22
|
|
23
|
-
The default configurations are:
|
24
23
|
|
25
24
|
```ruby
|
26
25
|
memory_threshold: 250.0 # mb
|
27
|
-
shutdown_wait_timeout: 25 # seconds
|
28
|
-
shutdown_signal: "SIGKILL"
|
29
26
|
silent_mode: false
|
30
27
|
statsd_klass: nil
|
31
28
|
```
|
32
29
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
30
|
+
|
31
|
+
|
32
|
+
| Config name | Description |
|
33
|
+
|------------------------- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
34
|
+
| `silent_mode` | When set to `true`, no signal will be sent to running process. This is helpful if you are planning to launch this, but want to first do a dry run.
|
35
|
+
| `memory_threshold` | When current RSS is above this threshold, the respective Sidekiq worker will be instructed for termination (via `TERM` signal, which sidekiq gracefully exits). |
|
36
|
+
| `statsd_klass` | This is a class object which responds to an `increment`. If present, the `increment` function will be called with a single argument of type `Hash` which contains, `metric_name`, `worker_name` and `current_memory_usage`. This class is called when attempting to terminate a process or if the process had to be forcefully be terminated. |
|
37
|
+
|
39
38
|
|
40
39
|
### Updating default configuration:
|
41
40
|
|
@@ -57,8 +56,6 @@ end
|
|
57
56
|
|
58
57
|
SidekiqProcessKiller.config do |con|
|
59
58
|
con.memory_threshold = 1024.0
|
60
|
-
con.shutdown_wait_timeout = 60
|
61
|
-
con.shutdown_signal = "SIGUSR2"
|
62
59
|
con.silent_mode = false
|
63
60
|
con.statsd_klass = CustomMetric.new # your custom statsd class object
|
64
61
|
end
|
@@ -18,32 +18,12 @@ module SidekiqProcessKiller
|
|
18
18
|
return if memory_threshold > memory
|
19
19
|
|
20
20
|
log_warn("Breached RSS threshold at #{memory_threshold}. Sending TERM Signal.")
|
21
|
-
|
21
|
+
increment_statsd({
|
22
|
+
metric_name: "process.term.signal.sent",
|
23
|
+
worker_name: worker.class,
|
24
|
+
current_memory_usage: memory
|
25
|
+
})
|
22
26
|
send_signal("SIGTERM", pid)
|
23
|
-
sleep(SidekiqProcessKiller.shutdown_wait_timeout)
|
24
|
-
|
25
|
-
shutdown_signal = SidekiqProcessKiller.shutdown_signal
|
26
|
-
|
27
|
-
begin
|
28
|
-
::Process.getpgid(pid)
|
29
|
-
log_warn("Forcefully killing process with #{shutdown_signal}.")
|
30
|
-
|
31
|
-
increment_statsd({
|
32
|
-
metric_name: "process.killed.forcefully",
|
33
|
-
worker_name: worker.class,
|
34
|
-
current_memory_usage: memory
|
35
|
-
})
|
36
|
-
|
37
|
-
send_signal(shutdown_signal, pid)
|
38
|
-
rescue Errno::ESRCH
|
39
|
-
log_warn("Process killed successfully.")
|
40
|
-
|
41
|
-
increment_statsd({
|
42
|
-
metric_name: "process.killed.successfully",
|
43
|
-
worker_name: worker.class,
|
44
|
-
current_memory_usage: memory
|
45
|
-
})
|
46
|
-
end
|
47
27
|
end
|
48
28
|
|
49
29
|
private def process_memory
|
@@ -66,10 +46,6 @@ module SidekiqProcessKiller
|
|
66
46
|
Sidekiq.logger.warn("[#{LOG_PREFIX}]#{silent_mode_msg} #{msg} #{humanized_attributes}")
|
67
47
|
end
|
68
48
|
|
69
|
-
private def log_info(msg)
|
70
|
-
Sidekiq.logger.info("[#{LOG_PREFIX}]#{silent_mode_msg} #{msg} #{humanized_attributes}")
|
71
|
-
end
|
72
|
-
|
73
49
|
private def send_signal(name, pid)
|
74
50
|
return if SidekiqProcessKiller.silent_mode
|
75
51
|
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module SidekiqProcessKiller
|
2
2
|
extend self
|
3
3
|
|
4
|
-
attr_accessor :
|
4
|
+
attr_accessor :silent_mode, :statsd_klass
|
5
5
|
|
6
|
-
self.shutdown_wait_timeout = 25 # seconds
|
7
|
-
self.shutdown_signal = "SIGKILL"
|
8
6
|
self.silent_mode = false
|
9
7
|
self.statsd_klass = nil
|
10
8
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq_process_killer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shayon Mukherjee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|