Re: SSI performance

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: "Dan Ports" <drkp(at)csail(dot)mit(dot)edu>, "Heikki Linnakangas" <heikki(dot)linnakangas(at)enterprisedb(dot)com>
Cc: "PostgreSQL-development" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: SSI performance
Date: 2011-02-04 17:29:15
Message-ID: 4D4BE30B020000250003A3E6@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com> wrote:

> The logic of PredicateLockAcquire is:
>
> 1. Check if we already have a lock on the tuple.
> 2. Check if we already have a lock on the page.
> 3. Check if we already have a lock on the relation.
>
> So if you're accessing a lot of rows, so that your lock is
> promoted to a relation lock, you perform three hash table lookups
> on every PredicateLockAcquire() call to notice that you already
> have the lock.
>
> I was going to put a note at the beginning of this mail saying
> upfront that this is 9.2 materila, but it occurs to me that we
> could easily just reverse the order of those tests. That would cut
> the overhead of the case where you already have a relation lock by
> 2/3, but make the case where you already have a tuple lock slower.
> Would that be a good tradeoff?

The problem with that is that we'd need to figure out how to handle
LW locking. The target at each level may be protected by a
different partition lock, so locks must be released and acquired for
each level checked. When we promote granularity we add to the
higher level first and then remove from the lower level, again
protected by potentially different partition locks. To avoid having
a search miss during concurrent promotion, we did the searches from
the finer to the coarser granularity. In early benchmarks we were
held up mostly by LW lock contention, and went to some effort to
rearrange locking to minimize that; we'd need to be very careful
trying to go the other direction here.

I just had a thought -- we already have the LocalPredicateLockHash
HTAB to help with granularity promotion issues without LW locking.
Offhand, I can't see any reason we couldn't use this for an initial
check for a relation level lock, before going through the more
rigorous pass under cover of the locks. We won't have a relation
lock showing in the local table if it never was taken out, and it
won't go away until the end of transaction (unless the whole
transaction is deamed safe from SSI conflicts and everything is
cleaned up early).

Dan, does that look sane to you, or am I having another "senior
moment" here?

If this works, it would be a very minor change, which might
eliminate a lot of that overhead for many common cases.

-Kevin

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2011-02-04 17:29:59 Re: arrays as pl/perl input arguments [PATCH]
Previous Message Robert Haas 2011-02-04 17:17:32 more buildfarm breakage