Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 8FBDD63461B for ; Wed, 18 Mar 2009 09:06:59 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 45505-08 for ; Wed, 18 Mar 2009 09:06:45 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outmail136056.authsmtp.com (outmail136056.authsmtp.com [62.13.136.56]) by mail.postgresql.org (Postfix) with ESMTP id 447ED6331F0 for ; Wed, 18 Mar 2009 09:06:51 -0300 (ADT) Received: from mail-c189.authsmtp.com (mail-c189.authsmtp.com [62.13.128.71]) by punt7.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id n2IC6lkY083528; Wed, 18 Mar 2009 12:06:47 GMT Received: from [192.168.0.2] (85-211-223-92.dyn.gotadsl.co.uk [85.211.223.92]) (authenticated bits=0) by mail.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id n2IC6kSU001743; Wed, 18 Mar 2009 12:06:46 GMT Subject: Re: Proposal of tunable fix for scalability of 8.4 From: Simon Riggs To: Matthew Wakeling Cc: "pgsql-performance@postgresql.org" In-Reply-To: References: <603c8f070903121829r31cf1472ha9876e5c480a542e@mail.gmail.com> <12292.1236964604@sss.pgh.pa.us> <49BB699D.1070809@enterprisedb.com> <1237362833.3953.186.camel@ebony.2ndQuadrant> Content-Type: text/plain Date: Wed, 18 Mar 2009 12:06:49 +0000 Message-Id: <1237378009.3953.303.camel@ebony.2ndQuadrant> Mime-Version: 1.0 X-Mailer: Evolution 2.12.0 Content-Transfer-Encoding: 7bit X-Server-Quench: 411fafb8-13b5-11de-bc7b-001f29070be2 X-AuthRoute: OCdxZQATClZOTQEd DAteCiNZVAwpPBRK HVkIKg5MJUcNSQVJ NksadBtFaQ1bYFhD HGQLW11EUV97WWV/ bw0fZQBDYEtPQQdo U1ZAQE1QEQdtHhxP WBxnIR8pFGBGeH93 YUUsXXldWwp+dEcr ExgGHXAHZjVldWEe BBVFJVBTIh5Kfh4T aFl/U3NfNGdJBC9q VzwLEgofGg96HWxt WAYVKkkbRQ4MEHYg WhYLFzEiVUMEV209 KAZuMVUVGE8bM0Ez LUppXlxQY1lOYiwg X-Authentic-SMTP: 61633235383639.kestrel.dmpriest.net.uk:1378/Kp X-Report-SPAM: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-Virus-Status: No virus detected - but ensure you scan with your own anti-virus system. X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200903/248 X-Sequence-Number: 33170 On Wed, 2009-03-18 at 11:45 +0000, Matthew Wakeling wrote: > On Wed, 18 Mar 2009, Simon Riggs wrote: > > I agree with that, apart from the "granting no more" bit. > > > > The most useful behaviour is just to have two modes: > > * exclusive-lock held - all other x locks welcome, s locks queue > > * shared-lock held - all other s locks welcome, x locks queue > > The problem with making all other locks welcome is that there is a > possibility of starvation. Imagine a case where there is a constant stream > of shared locks - the exclusive locks may never actually get hold of the > lock under the "all other shared locks welcome" strategy. That's exactly what happens now. > Likewise with the reverse. I think it depends upon how frequently requests arrive. Commits cause X locks and we don't commit that often, so its very unlikely that we'd see a constant stream of X locks and prevent shared lockers. Some comments from an earlier post on this topic (about 20 months ago): Since shared locks are currently queued behind exclusive requests when they cannot be immediately satisfied, it might be worth reconsidering the way LWLockRelease works also. When we wake up the queue we only wake the Shared requests that are adjacent to the head of the queue. Instead we could wake *all* waiting Shared requestors. e.g. with a lock queue like this: (HEAD) S<-S<-X<-S<-X<-S<-X<-S Currently we would wake the 1st and 2nd waiters only. If we were to wake the 3rd, 5th and 7th waiters also, then the queue would reduce in length very quickly, if we assume generally uniform service times. (If the head of the queue is X, then we wake only that one process and I'm not proposing we change that). That would mean queue jumping right? Well thats what already happens in other circumstances, so there cannot be anything intrinsically wrong with allowing it, the only question is: would it help? We need not wake the whole queue, there may be some generally more beneficial heuristic. The reason for considering this is not to speed up Shared requests but to reduce the queue length and thus the waiting time for the Xclusive requestors. Each time a Shared request is dequeued, we effectively re-enable queue jumping, so a Shared request arriving during that point will actually jump ahead of Shared requests that were unlucky enough to arrive while an Exclusive lock was held. Worse than that, the new incoming Shared requests exacerbate the starvation, so the more non-adjacent groups of Shared lock requests there are in the queue, the worse the starvation of the exclusive requestors becomes. We are effectively randomly starving some shared locks as well as exclusive locks in the current scheme, based upon the state of the lock when they make their request. The situation is worst when the lock is heavily contended and the workload has a 50/50 mix of shared/exclusive requests, e.g. serializable transactions or transactions with lots of subtransactions. -- Simon Riggs www.2ndQuadrant.com PostgreSQL Training, Services and Support