unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Michael Guterl <mguterl@gmail.com>
To: unicorn list <mongrel-unicorn@rubyforge.org>
Subject: Re: Strange Thread related errors
Date: Thu, 7 Jan 2010 13:49:52 -0500	[thread overview]
Message-ID: <944a03771001071049j520f6580i26c3a3ae8b850a48@mail.gmail.com> (raw)
In-Reply-To: <201001071731.49847.ibc@aliax.net>

On Thu, Jan 7, 2010 at 11:31 AM, Iñaki Baz Castillo <ibc@aliax.net> wrote:
> El Jueves, 7 de Enero de 2010, Michael Guterl escribió:
>> Our Rails app has started raising exceptions (caught by hoptoad
>> thankfully) and I can only imagine they're related to unicorn.  I only
>> think the errors are occurring on the request after we deploy, which
>> upgrades the Unicorn process.  I say this because the errors are
>> coming from many different actions, but I haven't been able to
>> reproduce.
> Let me explain a problem I had with Sequel and Unicorn (already solved),
> perhaps it's related:
> I load Sequel database toolkit in the master process so it generates its own
> threads pool.
> Then Unicorn forks into workers but each worker uses the same instance of
> Sequel database, this is, the same threads pool.
> This causes errors since some thread could be used by different processes at
> the same time.
> The solution is simple:
> Don't set the Sequel instance in the master process, instead do it in each
> worker ("after_fork" block in unicorn config file).
> In this way each process has its own Sequel instance with its own threads
> pool.
> Also, using Sequel thread pool makes no sense when using Unicorn as each
> worker is single thread, so I gain some performance by setting
> "single_threaded = true" in Sequel database configuration (no thread pool
> stuff).
> Probably you are getting a similar issue due to ActiveRecord or any other
> multithread library you load in the master process so the instance is shared
> between all the workers.

We currently disconnect from both databases in before_fork and
re-establish the connection in after_fork.

Here's our unicorn config: http://gist.github.com/271449

Maybe I should disable connection pooling?

Best regards,
Michael Guterl
Unicorn mailing list - mongrel-unicorn@rubyforge.org
Do not quote signatures (like this one) or top post when replying

  parent reply	other threads:[~2010-01-07 18:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-07 16:05 Strange Thread related errors Michael Guterl
2010-01-07 16:31 ` Iñaki Baz Castillo
2010-01-07 18:10   ` Jeremy Evans
2010-01-07 18:33     ` Iñaki Baz Castillo
2010-01-07 18:49   ` Michael Guterl [this message]
2010-01-07 19:08     ` Iñaki Baz Castillo
2010-01-07 20:08     ` Jeremy Evans
2010-01-07 20:13 ` Eric Wong
2010-01-07 21:32   ` Michael Guterl

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:

  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=944a03771001071049j520f6580i26c3a3ae8b850a48@mail.gmail.com \
    --to=mguterl@gmail.com \
    --cc=mongrel-unicorn@rubyforge.org \


* 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


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).