Unicorn has OobGC rack middleware that can be used to run GC.start
after a certain number of requests.
Is there a similar sort of thing in Phusion Passenger?
Unicorn has OobGC rack middleware that can be used to run GC.start
after a certain number of requests.
Is there a similar sort of thing in Phusion Passenger?
Hooking into
PhusionPassenger::Rack::RequestHandler#process_request()
is the only mechanism I have found.To do this in a similar way to the Unicorn OobGC, you can use the following module:
and invoke it in an initializer with:
You have to patch Passenger. Doing a
GC.start
after each request has been handed off ensures that garbage collection never occurs while holding a client request. This is a one-line change that you might consider if you're trying to reduce your average request time.In lib/phusion_passenger/abstract_request_handler.rb, patch
accept_and_process_next_request
and add theGC.start
call at the end, with an appropriate interval.See this commit for an example (thanks, @raphaelcm).
Phusion Passenger 4 officially introduces an out of band garbage collection mechanism. It's more flexible than Unicorn's by allowing any arbitrary work, not just garbage collection. http://blog.phusion.nl/2013/01/22/phusion-passenger-4-technology-preview-out-of-band-work/