unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: Dan Herrera <dan@revelationglobal.com>
Cc: mongrel-unicorn@rubyforge.org, labs@revelationglobal.com
Subject: Re: Unicorn - "Still a couple bugs to knock out."
Date: Wed, 7 Oct 2009 21:47:33 -0700	[thread overview]
Message-ID: <20091008044733.GA2112@dcvr.yhbt.net> (raw)
In-Reply-To: <b89b94f00910072029m5c7265ban2f98e4346265e534@mail.gmail.com>

Dan Herrera <dan@revelationglobal.com> wrote:
> Hi Eric,
> 
> Thanks for getting in touch.  We were also pleasantly surprised by the
> performance of unicorn!
> 
> As to the blog post, we misspoke and will revise our language on the post to
> reflect that what we encountered weren't bugs, but issues with our own
> setup.

Thanks for the clarification, I was worried :x

> Our app has a memory leak, and we haven't yet settled on a monit recipe to
> restart unicorn when the sub processes that are started run over a certain
> memory threshold.  There were also some changes we needed to make with our
> nginx configuration, but again, they didn't reflect any problems with
> unicorn.

You can probably have monit just SIGQUIT the workers that run over the
memory threshold and just let the unicorn master restart them (note: I'm
not a monit user).

If your OS supports it, you can try setrlimit in your after_fork hook.
Modern Linux 2.6 doesn't support Process::RLIMIT_RSS, but you can still
do Process::RLIMIT_AS which is still somewhat useful[1].

  after_fork do |server, worker|
    Process.setrlimit(Process::RLIMIT_AS, size_in_kilobytes)
  end

Then have a simple Rack middleware that traps NoMemoryError:

  # XXX totally untested!, I'm not sure what to do if Process.kill
  # here hits NoMemoryError, either...
  class ExitOnOOM < Struct.new(:app)
    def call(env)
      begin
        app.call(env)
      rescue NoMemoryError
        Process.kill(:QUIT, 0) # graceful exit signal
        # or maybe just: exit!
      end
    end
  end

[1] On modern GNU/Linux systems that don't have RLIMIT_RSS, the VM size
    taken by the mmap()'ed shared libraries usually doesn't change over the
    lifetime of the process, so you can use that as a baseline and figure
    out how far you want to go from there....  Of course, your Unicorns
    shouldn't be swapping so swap usage won't have to be accounted for.

Of course the proper solution to all this is to fix your memory leaks :)

I posted some notes here a few months back on the Mongrel list:

  http://thread.gmane.org/gmane.comp.lang.ruby.mongrel.general/5760/focus=5766

> Engine Yard doesn't currently support unicorn on their slices, but once we
> have a satisfactory monit recipe and no other issues with our setup, we plan
> to work with them so that they'll hopefully change their mind.  I think
> this, and the monit recipe is what James meant when he said we wouldn't be
> using unicorn in the near future.

Ah, didn't know that.  I guess github was a special case where they
thought: "oh well, these guys are leaving us for another host anyways,
they can be our guinea pig!" :)

> Anyway, we are all great fans, and would like to thank all of you for all of
> your hard work.

No problem :)

-- 
Eric Wong

      parent reply	other threads:[~2009-10-08  4:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-08  0:31 Unicorn - "Still a couple bugs to knock out." Eric Wong
2009-10-08  0:59 ` Chris Wanstrath
     [not found] ` <b89b94f00910072029m5c7265ban2f98e4346265e534@mail.gmail.com>
2009-10-08  4:47   ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/unicorn/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091008044733.GA2112@dcvr.yhbt.net \
    --to=normalperson@yhbt.net \
    --cc=dan@revelationglobal.com \
    --cc=labs@revelationglobal.com \
    --cc=mongrel-unicorn@rubyforge.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).