Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id CC9F0B5DC39 for ; Mon, 11 Jul 2011 21:09:56 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 67692-01 for ; Tue, 12 Jul 2011 00:09:50 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from nm20.bullet.mail.bf1.yahoo.com (nm20.bullet.mail.bf1.yahoo.com [98.139.212.179]) by mail.postgresql.org (Postfix) with SMTP id 1D8C1B5DC3E for ; Mon, 11 Jul 2011 21:09:50 -0300 (ADT) Received: from [98.139.212.151] by nm20.bullet.mail.bf1.yahoo.com with NNFMP; 12 Jul 2011 00:09:49 -0000 Received: from [98.139.211.198] by tm8.bullet.mail.bf1.yahoo.com with NNFMP; 12 Jul 2011 00:09:49 -0000 Received: from [127.0.0.1] by smtp207.mail.bf1.yahoo.com with NNFMP; 12 Jul 2011 00:09:49 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1310429389; bh=vsCmjK0dKy0eE3c5ohCbSwxcINreBN897H6H6nd7ZXU=; 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=WI1hu+Yk2D0L3yRLpN3pbmWFx4Zcx5+EYJDu+wYKzsFR6g1xEsAIbuW9wMXHTcDugOPaaGaKXF1uv2LgRon04u/MWCTjEKSHaAQxCO5bCWNYqTqpp2QtLVTCu+3KrM9wczHIIy7PVlYbo0rDrlNR9DveHels0XBm6EUZX7L5wsI= X-Yahoo-Newman-Id: 564328.83347.bm@smtp207.mail.bf1.yahoo.com Received: from [192.168.206.5] (lhofhansl@67.170.234.149 with plain) by smtp207.mail.bf1.yahoo.com with SMTP; 11 Jul 2011 17:09:48 -0700 PDT X-Yahoo-SMTP: YmezqLWswBDx0ai534H100MJuqGzDQ-- X-YMail-OSG: 0mdIgFgVM1kotS2ivPu6nHpeU6aiaToBsQNvsxgeV.Eu_iT JD0IrW.8EOCeVaZTZ5SjY.Caq9UpwiNXKkm0_c_ERJpyYdLz84G.8gJJIY85 pFVvrk7Z6aHXRzK3ZDy3DQcs5JK4IWvBMdV_S2dmfwN9NhfIC1lSw9lys9A0 12GyN4ZOdLsyda5MtotJBPHCck0kcvYUCDtWFa19_YdudtrWrcqoh_G6eWWC yeG8henLPDEGb8knLX3OIlYch1gDw7NHlcbIUxTFdd8CGVrf24kWi4tI77Id jx5IVci8BYFamJWsZfc9Qijwb6OBYm4mJhQixa.irFIjbKP0zQYsKNiNPjI6 sr10ZaGamsMKEhrLmexUoFQ-- X-Yahoo-Newman-Property: ymail-3 Message-ID: <4E1B90AF.1020408@yahoo.com> Date: Mon, 11 Jul 2011 17:09:19 -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: Merlin Moncure CC: Kevin Grittner , pgsql-performance@postgresql.org, Craig Ringer Subject: Re: UPDATEDs slowing SELECTs in a fully cached database References: <4E16479D.3050605@yahoo.com> <4E1A0CBC.6090009@yahoo.com> <4E1A31AB.9010201@postnewspapers.com.au> <1310359653.80687.YahooMailRC@web121705.mail.ne1.yahoo.com> <4E1AEDAB020000250003F1C3@gw.wicourts.gov> <4E1B41EA.90104@yahoo.com> <4E1B05CC020000250003F1E6@gw.wicourts.gov> <4E1B810D.4070404@yahoo.com> In-Reply-To: <4E1B810D.4070404@yahoo.com> 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.909 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201107/105 X-Sequence-Number: 44317 On 07/11/2011 04:02 PM, lars wrote: > On 07/11/2011 02:43 PM, Merlin Moncure wrote: >> On Mon, Jul 11, 2011 at 2:16 PM, Kevin Grittner >> wrote: >>> lars wrote: >>> >>>> Stopping the UPDATEs, waiting for any CHECKPOINTs to finish, >>>> and then running the SELECTs indeed shows a similar slowdown. >>>> >>>> Interestingly I see very heavy WAL traffic while executing the >>>> SELECTs. (So I was confused as to what caused the WAL traffic). >>> Hint bit changes aren't logged, so if it was that you would be >>> seeing writes to the heap, but not to the WAL. Clean-up of dead >>> tuples is logged -- this is probably the result of pruning dead >>> tuples. You could probably reduce the impact on your SELECT >>> statements at least a little by making autovacuum more aggressive. >> yeah. In fact, I'd like to disable autovacuum completely just to >> confirm this. In particular I'd like to know if that removes wal >> traffic when only selects are going on. Another way to check is to >> throw some queries to pg_stat_activity during your select period and >> see if any non-select activity (like autovacum vacuum). Basically I'm >> suspicious there is more to this story. >> >> hint bit flusing causing i/o during SELECT is a typical complaint >> (especially on systems with underperformant i/o), but I'm suspicious >> if that's really the problem here. Since you are on a virtualized >> platform, I can't help but wonder if you are running into some >> bottleneck that you wouldn't see on native hardware. >> >> What's iowait during the slow period? >> >> merlin > Thanks Kevin and Merlin this is extremely helpful... > > Ok, that makes much more sense (WALing hint bits did not make sense). > > I disabled auto-vacuum and did four tests: > 1. Run a bunch of updates, stop that process, wait until checkpointing > is finished, and run the selects (as before). > 2. run VACUUM manually, then run the SELECTs > 3. Have the UPDATEs and SELECTs touch a mutually exclusive, random > sets of row (still in sets of 10000). > So the SELECTs are guaranteed not to select rows that were updated. > 4. Lastly, change the UPDATEs to update a non-indexed column. To rule > out Index maintenance. Still distinct set of rows. > > In the first case I see the same slowdown (from ~14ms to ~400-500ms). > pg_stat_activity shows no other load during that > time. I also see write activity only on the WAL volume. > > In the 2nd case after VACUUM is finished the time is back to 14ms. As > an aside: If I run the SELECTs while VACUUM is > running the slowdown is about the same as in the first case until > (apparently) VACUUM has cleaned up most of the table, > at which point the SELECTs become faster again (~50ms). > > In the 3rd case I see exactly the same behavior, which is interesting. > Both before VACUUM is run and after. > There's no guarantee obviously that distinct rows do not share the > same page of course especially since the index is > updated as part of this (but see the 4th case). > > In case 4 I still see the same issue. Again both before and after VACUUM. > > In all cases I see from pg_stat_bgwriter that no backend writes > buffers directly (but I think that only pertains to dirty buffers, and > not the WAL). > > So I think I have a partial answer to my initial question. > > However, that brings me to some other questions: > Why do SELECTs cause dead tuples to be pruned (as Kevin suggests)? > That even happens when the updates did not touch the selected rows(?) > And why does that slow down the SELECTs? (checkpointing activity on > the EBS volume holding the database for example > does not slow down SELECTs at all, only WAL activity does). Does the > selecting backend do that work itself? > > Lastly, is this documented somewhere? (I apologize if it is and I > missed it). If not I'd be happy to write a wiki entry for this. > > Oh, and iowait hovers around 20% when SELECTs are slow: avg-cpu: %user %nice %system %iowait %steal %idle 1.54 0.00 0.98 18.49 0.07 78.92 When SELECTs are fast it looks like this: avg-cpu: %user %nice %system %iowait %steal %idle 8.72 0.00 0.26 0.00 0.00 91.01 Note that this is a 12 core VM. So one core at 100% would show as 8.33% CPU.