Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 447FAB5DC69 for ; Mon, 5 Sep 2011 07:50:08 -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 95775-02 for ; Mon, 5 Sep 2011 10:50:02 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qy0-f181.google.com (mail-qy0-f181.google.com [209.85.216.181]) by mail.postgresql.org (Postfix) with ESMTP id A5697B5DC5F for ; Mon, 5 Sep 2011 07:49:59 -0300 (ADT) Received: by qyk34 with SMTP id 34so3052878qyk.19 for ; Mon, 05 Sep 2011 03:49:59 -0700 (PDT) Received: by 10.224.210.138 with SMTP id gk10mr2858428qab.18.1315219799755; Mon, 05 Sep 2011 03:49:59 -0700 (PDT) Received: from [10.1.1.8] (124-169-102-162.dyn.iinet.net.au. [124.169.102.162]) by mx.google.com with ESMTPS id u17sm6920qaz.1.2011.09.05.03.49.57 (version=SSLv3 cipher=OTHER); Mon, 05 Sep 2011 03:49:59 -0700 (PDT) Message-ID: <4E64A94E.7000803@ringerc.id.au> Date: Mon, 05 Sep 2011 18:49:50 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.1) Gecko/20110830 Thunderbird/6.0.1 MIME-Version: 1.0 To: Richard Shaw CC: pgsql-performance@postgresql.org Subject: Re: Rather large LA References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201109/31 X-Sequence-Number: 44807 On 5/09/2011 6:28 PM, Richard Shaw wrote: > max_connections | 1000 Woah! No wonder you have "stampeding herd" problems after a DB or server restart and are having performance issues. When you have 1000 clients trying to do work at once, they'll all be fighting over memory, disk I/O bandwidth, and CPU power which is nowhere near sufficient to allow them to all actually achieve something all at once. You'll have a lot of overhead as the OS tries to be fair and allow each to make progress - at the expense of overall throughput. If most of those connections are idle most of the time - say, they're peristent connections from some webapp that requrires one connection per webserver thread - then the situation isn't so bad. They're still costing you backend RAM and various housekeeping overhead (including task switching) related to lock management and shared memory, though. Consider using a connection pooler like PgPool-II or PgBouncer if your application is suitable. Most apps will be quite happy using pooled connections; only a few things like advisory locking and HOLD cursors work poorly with pooled connections. Using a pool allows you to reduce the number of actively working and busy connections to the real Pg backend to something your hardware can cope with, which should dramatically increase performance and reduce startup load spikes. The general very rough rule of thumb for number of active connections is "number of CPU cores + number of HDDs" but of course this is only incredibly rough and depends a lot on your workload and DB. Ideally PostgreSQL would take care of this pooling inside the server, breaking the "one connection = one worker backend" equivalence. Unfortunately the server's process-based design makes that harder than it could be. There's also a lot of debate about whether pooling is even the core DB server's job and if it is, which of the several possible approaches is the most appropriate. Then there's the issue of whether in-server connection pooling is even appropriate without admission control - which brings up the "admission control is insanely hard" problem. So for now, pooling lives outside the server in projects like PgPool-II and PgBouncer. -- Craig Ringer