pgsql: Improve performance of subsystems on top of SLRU

Поиск
Список
Период
Сортировка
От Alvaro Herrera
Тема pgsql: Improve performance of subsystems on top of SLRU
Дата
Msg-id E1rfMSf-001FbI-Co@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Improve performance of subsystems on top of SLRU

More precisely, what we do here is make the SLRU cache sizes
configurable with new GUCs, so that sites with high concurrency and big
ranges of transactions in flight (resp. multixacts/subtransactions) can
benefit from bigger caches.  In order for this to work with good
performance, two additional changes are made:

1. the cache is divided in "banks" (to borrow terminology from CPU
   caches), and algorithms such as eviction buffer search only affect
   one specific bank.  This forestalls the problem that linear searching
   for a specific buffer across the whole cache takes too long: we only
   have to search the specific bank, whose size is small.  This work is
   authored by Andrey Borodin.

2. Change the locking regime for the SLRU banks, so that each bank uses
   a separate LWLock.  This allows for increased scalability.  This work
   is authored by Dilip Kumar.  (A part of this was previously committed as
   d172b717c6f4.)

Special care is taken so that the algorithms that can potentially
traverse more than one bank release one bank's lock before acquiring the
next.  This should happen rarely, but particularly clog.c's group commit
feature needed code adjustment to cope with this.  I (Álvaro) also added
lots of comments to make sure the design is sound.

The new GUCs match the names introduced by bcdfa5f2e2f2 in the
pg_stat_slru view.

The default values for these parameters are similar to the previous
sizes of each SLRU.  commit_ts, clog and subtrans accept value 0, which
means to adjust by dividing shared_buffers by 512 (so 2MB for every 1GB
of shared_buffers), with a cap of 8MB.  (A new slru.c function
SimpleLruAutotuneBuffers() was added to support this.)  The cap was
previously 1MB for clog, so for sites with more than 512MB of shared
memory the total memory used increases, which is likely a good tradeoff.
However, other SLRUs (notably multixact ones) retain smaller sizes and
don't support a configured value of 0.  These values based on
shared_buffers may need to be revisited, but that's an easy change.

There was some resistance to adding these new GUCs: it would be better
to adjust to memory pressure automatically somehow, for example by
stealing memory from shared_buffers (where the caches can grow and
shrink naturally).  However, doing that seems to be a much larger
project and one which has made virtually no progress in several years,
and because this is such a pain point for so many users, here we take
the pragmatic approach.

Author: Andrey Borodin <x4mmm@yandex-team.ru>
Author: Dilip Kumar <dilipbalaut@gmail.com>
Reviewed-by: Amul Sul, Gilles Darold, Anastasia Lubennikova,
        Ivan Lazarev, Robert Haas, Thomas Munro, Tomas Vondra,
        Yura Sokolov, Васильев Дмитрий (Dmitry Vasiliev).
Discussion: https://postgr.es/m/2BEC2B3F-9B61-4C1D-9FB5-5FAB0F05EF86@yandex-team.ru
Discussion: https://postgr.es/m/CAFiTN-vzDvNz=ExGXz6gdyjtzGixKSqs0mKHMmaQ8sOSEFZ33A@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/53c2a97a92665be6bd7d70bd62ae6158fe4db96e

Modified Files
--------------
doc/src/sgml/config.sgml                        | 139 +++++++++
doc/src/sgml/monitoring.sgml                    |   9 +-
src/backend/access/transam/clog.c               | 243 +++++++++++-----
src/backend/access/transam/commit_ts.c          |  88 ++++--
src/backend/access/transam/multixact.c          | 190 +++++++++----
src/backend/access/transam/slru.c               | 357 +++++++++++++++++-------
src/backend/access/transam/subtrans.c           | 110 ++++++--
src/backend/commands/async.c                    |  61 ++--
src/backend/storage/lmgr/lwlock.c               |   9 +-
src/backend/storage/lmgr/lwlocknames.txt        |  14 +-
src/backend/storage/lmgr/predicate.c            |  34 ++-
src/backend/utils/activity/wait_event_names.txt |  15 +-
src/backend/utils/init/globals.c                |   9 +
src/backend/utils/misc/guc_tables.c             |  78 ++++++
src/backend/utils/misc/postgresql.conf.sample   |   9 +
src/include/access/clog.h                       |   1 -
src/include/access/commit_ts.h                  |   1 -
src/include/access/multixact.h                  |   4 -
src/include/access/slru.h                       |  86 ++++--
src/include/access/subtrans.h                   |   3 -
src/include/commands/async.h                    |   5 -
src/include/miscadmin.h                         |   8 +
src/include/storage/lwlock.h                    |   7 +
src/include/storage/predicate.h                 |   4 -
src/include/utils/guc_hooks.h                   |  11 +
src/test/modules/test_slru/test_slru.c          |  35 +--
26 files changed, 1177 insertions(+), 353 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Heikki Linnakangas
Дата:
Сообщение: pgsql: Remove configure --with-CC option
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Fix mis-rounding and overflow hazards in date_bin().