diff --git a/Changelog.md b/Changelog.md index a61a0f77aeaaa2467d89096a9e80422e6a22048c..7951b0fb88381d492985fc040076b3111073a8a9 100644 --- a/Changelog.md +++ b/Changelog.md @@ -107,6 +107,7 @@ before. * Redesign back to top button [#6782](https://github.com/diaspora/diaspora/pull/6782) * Adjusted Facebook integration for a successful review [#6778](https://github.com/diaspora/diaspora/pull/6778) * Redirect to the sign-in page instead of the stream on account deletion [#6784](https://github.com/diaspora/diaspora/pull/6784) +* Removed own unicorn killer by a maintained third-party gem [#6792](https://github.com/diaspora/diaspora/pull/6792) ## Bug fixes * Destroy Participation when removing interactions with a post [#5852](https://github.com/diaspora/diaspora/pull/5852) diff --git a/Gemfile b/Gemfile index 5d3da9ec3fa410e249126e7856042f2ae6a3f510..662a1c5ad67016b4a773874cacfe5ac05f2b2ba7 100644 --- a/Gemfile +++ b/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 diff --git a/Gemfile.lock b/Gemfile.lock index 5c16af4c41aa80f3a4986b2e7a60b3efa43859ea..659e1b2d282bf55c34a0154155d214d4711c7b03 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -343,6 +343,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 @@ -849,6 +850,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) @@ -1021,6 +1025,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) diff --git a/config.ru b/config.ru index e2524860075a6d80a3bed0413e13a1e767f631a3..2f5ac99d8fb0e19f38e70337f727684d08411ebe 100644 --- a/config.ru +++ b/config.ru @@ -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 diff --git a/lib/unicorn_killer.rb b/lib/unicorn_killer.rb deleted file mode 100644 index 7e908538de1f8260fde3fdf0c3304c6826f1cbd7..0000000000000000000000000000000000000000 --- a/lib/unicorn_killer.rb +++ /dev/null @@ -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