From a6f4d006702a62e6ad84a50403246c9f7c24189b Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 18 Feb 2014 14:09:47 +1100 Subject: [PATCH] Add oobgc compatible with Ruby 2.1 --- lib/middleware/unicorn_oobgc.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/middleware/unicorn_oobgc.rb b/lib/middleware/unicorn_oobgc.rb index 3699f28de08..260109aa75d 100644 --- a/lib/middleware/unicorn_oobgc.rb +++ b/lib/middleware/unicorn_oobgc.rb @@ -33,6 +33,22 @@ module Middleware::UnicornOobgc # TUNE ME, for Discourse this number is good MIN_FREE_SLOTS = 50_000 + # The oobgc implementation is far more efficient in 2.1 + # as we have a bunch of profiling hooks to hook it + # use @tmm1s implementation + def use_gctools? + if @use_gctools.nil? + @use_gctools = + if RUBY_VERSION >= "2.1.0" + require "gctools/oobgc" + true + else + false + end + end + @use_gctools + end + def verbose(msg=nil) @verbose ||= ENV["OOBGC_VERBOSE"] == "1" ? :true : :false if @verbose == :true @@ -59,6 +75,12 @@ module Middleware::UnicornOobgc end def process_client(client) + + if use_gctools? + GC::OOB.run + return + end + stat = GC.stat @num_requests ||= 0