milandobrota
unread,Sep 20, 2011, 7:48:15 PM9/20/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Phusion Passenger Discussions
Since Ruby garbage collection blocks the current process in order to
optimize the response time I thought it would make sense to make
garbage collector run outside of a request processing logic. I tried
different things, however In this case I am running GC every X
requests. This is what I have so far in my rails app:
# config/initializers/passenger_oobgc
module PassengerOobGC
def self.install!(interval = 5)
@@oobgc_interval = @@oobgc_requests_to_go = interval
PhusionPassenger::Rack::RequestHandler.send :include, self
end
def self.included(base)
base.send :alias_method_chain, :accept_and_process_next_request, :gc
end
def accept_and_process_next_request_with_gc(socket_wrapper, channel,
buffer)
response =
accept_and_process_next_request_without_gc(socket_wrapper, channel,
buffer)
if (@@oobgc_requests_to_go -= 1) <= 0
@@oobgc_requests_to_go = @@oobgc_interval
GC.start
end
response
end
end
if defined?(PhusionPassenger::Rack::RequestHandler)
PassengerOobGC.install!(10)
end
Now since individual requests do take ~10% less time, when I run them
one after another the worker picks up the new request while still
doing garbage collection. Is this because the TCP socket has been
closed (I was intentionally waiting for the response to get sent back
so the GC happens asynchronously)? Are there any other ways around
this?