Re: [PERFORM] Cpu usage 100% on slave. s_lock problem.

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: Дмитрий Дегтярёв <degtyaryov(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PERFORM] Cpu usage 100% on slave. s_lock problem.
Date: 2013-09-27 19:00:25
Message-ID: CAHyXU0x4whBio1S1prZ6BSwvD0LdT=7Ok7QZWVQwpcZW35t_yA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Sep 27, 2013 at 7:56 AM, Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:
> On Thu, Sep 26, 2013 at 10:14 PM, Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:
>> On Thu, Sep 26, 2013 at 6:08 PM, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
>>> On 2013-08-27 12:17:55 -0500, Merlin Moncure wrote:
>>>> On Tue, Aug 27, 2013 at 10:55 AM, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
>>>> > On 2013-08-27 09:57:38 -0500, Merlin Moncure wrote:
>>>> >> + bool
>>>> >> + RecoveryMightBeInProgress(void)
>>>> >> + {
>>>> >> + /*
>>>> >> + * We check shared state each time only until we leave recovery mode. We
>>>> >> + * can't re-enter recovery, so there's no need to keep checking after the
>>>> >> + * shared variable has once been seen false.
>>>> >> + */
>>>> >> + if (!LocalRecoveryInProgress)
>>>> >> + return false;
>>>> >> + else
>>>> >> + {
>>>> >> + /* use volatile pointer to prevent code rearrangement */
>>>> >> + volatile XLogCtlData *xlogctl = XLogCtl;
>>>> >> +
>>>> >> + /* Intentionally query xlogctl without spinlocking! */
>>>> >> + LocalRecoveryInProgress = xlogctl->SharedRecoveryInProgress;
>>>> >> +
>>>> >> + return LocalRecoveryInProgress;
>>>> >> + }
>>>> >> + }
>>>> >
>>>> > I don't think it's acceptable to *set* LocalRecoveryInProgress
>>>> > here. That should only be done in the normal routine.
>>>>
>>>> quite right -- that was a major error -- you could bypass the
>>>> initialization call to the xlog with some bad luck.
>>>
>>> I've seen this in profiles since, so I'd appreciate pushing this
>>> forward.
>>
>> roger that -- will push ahead when I get into the office...
>
> attached is new version fixing some comment typos.

Attached is simplified patch that replaces the spinlock with a read
barrier based on a suggestion made by Andres offlist. The approach
has different performance characteristics -- a barrier call is being
issued instead of a non-blocking read. I don't have a performance
test case in hand to prove that's better so I'm going with Andre's
approach because it's simpler. Aside: can this truly the only caller
of pg_read_barrier()?

Also, moving to -hackers from -performance.

merlin

Attachment Content-Type Size
recovery5.patch application/octet-stream 1.3 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jim Nasby 2013-09-27 19:14:35 Re: Minmax indexes
Previous Message Greg Stark 2013-09-27 18:43:51 Re: Minmax indexes