Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 52207B5DCEF for ; Tue, 12 Jul 2011 01:43:23 -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 64306-06 for ; Tue, 12 Jul 2011 04:43:16 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from nm18.bullet.mail.ne1.yahoo.com (nm18.bullet.mail.ne1.yahoo.com [98.138.90.81]) by mail.postgresql.org (Postfix) with SMTP id 2AA0EB5DCEE for ; Tue, 12 Jul 2011 01:43:15 -0300 (ADT) Received: from [98.138.90.53] by nm18.bullet.mail.ne1.yahoo.com with NNFMP; 12 Jul 2011 04:43:14 -0000 Received: from [98.138.226.126] by tm6.bullet.mail.ne1.yahoo.com with NNFMP; 12 Jul 2011 04:43:14 -0000 Received: from [127.0.0.1] by smtp205.mail.ne1.yahoo.com with NNFMP; 12 Jul 2011 04:43:14 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1310445794; bh=80eZ+ZX8pOqpmKFRlPTMCM/mz2v5UE67RkBQtOaRf0A=; h=X-Yahoo-Newman-Id:Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=2mm0dBZkPg+XNU/AJr0PVcbbIocoEw1dXrLPawEgtjbsBUL/i1Ag0S4tkcz9H5hPku6xJ/QeAlbi/orRs6bjgDWDKcQEoLPZIOQpGWK9yPqReF0ByiBLzbX3QMkerYB2OKV0feQab8deGhXLm1gsqB4EEaNsxxkF1L7wbwL5VWY= X-Yahoo-Newman-Id: 883317.55199.bm@smtp205.mail.ne1.yahoo.com Received: from [192.168.206.5] (lhofhansl@67.170.234.149 with plain) by smtp205.mail.ne1.yahoo.com with SMTP; 11 Jul 2011 21:43:14 -0700 PDT X-Yahoo-SMTP: YmezqLWswBDx0ai534H100MJuqGzDQ-- X-YMail-OSG: _7aH1NoVM1n7Dnvd11UOLeJLhZcnhrxgZbWMRQya1Nee4DM grsqT14dzBqCwq3Etbmlgacl47ZUCAEAK4ExN0peZZMa6KzAk0IYVjWrFD0M OsLXYo479yQihGLP20vWKG21acd.c_ggWSX5VUnvdyVNYoGsVquvAujM1VSM lYhRCqgAxOXv4FBFaHLPCk4uzZDqriSsZ9ge5Ur_U5djsgcISljTql_svSyu LSkGkWzGIT2mLnVc8KBesLnyPkjO7SCrfx4aflshfd7d38kLoyDMWW3QZhNV 5bQLKnVtoMxRG2CjM1avjRXwNZ3Zpv8p0ZEylohQe8ZuyeD8T7cT5RIND1En X04y5H293fQJryHkHmjLyYEnKA1Jiq81OhAthzkVba1WBNmqVT8mfCF8V8we MjyuOKWeClCYXKF2Tkg2YZOPKplGd_0_m6.8.ACk0aRl3JikjY1qza_UZLWc 6IrQ8Ywfl5tY- X-Yahoo-Newman-Property: ymail-3 Message-ID: <4E1BD0C5.5030204@yahoo.com> Date: Mon, 11 Jul 2011 21:42:45 -0700 From: lars User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110621 Fedora/3.1.11-1.fc14 Thunderbird/3.1.11 MIME-Version: 1.0 To: Robert Klemme CC: "ktm@rice.edu" , pgsql-performance@postgresql.org Subject: Re: UPDATEDs slowing SELECTs in a fully cached database References: <4E16479D.3050605@yahoo.com> <20110711131348.GA14305@staff-mud-56-27.rice.edu> 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.594 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SARE_MILLIONSOF=0.315, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201107/106 X-Sequence-Number: 44318 On 07/11/2011 08:26 AM, Robert Klemme wrote: > On Mon, Jul 11, 2011 at 3:13 PM, ktm@rice.edu wrote: >> I do not know if this makes sense in PostgreSQL and that readers >> do not block writers and writes do not block readers. Are your >> UPDATEs to individual rows, each in a separate transaction, or >> do you UPDATE multiple rows in the same transaction? If you >> perform multiple updates in a single transaction, you are >> synchronizing the changes to that set of rows and that constraint >> is causing other readers that need to get the correct values post- >> transaction to wait until the COMMIT completes. This means that >> the WAL write must be completed. > What readers should that be? Docs explicitly state that readers are > never blocked by writers: > http://www.postgresql.org/docs/9.0/interactive/mvcc-intro.html > http://www.postgresql.org/docs/9.0/interactive/mvcc.html > > From what I understand about this issue the observed effect must be > caused by the implementation and not by a conceptual issue with > transactions. > >> Have you tried disabling synchronous_commit? If this scenario >> holds, you should be able to reduce the slowdown by un-batching >> your UPDATEs, as counter-intuitive as that is. This seems to >> be similar to a problem that I have been looking at with using >> PostgreSQL as the backend to a Bayesian engine. I am following >> this thread with interest. > I don't think this will help (see above). Also, I would be very > cautious to do this because although the client might get a faster > acknowledge the DB still has to do the same work as without > synchronous_commit (i.e. WAL, checkpointing etc.) but it still has to > do significantly more transactions than in the batched version. > > Typically there is an optimum batch size: if batch size is too small > (say, one row) the ratio of TX overhead to "work" is too bad. If > batch size is too large (say, millions of rows) you hit resource > limitations (memory) which inevitable force the RDBMS to do additional > disk IO. > > Kind regards > > robert > Thanks Ken and Robert, What I am observing is definitely not readers blocked by writers by means of row-level locking. This seems to be some implementation detail in Postgres about how dirty pages (or dead versions of tuples) are flushed to the disk (see the other parts of this thread) when they accessed by a SELECT query. The batch size in this case is one SELECT statement accessing 10000 rows via an aggregate (such as COUNT) and an UPDATE updating 10000 rows in a single statement. I am not trying to optimize this particular use case, but rather to understand what Postgres is doing, and why SELECT queries are affected negatively (sometimes severely) by concurrent (or even preceding) UPDATEs at all when the database resides in the cache completely. -- Lars