From: | Alexander Korotkov <aekorotkov(at)gmail(dot)com> |
---|---|
To: | Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> |
Cc: | Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>, Kartyshov Ivan <i(dot)kartyshov(at)postgrespro(dot)ru>, Euler Taveira <euler(at)eulerto(dot)com>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, Peter Eisentraut <peter(at)eisentraut(dot)org>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, Peter Smith <smithpb2250(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org |
Subject: | Re: [HACKERS] make async slave to wait for lsn to be replayed |
Date: | 2024-04-03 08:42:11 |
Message-ID: | CAPpHfdsdu=h2viUprMg8XBh_ouNMB8_hM9yL8wpy8+ScSoDL-g@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi, Alvaro!
Thank you for your feedback.
On Wed, Apr 3, 2024 at 9:58 AM Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> wrote:
> Hello, I noticed that commit 06c418e163e9 uses waitLSN->mutex (a
> spinlock) to protect the contents of waitLSN -- and it's used to walk an
> arbitrary long list of processes waiting ... and also, an arbitrary
> number of processes could be calling this code. I think using a
> spinlock for this is unwise, as it'll cause busy-waiting whenever
> there's contention. Wouldn't it be better to use an LWLock for this?
> Then the processes would sleep until the lock is freed.
>
> While nosing about the code, other things struck me:
>
> I think there should be more comments about WaitLSNProcInfo and
> WaitLSNState in waitlsn.h.
>
> In addLSNWaiter it'd be better to assign 'cur' before acquiring the
> lock.
>
> Is a plan array really the most efficient data structure for this,
> considering that you have to reorder each time you add an element?
> Maybe it is, but wouldn't it make sense to use memmove() when adding one
> element rather iterating all the remaining elements to the end of the
> queue?
>
> I think the include list in waitlsn.c could be tightened a bit:
I've just pushed commit, which shortens the include list and fixes the
order of 'cur' assigning and taking spinlock in addLSNWaiter().
Regarding the shmem data structure for LSN waiters. I didn't pick
LWLock or ConditionVariable, because I needed the ability to wake up
only those waiters whose LSN is already replayed. In my experience
waking up a process is way slower than scanning a short flat array.
However, I agree that when the number of waiters is very high and flat
array may become a problem. It seems that the pairing heap is not
hard to use for shmem structures. The only memory allocation call in
paritingheap.c is in pairingheap_allocate(). So, it's only needed to
be able to initialize the pairing heap in-place, and it will be fine
for shmem.
I'll come back with switching to the pairing heap shortly.
------
Regards,
Alexander Korotkov
From | Date | Subject | |
---|---|---|---|
Next Message | Jeff Davis | 2024-04-03 08:45:55 | Re: Improve eviction algorithm in ReorderBuffer |
Previous Message | Jakub Wartak | 2024-04-03 08:41:42 | Re: Use streaming read API in ANALYZE |