Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 89EEA16C9C32 for ; Wed, 16 Nov 2011 00:27:55 -0400 (AST) 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 55077-01-6 for ; Wed, 16 Nov 2011 04:27:49 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id C7C47CD43BE for ; Wed, 16 Nov 2011 00:27:36 -0400 (AST) Received: from moutng.kundenserver.de ([212.227.17.10]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RQX5v-0005nD-H0 for pgsql-performance@postgresql.org; Wed, 16 Nov 2011 04:27:36 +0000 Received: from [192.168.1.3] (mail.highperformancepostgresql.com [71.179.240.8]) by mrelayeu.kundenserver.de (node=mreu3) with ESMTP (Nemesis) id 0M15EC-1Qc8Kc2oXI-00tfZX; Wed, 16 Nov 2011 05:27:18 +0100 Message-ID: <4EC33BA5.2040603@2ndQuadrant.com> Date: Tue, 15 Nov 2011 23:27:17 -0500 From: Greg Smith User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.16) Gecko/20111110 Icedove/3.0.11 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Slow queries / commits, mis-configuration or hardware issues? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:IQ85aFZ8rHCbDmTx2kpFcTyM4uMnzh46pdfHWCUxVXR ZZBKf4GlY79U2sf+uJilJOTeG7rpKjMKpdkCQzr1V6XLVEAXuZ p7QAyEx8QuJHyU0Q/PIzkS94qTA8iLHa49G6nWxu0WBR83ORLQ DQrmU0tr3RorrKLQkHeQtJoRbv5sy4idlkGcGHA8WR1tFVYA6r ThQfCHBLcvGPromlgwDDkqUfHhjsNtmZBc3oZuL3MY5lDZwxt2 UWYmDN7kNYXh9CmsZSsSpgnAix524so8HCYj29aX7BSJt+6T7U C+ybxKyN/S8KAPx69NtngZZGtZGBHmihgOhh5/NAAMtx/wP7cB aZ5GfRh1U15KNpyp3ZHE= 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: 201111/192 X-Sequence-Number: 45703 On 11/14/2011 01:16 PM, Cody Caughlan wrote: > We're starting to see some slow queries, especially COMMITs that are > happening more frequently. The slow queries are against seemingly > well-indexed tables. > Slow commits like: > > 2011-11-14 17:47:11 UTC pid:14366 (44/0-0) LOG: duration: 3062.784 ms > statement: COMMIT > 2011-11-14 17:47:11 UTC pid:14604 (48/0-0) LOG: duration: 2593.351 ms > statement: COMMIT > > These slow COMMITs are against tables that received a large number of > UPDATEs and are growing fairly rapidly. > Linux will fill its write cache with all of the writes coming out of each checkpoint. With a 16GB instance, I would expect that 5% * 16GB ~= 800MB of writes are batched up when your system is slow. You should be able to confirm that by looking at the "Dirty:" line in /proc/meminfo With 800MB queued up and I/O that is lucky to get 50MB/s, the sync calls at the end of each checkpoint are sometimes blocking for multiple seconds: > 2011-11-14 17:38:48 UTC pid:3965 (-0) LOG: checkpoint complete: wrote > 15121 buffers (3.3%); 0 transaction log file(s) added, 0 removed, 8 > recycled; write=270.101 s, sync=2.989 s, total=273.112 s; sync > files=60, longest=1.484 s, average=0.049 s > 2011-11-14 17:39:15 UTC pid:3965 (-0) LOG: checkpoint starting: time > 2011-11-14 17:43:49 UTC pid:3965 (-0) LOG: checkpoint complete: wrote > 16462 buffers (3.6%); 0 transaction log file(s) added, 0 removed, 9 > recycled; write=269.978 s, sync=4.106 s, total=274.117 s; sync > files=82, longest=2.943 s, average=0.050 s > When an individual sync call gets stuck for that long, clients can easily get stuck behind it too. There are a couple of techniques that might help: -Switch filesystems if you're running a slow one. ext3 has bad latency behavior here, XFS and ext4 are better. -Lower the dirty_* tunables like dirty_background_ratio or its bytes version. This will reduce average throughput, but can lower latency. -Spread checkpoints out more so that less average writes are happening. -Decrease shared_buffers so less data is getting pushed out at checkpoint time. -Reduce your reliability expectations and turn off synchronous_commit. Your server is sometimes showing multi-second latency issues with bonnie++ too; that suggests how this problem is not even specific to PostgreSQL. Linux is hard to tune for low latency under all circumstances; fighting latency down under a heavy update workload is hard to do even with good hardware to accelerate write performance. In an EC2 environment, it may not even be possible to do without making trade-offs like disabling synchronous writes. I can easily get transactions hung for 10 to 15 seconds on one of their servers if I try to make that problem bad, you're only seeing the middle range of latency issues so far. -- Greg Smith 2ndQuadrant US greg@2ndQuadrant.com Baltimore, MD PostgreSQL Training, Services, and 24x7 Support www.2ndQuadrant.us