Move unicorn_killer to Gemfile
This commit is contained in:
parent
f073a96b19
commit
56c7af940d
4 changed files with 11 additions and 55 deletions
1
Gemfile
1
Gemfile
|
|
@ -9,6 +9,7 @@ gem "responders", "2.1.1"
|
|||
# Appserver
|
||||
|
||||
gem "unicorn", "5.0.1", require: false
|
||||
gem "unicorn-worker-killer", "0.4.4"
|
||||
|
||||
# Federation
|
||||
|
||||
|
|
|
|||
|
|
@ -353,6 +353,7 @@ GEM
|
|||
fuubar (2.0.0)
|
||||
rspec (~> 3.0)
|
||||
ruby-progressbar (~> 1.4)
|
||||
get_process_mem (0.2.0)
|
||||
gherkin (3.2.0)
|
||||
gitlab (3.4.0)
|
||||
httparty
|
||||
|
|
@ -860,6 +861,9 @@ GEM
|
|||
kgio (~> 2.6)
|
||||
rack
|
||||
raindrops (~> 0.7)
|
||||
unicorn-worker-killer (0.4.4)
|
||||
get_process_mem (~> 0)
|
||||
unicorn (>= 4, < 6)
|
||||
url_safe_base64 (0.2.2)
|
||||
uuid (2.3.8)
|
||||
macaddr (~> 1.0)
|
||||
|
|
@ -1032,6 +1036,7 @@ DEPENDENCIES
|
|||
typhoeus (= 1.0.1)
|
||||
uglifier (= 2.7.2)
|
||||
unicorn (= 5.0.1)
|
||||
unicorn-worker-killer (= 0.4.4)
|
||||
uuid (= 2.3.8)
|
||||
versionist (= 1.4.1)
|
||||
webmock (= 1.22.6)
|
||||
|
|
|
|||
|
|
@ -5,12 +5,15 @@
|
|||
# This file is used by Rack-based servers to start the application.
|
||||
|
||||
require ::File.expand_path("../config/environment", __FILE__)
|
||||
require ::File.expand_path("../lib/unicorn_killer", __FILE__)
|
||||
require ::File.expand_path("../lib/rack/internet_explorer_version", __FILE__)
|
||||
|
||||
# Kill unicorn workers really aggressively (at 300mb)
|
||||
if defined?(Unicorn)
|
||||
use UnicornKiller::Oom, 300 * 1024
|
||||
require "unicorn/worker_killer"
|
||||
oom_min = (280) * (1024**2)
|
||||
oom_max = (300) * (1024**2)
|
||||
# Max memory size (RSS) per worker
|
||||
use Unicorn::WorkerKiller::Oom, oom_min, oom_max
|
||||
end
|
||||
use Rack::Deflater
|
||||
use Rack::InternetExplorerVersion, minimum: 9
|
||||
|
|
|
|||
|
|
@ -1,53 +0,0 @@
|
|||
# # your config.ru
|
||||
# require 'unicorn_killer'
|
||||
# use UnicornKiller::MaxRequests, 1000
|
||||
# use UnicornKiller::Oom, 400 * 1024
|
||||
|
||||
module UnicornKiller
|
||||
module Kill
|
||||
def quit
|
||||
sec = (Time.now - @process_start).to_i
|
||||
warn "#{self.class} send SIGQUIT (pid: #{Process.pid})\talive: #{sec} sec"
|
||||
Process.kill :QUIT, Process.pid
|
||||
end
|
||||
end
|
||||
|
||||
class Oom
|
||||
include Kill
|
||||
|
||||
def initialize(app, memory_size= 512 * 1024, check_cycle = 10)
|
||||
@app = app
|
||||
@memory_size = memory_size
|
||||
@check_cycle = check_cycle
|
||||
@check_count = 0
|
||||
end
|
||||
|
||||
def rss
|
||||
`ps -o rss= -p #{Process.pid}`.to_i
|
||||
end
|
||||
|
||||
def call(env)
|
||||
@process_start ||= Time.now
|
||||
if (@check_count += 1) % @check_cycle == 0
|
||||
@check_count = 0
|
||||
quit if rss > @memory_size
|
||||
end
|
||||
@app.call env
|
||||
end
|
||||
end
|
||||
|
||||
class MaxRequests
|
||||
include Kill
|
||||
|
||||
def initialize(app, max_requests = 1000)
|
||||
@app = app
|
||||
@max_requests = max_requests
|
||||
end
|
||||
|
||||
def call(env)
|
||||
@process_start ||= Time.now
|
||||
quit if (@max_requests -= 1) == 0
|
||||
@app.call env
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue