[DRE-commits] [ruby-unicorn-worker-killer] 02/05: Imported Upstream version 0.4.4

Dmitry Smirnov onlyjob at moszumanska.debian.org
Tue Jul 26 01:11:56 UTC 2016


This is an automated email from the git hooks/post-receive script.

onlyjob pushed a commit to branch master
in repository ruby-unicorn-worker-killer.

commit d46889f
Author: Dmitry Smirnov <onlyjob at member.fsf.org>
Date:   Tue Jul 26 01:03:30 2016

    Imported Upstream version 0.4.4
---
 ChangeLog                                        |   9 ++
 README.md                                        |   6 +-
 VERSION                                          |   2 +-
 lib/unicorn/worker_killer.rb                     |  42 ++-------
 lib/unicorn/{ => worker_killer}/configuration.rb |   0
 metadata.yml                                     | 107 +++++++++++++++++++++++
 unicorn-worker-killer.gemspec                    |   4 +-
 7 files changed, 128 insertions(+), 42 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 78c0d99..bc05bcb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Release 0.4.4 - 2015/11/13
+  * update for Unicorn 5
+
+Release 0.4.3 - 2013/12/23
+  * fix for occasional 'invalid argument' error
+
+Release 0.4.2 - 2013/09/23
+  * `verbose` options provides verbose logging
+
 Release 0.4.1 - 2013/03/12
   * Kill attempts happen once per request, not in a loop
 
