Created
April 16, 2009 07:20
-
-
Save parolkar/96287 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Patched mongrel for Garbage Collection | |
require 'mongrel' | |
unless Mongrel.const_defined?("UnixDispatchServer") | |
puts "Patched mongrel required!" | |
exit | |
end | |
Mongrel::UnixDispatchServer.preload_application do | |
puts "Loading application..." | |
require File.dirname(__FILE__) + '/../config/environment' | |
Dir.chdir(RAILS_ROOT) | |
puts "Installing garbage collect hook" | |
Mongrel::Server.class_eval do | |
def process_client_with_garbage_collect_hook(client) | |
# make sure garbage collection doesn't occur until after the response has been written to the browser | |
GC.disable | |
process_client_without_garbage_collect_hook(client) | |
GC.enable | |
end | |
alias_method_chain :process_client, :garbage_collect_hook | |
end | |
puts "Invoking garbage_collect" | |
ObjectSpace.garbage_collect | |
end | |
Mongrel::UnixDispatchServer.before_fork { ActiveRecord::Base.remove_connection } | |
Mongrel::UnixDispatchServer.after_fork { ActiveRecord::Base.establish_connection } | |
load `which mongrel_rails`.strip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment