Re: Is the unfair lwlock behavior intended?

From: Andres Freund <andres(at)anarazel(dot)de>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Ants Aasma <ants(dot)aasma(at)eesti(dot)ee>, "Tsunakawa, Takayuki" <tsunakawa(dot)takay(at)jp(dot)fujitsu(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Is the unfair lwlock behavior intended?
Date: 2016-05-24 22:26:41
Message-ID: 20160524222641.ygq2qo6xnw7af7dl@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2016-05-24 17:20:48 -0400, Robert Haas wrote:
> On Tue, May 24, 2016 at 4:39 PM, Ants Aasma <ants(dot)aasma(at)eesti(dot)ee> wrote:
> > On Tue, May 24, 2016 at 9:03 AM, Tsunakawa, Takayuki
> > <tsunakawa(dot)takay(at)jp(dot)fujitsu(dot)com> wrote:
> >> I encountered a strange behavior of lightweight lock in PostgreSQL 9.2. That appears to apply to 9.6, too, as far as I examine the code. Could you tell me if the behavior is intended or needs fix?
> >>
> >> Simply put, the unfair behavior is that waiters for exclusive mode are overtaken by share-mode lockers who arrive later.

Are you sure you're actually queued behind share locks, and not
primarily behind the lwlock's spinlocks? The latter is what I've seen in
similar cases.

> > 9.5 had significant LWLock scalability improvements. This might
> > improve performance enough so that exclusive lockers don't get
> > completely starved. It would be helpful if you could test if it's
> > still possible to trigger starvation with the new code.
>
> 9.5 didn't just increase the scalability; it also whacked the fairness
> aspects of this code around.

True, but the difference isn't that big. As the commit says:

> and the fairness isn't really much worse than before, as we always
> allowed new shared lockers to jump the queue.

if you have lots of incoming locks, as it appears to be the case for th
OP, the fact that queued share locks are woken up earlier doesn't make
much of a difference.

Regards,

Andres

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2016-05-24 22:34:31 Re: Is the unfair lwlock behavior intended?
Previous Message Jeff Janes 2016-05-24 22:22:01 Re: effective_io_concurrency in 9.6beta