Re: [COMMITTERS] pgsql: Make walsender more responsive.

Lists: pgsql-committerspgsql-hackers
From: Robert Haas <rhaas(at)postgresql(dot)org>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Make walsender more responsive.
Date: 2012-07-02 13:49:27
Message-ID: E1Slh0J-0005he-05@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

Make walsender more responsive.

Per testing by Andres Freund, this improves replication performance
and reduces replication latency and latency jitter. I was a bit
concerned about moving more work into XLogInsert, but testing seems
to show that it's not a problem in practice.

Along the way, improve comments for WaitLatchOrSocket.

Andres Freund. Review and stylistic cleanup by me.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/f83b59997d29f06c3d67e7eb9a1f2c9cd017d665

Modified Files
--------------
src/backend/access/transam/twophase.c | 21 ---------------------
src/backend/access/transam/xact.c | 7 -------
src/backend/access/transam/xlog.c | 25 ++++++++++++++++++-------
src/backend/port/unix_latch.c | 3 +++
src/backend/port/win32_latch.c | 4 ++++
src/backend/replication/walsender.c | 11 ++++++++++-
src/include/replication/walsender.h | 24 ++++++++++++++++++++++++
7 files changed, 59 insertions(+), 36 deletions(-)


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Haas <rhaas(at)postgresql(dot)org>
Cc: pgsql-committers(at)postgresql(dot)org
Subject: Re: pgsql: Make walsender more responsive.
Date: 2012-07-02 14:34:34
Message-ID: 16259.1341239674@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

Robert Haas <rhaas(at)postgresql(dot)org> writes:
> Make walsender more responsive. ...
> Andres Freund. Review and stylistic cleanup by me.

The comments could have used a bit more copy-editing.

(I got a good laugh out of the idea of "contented locks".)

regards, tom lane


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Haas <rhaas(at)postgresql(dot)org>, pgsql-committers(at)postgresql(dot)org
Subject: Re: pgsql: Make walsender more responsive.
Date: 2012-07-02 14:53:31
Message-ID: CA+TgmoYT2G=Eb4ZAyrvhB0qSgx1OC6OaaOs0sj+fVgd1C+AX4A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

On Mon, Jul 2, 2012 at 10:34 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Robert Haas <rhaas(at)postgresql(dot)org> writes:
>> Make walsender more responsive. ...
>> Andres Freund. Review and stylistic cleanup by me.
>
> The comments could have used a bit more copy-editing.
>
> (I got a good laugh out of the idea of "contented locks".)

Uh... what? I thought the meaning of that was perfectly clear.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: pgsql-committers(at)postgresql(dot)org
Subject: Re: pgsql: Make walsender more responsive.
Date: 2012-07-02 15:06:16
Message-ID: 16851.1341241576@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> On Mon, Jul 2, 2012 at 10:34 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> (I got a good laugh out of the idea of "contented locks".)

> Uh... what? I thought the meaning of that was perfectly clear.

My dictionary defines "contented" as "happy and at ease". I think
the word intended here is "contended":

+ /* wakeup the WalSnd now that we outside contented locks */

not to mention that this sentence no verb. I don't hold such things
against patch submitters whose first language isn't English, but
committers whose first language *is* English ought to fix them.

regards, tom lane


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-committers(at)postgresql(dot)org
Subject: Re: pgsql: Make walsender more responsive.
Date: 2012-07-02 15:19:39
Message-ID: CA+TgmoZdPKrSWHfmLdkhzybMnc8nisfBrmac96d5uu8qUiT=0Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

On Mon, Jul 2, 2012 at 11:06 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Robert Haas <robertmhaas(at)gmail(dot)com> writes:
>> On Mon, Jul 2, 2012 at 10:34 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>> (I got a good laugh out of the idea of "contented locks".)
>
>> Uh... what? I thought the meaning of that was perfectly clear.
>
> My dictionary defines "contented" as "happy and at ease". I think
> the word intended here is "contended":

Oh, nuts. My eyes skimmed right over that one after you pointed it out.

> + /* wakeup the WalSnd now that we outside contented locks */
>
> not to mention that this sentence no verb. I don't hold such things
> against patch submitters whose first language isn't English, but
> committers whose first language *is* English ought to fix them.

OK.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: David Fetter <david(at)fetter(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Haas <rhaas(at)postgresql(dot)org>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [COMMITTERS] pgsql: Make walsender more responsive.
Date: 2012-07-02 15:49:05
Message-ID: 20120702154905.GB21013@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

On Mon, Jul 02, 2012 at 10:34:34AM -0400, Tom Lane wrote:
> Robert Haas <rhaas(at)postgresql(dot)org> writes:
> > Make walsender more responsive. ... Andres Freund. Review and
> > stylistic cleanup by me.
>
> The comments could have used a bit more copy-editing.
>
> (I got a good laugh out of the idea of "contented locks".)

I say we leave it in there ;)

