Created
March 17, 2010 21:34
-
-
Save floere/335735 to your computer and use it in GitHub Desktop.
This file contains 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
# In your unicorn.rb | |
# | |
after_fork do |server, worker| | |
GC.disable | |
end | |
# The rack app. | |
# | |
Responder = lambda do |env| | |
harakiri | |
# Your app here | |
end | |
# In the same scope as the Responder: | |
# | |
@@requests = 0 | |
@@quit_after_requests = 50 | |
def harakiri | |
@@requests = @@requests + 1 | |
# Kill yourself off, by means of a quick slice. | |
# Will finish the request in Unicorn with honor, then die. | |
# Unicorn will fork you a new one. | |
Process.kill(:QUIT, Process.pid) if @@requests > @@quit_after_requests | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment