From: Eric Wong <normalperson-rMlxZR9MS24@public.gmane.org>
To: Rainbows! list <rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org>
Subject: Re: leakage of sockets or activerecord connections
Date: Thu, 22 Aug 2013 22:45:27 +0000 [thread overview]
Message-ID: <20130822224526.GA11728@dcvr.yhbt.net> (raw)
In-Reply-To: <52168D10.8080407-FIgL9nsKG9THeUWFKdsAYQC/G2K4zDHf@public.gmane.org>
Corin Langosch <info-FIgL9nsKG9THeUWFKdsAYQC/G2K4zDHf@public.gmane.org> wrote:
> I'm using rainbows to power my own small middleware. I doen't use
> rails (or any other framework), only activerecord for database
> access. I chose XEpollThreadSpawn, set worker_processes 1 and
> worker_connections 25. All classes are eager loaded, no reloading of
> anything while the server is running. AR connection pool size is set
> to 100.
I'm not sure how AR connection pool works (if it uses thread-local
variables for storing the connections). If it's using thread-locals,
it could be reliant on GC, and that would require:
a) GC to run frequently enough to reap connections
b) your Postgres bindings being GC-aware (and really being unreachable
in your VM)
> Now it seems that every request opens a new connection and never
> frees/ closes it. So after 100 requests I get an AR connection pool
> exception. I also see exactly 100 postgresql clients connected. When
> I kill the server all clients get disconnected.
>
> I wonder if I have to setup and hooks (like in unicorn before_fork
> etc.)? In fact I'd expect this happens automatically as the thread
> exits after the request is completed?
Can you reproduce the issue with XEpollThreadPool?
If it's using thread-local storage, you probably need to have a Rack
middleware push the connection back into the pool when it's done working
on a request.
Something like this in your config.ru:
class ReleaseConnections
def initialize(app)
@app = app
end
def call(env)
begin
@app.call(env)
ensure
Thread.current[:whatever_sockets].release_to_pool
end
end
end
use ReleaseConnections
...
run YourApp.new
In any case, I'd dig through the Rails/AR APIs to see how it works
and how to release resources back to the pool.
_______________________________________________
Rainbows! mailing list - rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org
http://rubyforge.org/mailman/listinfo/rainbows-talk
Do not quote signatures (like this one) or top post when replying
next prev parent reply other threads:[~2013-08-22 22:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-22 22:13 leakage of sockets or activerecord connections Corin Langosch
[not found] ` <52168D10.8080407-FIgL9nsKG9THeUWFKdsAYQC/G2K4zDHf@public.gmane.org>
2013-08-22 22:45 ` Eric Wong [this message]
2013-08-22 22:46 ` Lin Jen-Shin (godfat)
[not found] ` <CAA2_N1soVYiNkRgZqa+mLO26KUzvTAXuk0gA9Qo7MPrZ0+bNXw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-08-27 12:31 ` Corin Langosch
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/rainbows/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130822224526.GA11728@dcvr.yhbt.net \
--to=normalperson-rmlxzr9ms24@public.gmane.org \
--cc=rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.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/rainbows.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).