Cheers,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david(dot)fetter(at)gmail(dot)com
iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate


From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Robert Haas <rhaas(at)postgresql(dot)org>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [COMMITTERS] pgsql: Make walsender more responsive.
Date: 2012-07-02 17:19:19
Message-ID: CAHGQGwF4=d8XpW5bwUTn=eanpg9E+t-FM_L597WcJ4adx8K5-Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

On Mon, Jul 2, 2012 at 10:49 PM, Robert Haas <rhaas(at)postgresql(dot)org> wrote:
> Make walsender more responsive.
>
> Per testing by Andres Freund, this improves replication performance
> and reduces replication latency and latency jitter. I was a bit
> concerned about moving more work into XLogInsert, but testing seems
> to show that it's not a problem in practice.
>
> Along the way, improve comments for WaitLatchOrSocket.

This commit makes the synchronous replication slow down very much
when wal_sync_method is set to open_sync or open_datasync. I think
the attached patch needs to be applied.

+#define WalSndWakeupProcessRequests() \
+ do \
+ { \
+ if (wake_wal_senders) \
+ { \
+ wake_wal_senders = false; \
+ if (max_wal_senders > 0) \
+ WalSndWakeup(); \
+ } \
+ } while (0)

I'm not sure it's really worth doing, but isn't it good idea to test
max_wal_sender > 0 first to eliminate any CPU cycle in non replication case?

Regards,

--
Fujii Masao

Attachment Content-Type Size
bugfix_v1.patch application/octet-stream 616 bytes

From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, Robert Haas <rhaas(at)postgresql(dot)org>
Subject: Re: [COMMITTERS] pgsql: Make walsender more responsive.
Date: 2012-07-02 17:53:25
Message-ID: 201207021953.25468.andres@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

On Monday, July 02, 2012 07:19:19 PM Fujii Masao wrote:
> On Mon, Jul 2, 2012 at 10:49 PM, Robert Haas <rhaas(at)postgresql(dot)org> wrote:
> > Make walsender more responsive.
> >
> > Per testing by Andres Freund, this improves replication performance
> > and reduces replication latency and latency jitter. I was a bit
> > concerned about moving more work into XLogInsert, but testing seems
> > to show that it's not a problem in practice.
> >
> > Along the way, improve comments for WaitLatchOrSocket.
>
> This commit makes the synchronous replication slow down very much
> when wal_sync_method is set to open_sync or open_datasync. I think
> the attached patch needs to be applied.
Hm. Yes, definitely. No idea why I placed the call there, sorry.

Thats how synchronous_write=off behaved generally till the recent (simple) fix
btw ;)

> +#define WalSndWakeupProcessRequests() \
> + do \
> + { \
> + if (wake_wal_senders) \
> + { \
> + wake_wal_senders = false; \
> + if (max_wal_senders > 0) \
> + WalSndWakeup(); \
> + } \
> + } while (0)
>
> I'm not sure it's really worth doing, but isn't it good idea to test
> max_wal_sender > 0 first to eliminate any CPU cycle in non replication
> case?
I think the difference is ignorable. wake_wal_senders probably has better
cache locality but is set to true more often, but not that often...

Thanks,

Andres
--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, Robert Haas <rhaas(at)postgresql(dot)org>
Subject: Re: [COMMITTERS] pgsql: Make walsender more responsive.
Date: 2012-07-02 18:50:23
Message-ID: CA+Tgmob69X5VkULo4WTjTZEns8WxXdJVOKgLfcsDjyAu7NzLxA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

On Mon, Jul 2, 2012 at 1:53 PM, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
>> This commit makes the synchronous replication slow down very much
>> when wal_sync_method is set to open_sync or open_datasync. I think
>> the attached patch needs to be applied.
> Hm. Yes, definitely. No idea why I placed the call there, sorry.

Committed.

>> +#define WalSndWakeupProcessRequests() \
>> + do \
>> + { \
>> + if (wake_wal_senders) \
>> + { \
>> + wake_wal_senders = false; \
>> + if (max_wal_senders > 0) \
>> + WalSndWakeup(); \
>> + } \
>> + } while (0)
>>
>> I'm not sure it's really worth doing, but isn't it good idea to test
>> max_wal_sender > 0 first to eliminate any CPU cycle in non replication
>> case?
> I think the difference is ignorable. wake_wal_senders probably has better
> cache locality but is set to true more often, but not that often...

I was wondering if we shouldn't do this as:

if (max_wal_senders > 0 && wake_wal_senders)
WalSndWakeup();

....and then put wake_wal_senders = false into WalSndWakeup().

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company