pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Robert Haas <rhaas@postgresql.org>
To: pgsql-committers@postgresql.org
Subject: pgsql: shm_mq: Reduce spinlock usage.
Date: Fri, 02 Mar 2018 17:19:58 +0000
Message-ID: <E1eroLe-0003nE-NJ@gemulon.postgresql.org> (raw)

shm_mq: Reduce spinlock usage.

Previously, mq_bytes_read and mq_bytes_written were protected by the
spinlock, but that turns out to cause pretty serious spinlock
contention on queries which send many tuples through a Gather or
Gather Merge node.  This patches changes things so that we instead
read and write those values using 8-byte atomics.  Since mq_bytes_read
can only be changed by the receiver and mq_bytes_written can only be
changed by the sender, the only purpose of the spinlock is to prevent
reads and writes of these values from being torn on platforms where
8-byte memory access is not atomic, making the conversion fairly
straightforward.

Testing shows that this produces some slowdown if we're using emulated
64-bit atomics, but since they should be available on any platform
where performance is a primary concern, that seems OK.  It's faster,
sometimes a lot faster, on platforms where such atomics are available.

Patch by me, reviewed by Andres Freund, who also suggested the
design.  Also tested by Rafia Sabih.

Discussion: http://postgr.es/m/CA+TgmoYuK0XXxmUNTFT9TSNiBtWnRwasBcHHRCOK9iYmDLQVPg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/34db06ef9a1d7f36391c64293bf1e0ce44a33915

Modified Files
--------------
src/backend/storage/ipc/shm_mq.c | 251 ++++++++++++++++++++-------------------
1 file changed, 129 insertions(+), 122 deletions(-)



Message-ID: <E1eroLe-0003nE-NJ@gemulon.postgresql.org>
Permalink:  ../E1eroLe-0003nE-NJ@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1eroLe-0003nE-NJ@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: rhaas@postgresql.org
  Subject: Re: pgsql: shm_mq: Reduce spinlock usage.
  In-Reply-To: <E1eroLe-0003nE-NJ@gemulon.postgresql.org>
  References: <E1eroLe-0003nE-NJ@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox