pgsql: Allocate consecutive blocks during parallel seqscans - Mailing list pgsql-committers

From David Rowley
Subject pgsql: Allocate consecutive blocks during parallel seqscans
Date
Msg-id E1jzcZ0-0002Ej-FG@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Allocate consecutive blocks during parallel seqscans

Previously we would allocate blocks to parallel workers during a parallel
sequential scan 1 block at a time.  Since other workers were likely to
request a block before a worker returns for another block number to work
on, this could lead to non-sequential I/O patterns in each worker which
could cause the operating system's readahead to perform poorly or not at
all.

Here we change things so that we allocate consecutive "chunks" of blocks
to workers and have them work on those until they're done, at which time
we allocate another chunk for the worker.  The size of these chunks is
based on the size of the relation.

Initial patch here was by Thomas Munro which showed some good improvements
just having a fixed chunk size of 64 blocks with a simple ramp-down near
the end of the scan. The revisions of the patch to make the chunk size
based on the relation size and the adjusted ramp-down in powers of two was
done by me, along with quite extensive benchmarking to determine the
optimal chunk sizes.

For the most part, benchmarks have shown significant performance
improvements for large parallel sequential scans on Linux, FreeBSD and
Windows using SSDs.  It's less clear how this affects the performance of
cloud providers.  Tests done so far are unable to obtain stable enough
performance to provide meaningful benchmark results.  It is possible that
this could cause some performance regressions on more obscure filesystems,
so we may need to later provide users with some ability to get something
closer to the old behavior.  For now, let's leave that until we see that
it's really required.

Author: Thomas Munro, David Rowley
Reviewed-by: Ranier Vilela, Soumyadeep Chakraborty, Robert Haas
Reviewed-by: Amit Kapila, Kirk Jamison
Discussion: https://postgr.es/m/CA+hUKGJ_EErDv41YycXcbMbCBkztA34+z1ts9VQH+ACRuvpxig@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/56788d2156fc32bd5737e7ac716d70e6a269b7bc

Modified Files
--------------
src/backend/access/heap/heapam.c   |  22 +++++--
src/backend/access/table/tableam.c | 118 +++++++++++++++++++++++++++++++++++--
src/include/access/relscan.h       |  14 ++++-
src/include/access/tableam.h       |   2 +
4 files changed, 144 insertions(+), 12 deletions(-)


pgsql-committers by date:

Previous
From: Michael Paquier
Date:
Subject: pgsql: Tweak behavior of pg_stat_activity.leader_pid
Next
From: Jeff Davis
Date:
Subject: pgsql: Fix LookupTupleHashEntryHash() pipeline-stall issue.