unicorn-worker-killer 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: 420acce9af285728e9a01073187ff9a30d04c59f
4
+ data.tar.gz: 3c64abf746d3b61cb62bffd8b9d504ec43ba62fb
5
+ !binary "U0hBNTEy":
6
+ metadata.gz: 5e3eb914600705eb38a473e6f87cab3433647be992248bffe1c4c4e6472cc03f689e34473dd087e72a359102d0d9979ab8773d347283722179f40ae8f0146f45
7
+ data.tar.gz: d094e7db25d113ff730551ac538b4ccee4dd0bea1ae65629ab36fee762bdddbf40ea8a0ef31e03430dabd4383d98fbac08273eba970b8dfc9fca69a669625427
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # unicorn-worker-killer
2
2
 
3
- [Unicorn](http://unicorn.bogomips.org/) is widely used HTTP-server for Rack applications. One thing we thought Unicorn misssed, is killing the Unicorn workers based on the number of requests and consumed memories.
3
+ [Unicorn](http://unicorn.bogomips.org/) is widely used HTTP-server for Rack applications. One thing we thought Unicorn missed, is killing the Unicorn workers based on the number of requests and consumed memories.
4
4
 
5
5
  `unicorn-worker-killer` gem provides automatic restart of Unicorn workers based on 1) max number of requests, and 2) process memory size (RSS), without affecting any requests. This will greatly improves site's stability by avoiding unexpected memory exhaustion at the application nodes.
6
6
 
@@ -12,7 +12,7 @@ No external process like `god` is required. Just install one gem: `unicorn-worke
12
12
 
13
13
  # Usage
14
14
 
15
- Add these lines to your `config.ru`.
15
+ Add these lines to your `config.ru`. (These lines should be added above the `require ::File.expand_path('../config/environment', __FILE__)` line.
16
16
 
17
17
  # Unicorn self-process killer
18
18
  require 'unicorn/worker_killer'
@@ -25,13 +25,15 @@ Add these lines to your `config.ru`.
25
25
 
26
26
  This gem provides two modules.
27
27
 
28
- ### Unicorn::WorkerKiller::MaxRequests(max_requests_min=3072, max_requests_max=4096)
28
+ ### Unicorn::WorkerKiller::MaxRequests(max_requests_min=3072, max_requests_max=4096, verbose=false)
29
29
 
30
30
  This module automatically restarts the Unicorn workers, based on the number of requests which worker processed.
31
31
 
32
32
  `max_requests_min` and `max_requests_max` specify the min and max of maximum requests per worker. The actual limit is decided by rand() between `max_requests_min` and `max_requests_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
33
 
34
- ### Unicorn::WorkerKiller::Oom(memory_limit_min=(1024**3), memory_limit_max=(2*(1024**3)), check_cycle = 16)
34
+ 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
+
36
+ ### Unicorn::WorkerKiller::Oom(memory_limit_min=(1024**3), memory_limit_max=(2*(1024**3)), check_cycle = 16, verbose = false)
35
37
 
36
38
  This module automatically restarts the Unicorn workers, based on its memory size.
37
39
 
@@ -39,5 +41,9 @@ This module automatically restarts the Unicorn workers, based on its memory size
39
41
 
40
42
  The memory size check is done in every `check_cycle` requests.
41
43
 
