Is there an easy way to start garbage collection outside the Passenger request cycle?

Unicorn has OobGC middleware rack that can be used to run GC.start after a certain number of requests.

Are there any similar things in Phusion Passenger?

+8
ruby ruby-on-rails passenger mod-rails
source share
3 answers

Binding to PhusionPassenger::Rack::RequestHandler#process_request() is the only mechanism I have found.

To do this similarly to Unicorn OobGC, you can use the following module:

 module PassengerOobGC def self.install!(path, interval = 5) self.const_set :OOBGC_PATH, path self.const_set :OOBGC_INTERVAL, interval @@oob_nr = interval PhusionPassenger::Rack::RequestHandler.send :include, self end def self.included(base) base.send :alias_method_chain, :process_request, :gc end def process_request_with_gc(env, *args) process_request_without_gc(env, *args) if OOBGC_PATH =~ env["PATH_INFO"] && ((@@oob_nr -= 1) <= 0) @@oob_nr = OOBGC_INTERVAL GC.start end end end 

and call it in the initializer with:

 if defined?(PhusionPassenger::Rack::RequestHandler) require 'passenger_oob_gc' PassengerOobGC.install!(%r{^/admin/}, 3) end 
+3
source share

Phusion Passenger 4 officially unveils out-of-band garbage collection. It is more flexible than Unicorn, allowing arbitrary work rather than garbage collection. http://blog.phusion.nl/2013/01/22/phusion-passenger-4-technology-preview-out-of-band-work/

+5
source share

You need to fix the Passenger. Running GC.start after passing each request ensures that garbage collection never occurs when a client request is made. This is a one-line change that you can consider if you are trying to reduce the average query time.

In lib / phusion_passenger / abstract_request_handler.rb, patch accept_and_process_next_request and add a call to GC.start at the end with the appropriate interval.

See this commit for an example (thanks, @raphaelcm).

+2
source share

All Articles