unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* Autokill Workers which have grown too big
@ 2010-07-30 14:11 hukl
  2010-07-30 22:06 ` Eric Wong
  2010-07-30 22:32 ` Florian Hanke
  0 siblings, 2 replies; 3+ messages in thread
From: hukl @ 2010-07-30 14:11 UTC (permalink / raw)
  To: unicorn list

Hey,


at Euruko 2010 I saw a presentation where Florian Hanke presented parts 
of a unicorn config which killed workers once they've used up too much 
memory.

The snipped looks like this:

RackResponder = lambda do |env|
   possibly_commit_harakiri ...
end

# Commit Harakiri/Seppuku, kill yourself. #
def possibly_commit_harakiri
   return unless commit_harakiri?
   Process.kill “KILL”, Process.pid
end

Now I couldn't find anything about that RackResponder part on the web 
and was hoping that Florian himself or somebody else on the list could 
clue me in how that works.

Also I'd like to know if there is a way to get the current memory 
footprint of a worker other than something like:

%x(ps -o rss= -p #{Process.pid}).to_i

Kind regards,

John
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Autokill Workers which have grown too big
  2010-07-30 14:11 Autokill Workers which have grown too big hukl
@ 2010-07-30 22:06 ` Eric Wong
  2010-07-30 22:32 ` Florian Hanke
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2010-07-30 22:06 UTC (permalink / raw)
  To: unicorn list

hukl <hukl@berlin.ccc.de> wrote:
> Also I'd like to know if there is a way to get the current memory  
> footprint of a worker other than something like:
>
> %x(ps -o rss= -p #{Process.pid}).to_i

Hi John,

I know under Linux it's possible to parse /proc/$$/stat and also
(the bigger, but more human-readable) /proc/$$/status to get
current memory usage.

There's also the sys-proctable gem, too, which I haven't used.

-- 
Eric Wong
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Autokill Workers which have grown too big
  2010-07-30 14:11 Autokill Workers which have grown too big hukl
  2010-07-30 22:06 ` Eric Wong
@ 2010-07-30 22:32 ` Florian Hanke
  1 sibling, 0 replies; 3+ messages in thread
From: Florian Hanke @ 2010-07-30 22:32 UTC (permalink / raw)
  To: mongrel-unicorn

hukl <hukl <at> berlin.ccc.de> writes:
> at Euruko 2010 I saw a presentation where Florian Hanke presented parts 
> of a unicorn config which killed workers once they've used up too much 
> memory.
>
> The snipped looks like this:
> 
> RackResponder = lambda do |env|
>    possibly_commit_harakiri ...
> end
> 
> # Commit Harakiri/Seppuku, kill yourself. #
> def possibly_commit_harakiri
>    return unless commit_harakiri?
>    Process.kill “KILL”, Process.pid
> end
> 
> Now I couldn't find anything about that RackResponder part on the web 
> and was hoping that Florian himself or somebody else on the list could 
> clue me in how that works.

Hi John

I thought I'd answer your question here too (not just on Github) for
others to see. Perhaps someone else has similar questions. 

Sure. Using the RackResponder constant was just my way of naming the
application. It could be any old lambda.

I didn't want the GC to run and slow down any queries (in the search
engine). The way the whole thing works is this:
1. The forked Unicorn child switches off the GC just after forking.

unicorn.rb:
  after_fork do |_, _|
    GC.disable
  end

2. On each request, the child takes a look at how many requests
it has already answered (or how much memory it uses, or any metric). If a
threshold has been passed, it will honorably kill itself, by sending
itself the QUIT signal. It will then finish responding the request and die.

A Rack middleware for the request counting metric can be found here: 
http://bit.ly/bjkbRG

3. The Unicorn master process notices that a child has gone and
   forks a new one.

4. The OS – rather than the GC – cleans up the memory mess left
   by the dead child ;)

> Also I'd like to know if there is a way to get the current memory 
> footprint of a worker other than something like:
> 
> %x(ps -o rss= -p #{Process.pid}).to_i

On Linux, the /proc folder holds a lot of information on the currently
running processes.
One can for example use
cat /proc/some_proc_id/statm
to get Memory information.

Cheers and have fun,
   Florian

_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-07-30 23:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-30 14:11 Autokill Workers which have grown too big hukl
2010-07-30 22:06 ` Eric Wong
2010-07-30 22:32 ` Florian Hanke

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/unicorn.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).