From: Eric Wong <normalperson@yhbt.net>
To: unicorn list <mongrel-unicorn@rubyforge.org>
Cc: Luke Melia <luke@lukemelia.com>
Subject: Re: Garbage collection outside of request cycle?
Date: Thu, 6 May 2010 13:57:54 -0700 [thread overview]
Message-ID: <20100506205754.GA13412@dcvr.yhbt.net> (raw)
In-Reply-To: <0BFC98E9-072B-47EE-9A70-05478C20141B@lukemelia.com>
Luke Melia <luke@lukemelia.com> wrote:
> I've been analyzing our Unicorn-powered Rails app's performance, and
> have found that garbage collection is a big factor in slow requests.
>
> In the interest of avoiding those performance hits while handling
> requests, would it be possible to have a unicorn worker run garbage
> collection after handling a request and before waiting for the next
> one? Would this be a good idea?
Hi Luke,
I made this for one heavyweight app a while back.
I guess I should throw this into the examples section, but it won't be
the default since it hurts simpler applications that don't generate
much garbage.
==> big_app_gc.rb <==
# This shouldn't hurt overall performance as long as the server cluster
# is at <=50% CPU capacity, and improves the performance of most memory
# intensive requests. This serves to improve _client-visible_
# performance (possibly at the cost of overall performance).
#
# We'll call GC after each request is been written out to the socket, so
# the client never sees the extra GC hit it. It's ideal to call the GC
# inside the HTTP server (vs middleware or hooks) since the stack is
# smaller at this point, so the GC will both be faster and more
# effective at releasing unused memory.
#
# This monkey patch is _only_ effective for applications that use a lot
# of memory, and will hurt simpler apps/endpoints that can process
# multiple requests before incurring GC.
class Unicorn::HttpServer
REQ = Unicorn::HttpRequest::REQ
alias _process_client process_client
undef_method :process_client
def process_client(client)
_process_client(client)
REQ.clear
GC.start
end
end if defined?(Unicorn)
--
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
next prev parent reply other threads:[~2010-05-06 20:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-06 20:29 Garbage collection outside of request cycle? Luke Melia
2010-05-06 20:57 ` Eric Wong [this message]
2010-05-06 21:12 ` Eric Wong
2010-05-06 23:17 ` Luke Melia
2010-05-13 20:29 ` Luke Melia
2010-05-14 19:02 ` Eric Wong
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=20100506205754.GA13412@dcvr.yhbt.net \
--to=normalperson@yhbt.net \
--cc=luke@lukemelia.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).