diff --git a/README.md b/README.md
index e676bde..d74fb0f 100644
--- a/README.md
+++ b/README.md
@@ -25,7 +25,7 @@ Add these lines to your `config.ru`. (These lines should be added above the `req
 
 This gem provides two modules.
 
-### Unicorn::WorkerKiller::MaxRequests(max_requests_min=3072, max_requests_max=4096, verbose=false)
+### `Unicorn::WorkerKiller::MaxRequests(max_requests_min=3072, max_requests_max=4096, verbose=false)`
 
 This module automatically restarts the Unicorn workers, based on the number of requests which worker processed.
 
@@ -33,11 +33,11 @@ This module automatically restarts the Unicorn workers, based on the number of r
 
 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.
 
-### Unicorn::WorkerKiller::Oom(memory_limit_min=(1024**3), memory_limit_max=(2*(1024**3)), check_cycle = 16, verbose = false)
+### `Unicorn::WorkerKiller::Oom(memory_limit_min=(1024\*\*3), memory_limit_max=(2\*(1024\*\*3)), check_cycle = 16, verbose = false)`
 
 This module automatically restarts the Unicorn workers, based on its memory size.
 
-`memory_limit_min` and `memory_limit_max` specify the min and max of maximum memory per worker. The actual limit is decided by rand() between `memory_limit_min` and `memory_limit_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.
+`memory_limit_min` and `memory_limit_max` specify the min and max of maximum memory in bytes per worker. The actual limit is decided by rand() between `memory_limit_min` and `memory_limit_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.
 
 The memory size check is done in every `check_cycle` requests.
 
diff --git a/VERSION b/VERSION
index 2b7c5ae..6f2743d 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.4.2
+0.4.4
diff --git a/lib/unicorn/worker_killer.rb b/lib/unicorn/worker_killer.rb
index dd59e82..389407c 100644
--- a/lib/unicorn/worker_killer.rb
+++ b/lib/unicorn/worker_killer.rb
@@ -1,4 +1,5 @@
-require 'unicorn/configuration'
+require 'unicorn/worker_killer/configuration'
+require 'get_process_mem'
 
 module Unicorn::WorkerKiller
   class << self
@@ -44,7 +45,7 @@ module Unicorn::WorkerKiller
     end
 
     def randomize(integer)
-      RUBY_VERSION > "1.9" ? Random.rand(integer) : rand(integer)
+      RUBY_VERSION > "1.9" ? Random.rand(integer.abs) : rand(integer)
     end
 
     def process_client(client)
@@ -54,9 +55,8 @@ module Unicorn::WorkerKiller
       @_worker_process_start ||= Time.now
       @_worker_memory_limit ||= @_worker_memory_limit_min + randomize(@_worker_memory_limit_max - @_worker_memory_limit_min + 1)
       @_worker_check_count += 1
-
       if @_worker_check_count % @_worker_check_cycle == 0
-        rss = _worker_rss()
+        rss = GetProcessMem.new.bytes
         logger.info "#{self}: worker (pid: #{Process.pid}) using #{rss} bytes." if @_verbose
         if rss > @_worker_memory_limit
           logger.warn "#{self}: worker (pid: #{Process.pid}) exceeds memory limit (#{rss} bytes > #{@_worker_memory_limit} bytes)"
@@ -65,38 +65,6 @@ module Unicorn::WorkerKiller
         @_worker_check_count = 0
       end
     end
-
-    private
-
-    def _worker_rss
-      proc_status = "/proc/#{Process.pid}/status"
-      if File.exists? proc_status
-        open(proc_status).each_line { |l|
-          if l.include? 'VmRSS'
-            ls = l.split
-            if ls.length == 3
-              value = ls[1].to_i
-              unit = ls[2]
-              case unit.downcase
-              when 'kb'
-                return value*(1024**1)
-              when 'mb'
-                return value*(1024**2)
-              when 'gb'
-                return value*(1024**3)
-              end
-            end
-          end
-        }
-      end
-
-      # Forking the child process sometimes fails under low memory condition.
-      # It would be ideal for not forking the process to get RSS. For Linux,
-      # this module reads '/proc/<pid>/status' to get RSS, but not for other
-      # environments (e.g. MacOS and Windows).
-      kb = `ps -o rss= -p #{Process.pid}`.to_i
-      return kb * 1024
-    end
   end
 
   module MaxRequests
@@ -117,7 +85,7 @@ module Unicorn::WorkerKiller
     end
 
     def randomize(integer)
-      RUBY_VERSION > "1.9" ? Random.rand(integer) : rand(integer)
+      RUBY_VERSION > "1.9" ? Random.rand(integer.abs) : rand(integer)
     end
 
     def process_client(client)
diff --git a/lib/unicorn/configuration.rb b/lib/unicorn/worker_killer/configuration.rb
similarity index 100%
rename from lib/unicorn/configuration.rb
rename to lib/unicorn/worker_killer/configuration.rb
diff --git a/metadata.yml b/metadata.yml
new file mode 100644
index 0000000..db7d636
--- /dev/null
+++ b/metadata.yml
@@ -0,0 +1,107 @@
+--- !ruby/object:Gem::Specification
+name: unicorn-worker-killer
+version: !ruby/object:Gem::Version
+  version: 0.4.4
+platform: ruby
+authors:
+- Kazuki Ohta
+- Sadayuki Furuhashi
+- Jonathan Clem
+autorequire: 
+bindir: bin
+cert_chain: []
+date: 2015-11-13 00:00:00.000000000 Z
+dependencies:
+- !ruby/object:Gem::Dependency
+  name: unicorn
+  requirement: !ruby/object:Gem::Requirement
+    requirements:
+    - - ">="
+      - !ruby/object:Gem::Version
+        version: '4'
+    - - "<"
+      - !ruby/object:Gem::Version
+        version: '6'
+  type: :runtime
+  prerelease: false
+  version_requirements: !ruby/object:Gem::Requirement
+    requirements:
+    - - ">="
+      - !ruby/object:Gem::Version
+        version: '4'
+    - - "<"
+      - !ruby/object:Gem::Version
+        version: '6'
+- !ruby/object:Gem::Dependency
+  name: get_process_mem
+  requirement: !ruby/object:Gem::Requirement
+    requirements:
+    - - "~>"
+      - !ruby/object:Gem::Version
+        version: '0'
+  type: :runtime
+  prerelease: false
+  version_requirements: !ruby/object:Gem::Requirement
+    requirements:
+    - - "~>"
+      - !ruby/object:Gem::Version
+        version: '0'
+- !ruby/object:Gem::Dependency
+  name: rake
+  requirement: !ruby/object:Gem::Requirement
+    requirements:
+    - - ">="
+      - !ruby/object:Gem::Version
+        version: 0.9.2
+  type: :development
+  prerelease: false
+  version_requirements: !ruby/object:Gem::Requirement
+    requirements:
+    - - ">="
+      - !ruby/object:Gem::Version
+        version: 0.9.2
+description: Kill unicorn workers by memory and request counts
+email:
+- kazuki.ohta at gmail.com
+- frsyuki at gmail.com
+- jonathan at jclem.net
+executables: []
+extensions: []
+extra_rdoc_files: []
+files:
+- AUTHORS
+- ChangeLog
+- Gemfile
+- LICENSE
+- README.md
+- Rakefile
+- VERSION
+- lib/unicorn/worker_killer.rb
+- lib/unicorn/worker_killer/configuration.rb
+- unicorn-worker-killer.gemspec
+homepage: https://github.com/kzk/unicorn-worker-killer
+licenses:
+- GPLv2+
+- Ruby 1.8
+metadata: {}
+post_install_message: 
+rdoc_options: []
+require_paths:
+- lib
+required_ruby_version: !ruby/object:Gem::Requirement
+  requirements:
+  - - ">="
+    - !ruby/object:Gem::Version
+      version: '0'
+required_rubygems_version: !ruby/object:Gem::Requirement
+  requirements:
+  - - ">="
+    - !ruby/object:Gem::Version
+      version: '0'
+requirements: []
+rubyforge_project: 
+rubygems_version: 2.4.7
+signing_key: 
+specification_version: 4
+summary: Kill unicorn workers by memory and request counts
+test_files: []
diff --git a/unicorn-worker-killer.gemspec b/unicorn-worker-killer.gemspec
index 692f843..ef26d3a 100644
--- a/unicorn-worker-killer.gemspec
+++ b/unicorn-worker-killer.gemspec
@@ -14,7 +14,9 @@ Gem::Specification.new do |gem|
   gem.files       = `git ls-files`.split("\n")
   gem.test_files  = `git ls-files -- {test,spec,features}/*`.split("\n")
   gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+  gem.licenses    = ["GPLv2+", "Ruby 1.8"]
   gem.require_paths = ['lib']
-  gem.add_dependency "unicorn", "~> 4"
+  gem.add_dependency "unicorn",         [">= 4", "< 6"]
+  gem.add_dependency "get_process_mem", "~> 0"
   gem.add_development_dependency "rake", ">= 0.9.2"
 end

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-unicorn-worker-killer.git



More information about the Pkg-ruby-extras-commits mailing list