42
- # TODO
43
- - Get RSS (Resident Set Size) without forking the child process at Mac OS and Windows
44
+ 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.
45
+
46
+ # Special Thanks
47
+
48
+ - [@hotchpotch](http://github.com/hotchpotch/) for the [original idea](https://gist.github.com/hotchpotch/1258681)
49
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.2
@@ -31,13 +31,14 @@ module Unicorn::WorkerKiller
31
31
  # affect the request.
32
32
  #
33
33
  # @see https://github.com/defunkt/unicorn/blob/master/lib/unicorn/oob_gc.rb#L40
34
- def self.new(app, memory_limit_min = (1024**3), memory_limit_max = (2*(1024**3)), check_cycle = 16)
34
+ def self.new(app, memory_limit_min = (1024**3), memory_limit_max = (2*(1024**3)), check_cycle = 16, verbose = false)
35
35
  ObjectSpace.each_object(Unicorn::HttpServer) do |s|
36
36
  s.extend(self)
37
37
  s.instance_variable_set(:@_worker_memory_limit_min, memory_limit_min)
38
38
  s.instance_variable_set(:@_worker_memory_limit_max, memory_limit_max)
39
39
  s.instance_variable_set(:@_worker_check_cycle, check_cycle)
40
40
  s.instance_variable_set(:@_worker_check_count, 0)
41
+ s.instance_variable_set(:@_verbose, verbose)
41
42
  end
42
43
  app # pretend to be Rack middleware since it was in the past
43
44
  end
@@ -48,7 +49,6 @@ module Unicorn::WorkerKiller
48
49
 
49
50
  def process_client(client)
50
51
  super(client) # Unicorn::HttpServer#process_client
51
-
52
52
  return if @_worker_memory_limit_min == 0 && @_worker_memory_limit_max == 0
53
53
 
54
54
  @_worker_process_start ||= Time.now
@@ -57,6 +57,7 @@ module Unicorn::WorkerKiller
57
57
 
58
58
  if @_worker_check_count % @_worker_check_cycle == 0
59
59
  rss = _worker_rss()
60
+ logger.info "#{self}: worker (pid: #{Process.pid}) using #{rss} bytes." if @_verbose
60
61
  if rss > @_worker_memory_limit
61
62
  logger.warn "#{self}: worker (pid: #{Process.pid}) exceeds memory limit (#{rss} bytes > #{@_worker_memory_limit} bytes)"
62
63
  Unicorn::WorkerKiller.kill_self(logger, @_worker_process_start)
@@ -104,11 +105,12 @@ module Unicorn::WorkerKiller
104
105
  # affect the request.
105
106
  #
106
107
  # @see https://github.com/defunkt/unicorn/blob/master/lib/unicorn/oob_gc.rb#L40
107
- def self.new(app, max_requests_min = 3072, max_requests_max = 4096)
108
+ def self.new(app, max_requests_min = 3072, max_requests_max = 4096, verbose = false)
108
109
  ObjectSpace.each_object(Unicorn::HttpServer) do |s|
109
110
  s.extend(self)
110
111
  s.instance_variable_set(:@_worker_max_requests_min, max_requests_min)
111
112
  s.instance_variable_set(:@_worker_max_requests_max, max_requests_max)
113
+ s.instance_variable_set(:@_verbose, verbose)
112
114
  end
113
115
 
114
116
  app # pretend to be Rack middleware since it was in the past
@@ -125,6 +127,7 @@ module Unicorn::WorkerKiller
125
127
  @_worker_process_start ||= Time.now
126
128
  @_worker_cur_requests ||= @_worker_max_requests_min + randomize(@_worker_max_requests_max - @_worker_max_requests_min + 1)
127
129
  @_worker_max_requests ||= @_worker_cur_requests
130
+ logger.info "#{self}: worker (pid: #{Process.pid}) has #{@_worker_cur_requests} left before being killed" if @_verbose
128
131
 
129
132
  if (@_worker_cur_requests -= 1) <= 0
130
133
  logger.warn "#{self}: worker (pid: #{Process.pid}) exceeds max number of requests (limit: #{@_worker_max_requests})"
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unicorn-worker-killer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
5
- prerelease:
4
+ version: 0.4.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Kazuki Ohta
@@ -11,12 +10,11 @@ authors:
11
10
  autorequire:
12
11
  bindir: bin
13
12
  cert_chain: []
14
- date: 2013-03-15 00:00:00.000000000 Z
13
+ date: 2013-09-23 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: unicorn
18
17
  requirement: !ruby/object:Gem::Requirement
19
- none: false
20
18
  requirements:
21
19
  - - ~>
22
20
  - !ruby/object:Gem::Version
@@ -24,7 +22,6 @@ dependencies:
24
22
  type: :runtime
25
23
  prerelease: false
26
24
  version_requirements: !ruby/object:Gem::Requirement
27
- none: false
28
25
  requirements:
29
26
  - - ~>
30
27
  - !ruby/object:Gem::Version
@@ -32,7 +29,6 @@ dependencies:
32
29
  - !ruby/object:Gem::Dependency
33
30
  name: rake
34
31
  requirement: !ruby/object:Gem::Requirement
35
- none: false
36
32
  requirements:
37
33
  - - ! '>='
38
34
  - !ruby/object:Gem::Version
@@ -40,7 +36,6 @@ dependencies:
40
36
  type: :development
41
37
  prerelease: false
42
38
  version_requirements: !ruby/object:Gem::Requirement
43
- none: false
44
39
  requirements:
45
40
  - - ! '>='
46
41
  - !ruby/object:Gem::Version
@@ -66,26 +61,25 @@ files:
66
61
  - unicorn-worker-killer.gemspec
67
62
  homepage: https://github.com/kzk/unicorn-worker-killer
68
63
  licenses: []
64
+ metadata: {}
69
65
  post_install_message:
70
66
  rdoc_options: []
71
67
  require_paths:
72
68
  - lib
73
69
  required_ruby_version: !ruby/object:Gem::Requirement
74
- none: false
75
70
  requirements:
76
71
  - - ! '>='
77
72
  - !ruby/object:Gem::Version
78
73
  version: '0'
79
74
  required_rubygems_version: !ruby/object:Gem::Requirement
80
- none: false
81
75
  requirements:
82
76
  - - ! '>='
83
77
  - !ruby/object:Gem::Version
84
78
  version: '0'
85
79
  requirements: []
86
80
  rubyforge_project:
87
- rubygems_version: 1.8.24
81
+ rubygems_version: 2.0.3
88
82
  signing_key:
89
- specification_version: 3
83
+ specification_version: 4
90
84
  summary: Kill unicorn workers by memory and request counts
91
85
  test_files: []