Re: LWLock contention: I think I understand the problem

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org, "Jeffrey W(dot) Baker" <jwbaker(at)acm(dot)org>
Subject: Re: LWLock contention: I think I understand the problem
Date: 2001-12-29 19:45:28
Message-ID: 19542.1009655128@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-odbc

Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> I still need to think about this, but the above idea doesn't seem good.
> Right now, we wake only one waiting process who gets the lock while
> other waiters stay sleeping, right? If we don't give them the lock,
> don't we have to wake up all the waiters?

No. We'll still wake up the same processes as now: either one would-be
exclusive lock holder, or multiple would-be shared lock holders.
But what I'm proposing is that they don't get granted the lock at that
instant; they have to try to get the lock once they actually start to
run.

Once in a while, they'll fail to get the lock, either because the
original releaser reacquired the lock, and then ran out of his time
quantum before releasing it, or because some third process came along
and acquired the lock. In either of these scenarios they'd have to
block again, and we'd have wasted a process dispatch cycle. The
important thing though is that the current arrangement wastes a process
dispatch cycle for every acquisition of a contended-for lock.

What I had not really focused on before, but it's now glaringly obvious,
is that on modern machines one process time quantum (0.01 sec typically)
is enough time for a LOT of computation, in particular an awful lot of
trips through the buffer manager or other modules with shared state.
We want to be sure that a process can repeatedly acquire and release
the shared lock for as long as its time quantum holds out, even if there
are other processes waiting for the lock. Otherwise we'll be swapping
processes too often.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2001-12-29 19:46:18 Re: LWLock contention: I think I understand the problem
Previous Message Bruce Momjian 2001-12-29 19:37:15 Re: LWLock contention: I think I understand the problem

Browse pgsql-odbc by date

  From Date Subject
Next Message Tom Lane 2001-12-29 19:46:18 Re: LWLock contention: I think I understand the problem
Previous Message Bruce Momjian 2001-12-29 19:37:15 Re: LWLock contention: I think I understand the problem