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?
One fundamental problem with garbage collection, though, is that it is difficult to estimate and manage the actual size of the working set in memory, because garbage collector can free your memory only delayedly. So, yes, when memory is restricted, garbage collection might not be a good choice.
Garbage collection cannot be forced. Garbage collection cannot be forced. This indicates that Garbage Collector is an independent thread and is on a priority which is decided by the Java Virtual Machine, so you may not enforce Garbage Collection.
The usual fix is to reboot. Freeing up the operating system for reuse of the space that has been taken over by memory leaks is called garbage collection. In the past, programs have had to explicitly request storage and then return it to the system when it was no longer needed.
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/
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:
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 invoke it in an initializer with:
if defined?(PhusionPassenger::Rack::RequestHandler)
require 'passenger_oob_gc'
PassengerOobGC.install!(%r{^/admin/}, 3)
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With