From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: * X-Spam-ASN: AS33070 50.56.128.0/17 X-Spam-Status: No, score=1.7 required=3.0 tests=AWL,HK_RANDOM_FROM, MSGID_FROM_MTA_HEADER,RDNS_NONE shortcircuit=no autolearn=no version=3.3.2 Path: news.gmane.org!not-for-mail From: Eric Wong Newsgroups: gmane.comp.lang.ruby.rainbows.general Subject: Re: leakage of sockets or activerecord connections Date: Thu, 22 Aug 2013 22:45:27 +0000 Message-ID: <20130822224526.GA11728@dcvr.yhbt.net> References: <52168D10.8080407@corinlangosch.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1377211536 14059 80.91.229.3 (22 Aug 2013 22:45:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 22 Aug 2013 22:45:36 +0000 (UTC) To: Rainbows! list Original-X-From: rainbows-talk-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Fri Aug 23 00:45:38 2013 Return-path: Envelope-to: gclrrg-rainbows-talk@m.gmane.org X-Original-To: rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Delivered-To: rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Content-Disposition: inline In-Reply-To: <52168D10.8080407-FIgL9nsKG9THeUWFKdsAYQC/G2K4zDHf@public.gmane.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: rainbows-talk-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Errors-To: rainbows-talk-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org X-Broken-Reverse-DNS: no host name found for IP address 50.56.192.79 Xref: news.gmane.org gmane.comp.lang.ruby.rainbows.general:515 Archived-At: Received: from [50.56.192.79] (helo=rubyforge.org) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VCddK-0004IN-7r for gclrrg-rainbows-talk@m.gmane.org; Fri, 23 Aug 2013 00:45:38 +0200 Received: from localhost.localdomain (localhost [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id 3FB262E19A; Thu, 22 Aug 2013 22:45:38 +0000 (UTC) Received: from dcvr.yhbt.net (dcvr.yhbt.net [64.71.152.64]) by rubyforge.org (Postfix) with ESMTP id 7467F2E183 for ; Thu, 22 Aug 2013 22:45:29 +0000 (UTC) Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 3F6291F464; Thu, 22 Aug 2013 22:45:27 +0000 (UTC) Corin Langosch 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