Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 2582F6335FF for ; Fri, 30 Jul 2010 12:57:58 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 59619-07-4 for ; Fri, 30 Jul 2010 15:57:50 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from gw.wicourts.gov (gwmta.wicourts.gov [165.219.244.99]) by mail.postgresql.org (Postfix) with ESMTP id 73A9D6333DE for ; Fri, 30 Jul 2010 12:57:43 -0300 (ADT) Received: from Courts-MTA by gw.wicourts.gov with Novell_GroupWise; Fri, 30 Jul 2010 10:57:42 -0500 Message-Id: <4C52B0240200002500033F10@gw.wicourts.gov> X-Mailer: Novell GroupWise Internet Agent 8.0.1 Date: Fri, 30 Jul 2010 10:57:40 -0500 From: "Kevin Grittner" To: "Craig James" , Subject: Re: Connection pooling for a mixture of lightweight and heavyweight jobs? References: <4C50ABA5.5010408@emolecules.com> In-Reply-To: <4C50ABA5.5010408@emolecules.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.51 tagged_above=-10 required=5 tests=BAYES_50=0.8, RCVD_IN_DNSWL_MED=-2.3, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201007/221 X-Sequence-Number: 35240 Craig James wrote: > We create a bunch of high-performance lightweight Postgres clients > that serve up images (via mod_perl and Apache::DBI). We have > roughly ten web sites, with ten mod_perl instances each, so we > always have around 100 Postgres backends sitting around all the > time waiting. When a lightweight request comes in, it's a single > query on an primary key with no joins, so it's very fast. > > We also have a very heavyweight process (our primary search > technology) that can take many seconds, even minutes, to do a > search and generate a web page. > > The lightweight backends are mostly idle, but when a heavyweight > search finishes, it causes a burst on the lightweight backends, > which must be very fast. (They provide all of the images in the > results page.) > > This mixture seems to make it hard to configure Postgres with the > right amount of memory and such. The primary query needs some > elbow room to do its work, but the lightweight queries all get the > same resources. > > I figured that having these lightweight Postgres backends sitting > around was harmless -- they allocate shared memory and other > resources, but they never use them, so what's the harm? But > recent discussions about connection pooling seem to suggest > otherwise, that merely having 100 backends sitting around might be > a problem. Well, the "if it ain't broke, don't fix it" rule might come into play here. The current configuration might leave you vulnerable to occasional less-than-optimal performance, if two or more heavyweight processes finish at the same time, and cause a "thundering herd" of lightweight processes. Having the lightweight requests go through a connection pool could mitigate that problem, but they introduce their own overhead on every request. So, I would advise keeping an eye out for problems which might match the above, but not to take hasty action in the absence of evidence. You might buy back 400MB of RAM for caching (which you may or may not need) at the cost of extra latency and CPU per request. -Kevin