mirror of
https://github.com/postgres/postgres.git
synced 2025-11-22 12:22:45 +03:00
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 bcdfa5f2e2 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
This commit is contained in:
@@ -295,11 +295,7 @@ SInvalWrite "Waiting to add a message to the shared catalog invalidation queue."
|
||||
WALBufMapping "Waiting to replace a page in WAL buffers."
|
||||
WALWrite "Waiting for WAL buffers to be written to disk."
|
||||
ControlFile "Waiting to read or update the <filename>pg_control</filename> file or create a new WAL file."
|
||||
XactSLRU "Waiting to access the transaction status SLRU cache."
|
||||
SubtransSLRU "Waiting to access the sub-transaction SLRU cache."
|
||||
MultiXactGen "Waiting to read or update shared multixact state."
|
||||
MultiXactOffsetSLRU "Waiting to access the multixact offset SLRU cache."
|
||||
MultiXactMemberSLRU "Waiting to access the multixact member SLRU cache."
|
||||
RelCacheInit "Waiting to read or update a <filename>pg_internal.init</filename> relation cache initialization file."
|
||||
CheckpointerComm "Waiting to manage fsync requests."
|
||||
TwoPhaseState "Waiting to read or update the state of prepared transactions."
|
||||
@@ -310,19 +306,16 @@ Autovacuum "Waiting to read or update the current state of autovacuum workers."
|
||||
AutovacuumSchedule "Waiting to ensure that a table selected for autovacuum still needs vacuuming."
|
||||
SyncScan "Waiting to select the starting location of a synchronized table scan."
|
||||
RelationMapping "Waiting to read or update a <filename>pg_filenode.map</filename> file (used to track the filenode assignments of certain system catalogs)."
|
||||
NotifySLRU "Waiting to access the <command>NOTIFY</command> message SLRU cache."
|
||||
NotifyQueue "Waiting to read or update <command>NOTIFY</command> messages."
|
||||
SerializableXactHash "Waiting to read or update information about serializable transactions."
|
||||
SerializableFinishedList "Waiting to access the list of finished serializable transactions."
|
||||
SerializablePredicateList "Waiting to access the list of predicate locks held by serializable transactions."
|
||||
SerialSLRU "Waiting to access the serializable transaction conflict SLRU cache."
|
||||
SyncRep "Waiting to read or update information about the state of synchronous replication."
|
||||
BackgroundWorker "Waiting to read or update background worker state."
|
||||
DynamicSharedMemoryControl "Waiting to read or update dynamic shared memory allocation information."
|
||||
AutoFile "Waiting to update the <filename>postgresql.auto.conf</filename> file."
|
||||
ReplicationSlotAllocation "Waiting to allocate or free a replication slot."
|
||||
ReplicationSlotControl "Waiting to read or update replication slot state."
|
||||
CommitTsSLRU "Waiting to access the commit timestamp SLRU cache."
|
||||
CommitTs "Waiting to read or update the last value set for a transaction commit timestamp."
|
||||
ReplicationOrigin "Waiting to create, drop or use a replication origin."
|
||||
MultiXactTruncation "Waiting to read or truncate multixact information."
|
||||
@@ -375,6 +368,14 @@ LogicalRepLauncherDSA "Waiting to access logical replication launcher's dynamic
|
||||
LogicalRepLauncherHash "Waiting to access logical replication launcher's shared hash table."
|
||||
DSMRegistryDSA "Waiting to access dynamic shared memory registry's dynamic shared memory allocator."
|
||||
DSMRegistryHash "Waiting to access dynamic shared memory registry's shared hash table."
|
||||
CommitTsSLRU "Waiting to access the commit timestamp SLRU cache."
|
||||
MultiXactOffsetSLRU "Waiting to access the multixact offset SLRU cache."
|
||||
MultiXactMemberSLRU "Waiting to access the multixact member SLRU cache."
|
||||
NotifySLRU "Waiting to access the <command>NOTIFY</command> message SLRU cache."
|
||||
SerialSLRU "Waiting to access the serializable transaction conflict SLRU cache."
|
||||
SubtransSLRU "Waiting to access the sub-transaction SLRU cache."
|
||||
XactSLRU "Waiting to access the transaction status SLRU cache."
|
||||
|
||||
|
||||
#
|
||||
# Wait Events - Lock
|
||||
|
||||
@@ -157,3 +157,12 @@ int64 VacuumPageDirty = 0;
|
||||
|
||||
int VacuumCostBalance = 0; /* working state for vacuum */
|
||||
bool VacuumCostActive = false;
|
||||
|
||||
/* configurable SLRU buffer sizes */
|
||||
int commit_timestamp_buffers = 0;
|
||||
int multixact_member_buffers = 32;
|
||||
int multixact_offset_buffers = 16;
|
||||
int notify_buffers = 16;
|
||||
int serializable_buffers = 32;
|
||||
int subtransaction_buffers = 0;
|
||||
int transaction_buffers = 0;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "access/commit_ts.h"
|
||||
#include "access/gin.h"
|
||||
#include "access/slru.h"
|
||||
#include "access/toast_compression.h"
|
||||
#include "access/twophase.h"
|
||||
#include "access/xlog_internal.h"
|
||||
@@ -2283,6 +2284,83 @@ struct config_int ConfigureNamesInt[] =
|
||||
NULL, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"commit_timestamp_buffers", PGC_POSTMASTER, RESOURCES_MEM,
|
||||
gettext_noop("Sets the size of the dedicated buffer pool used for the commit timestamp cache."),
|
||||
NULL,
|
||||
GUC_UNIT_BLOCKS
|
||||
},
|
||||
&commit_timestamp_buffers,
|
||||
0, 0, SLRU_MAX_ALLOWED_BUFFERS,
|
||||
check_commit_ts_buffers, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"multixact_member_buffers", PGC_POSTMASTER, RESOURCES_MEM,
|
||||
gettext_noop("Sets the size of the dedicated buffer pool used for the MultiXact member cache."),
|
||||
NULL,
|
||||
GUC_UNIT_BLOCKS
|
||||
},
|
||||
&multixact_member_buffers,
|
||||
32, 16, SLRU_MAX_ALLOWED_BUFFERS,
|
||||
check_multixact_member_buffers, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"multixact_offset_buffers", PGC_POSTMASTER, RESOURCES_MEM,
|
||||
gettext_noop("Sets the size of the dedicated buffer pool used for the MultiXact offset cache."),
|
||||
NULL,
|
||||
GUC_UNIT_BLOCKS
|
||||
},
|
||||
&multixact_offset_buffers,
|
||||
16, 16, SLRU_MAX_ALLOWED_BUFFERS,
|
||||
check_multixact_offset_buffers, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"notify_buffers", PGC_POSTMASTER, RESOURCES_MEM,
|
||||
gettext_noop("Sets the size of the dedicated buffer pool used for the LISTEN/NOTIFY message cache."),
|
||||
NULL,
|
||||
GUC_UNIT_BLOCKS
|
||||
},
|
||||
¬ify_buffers,
|
||||
16, 16, SLRU_MAX_ALLOWED_BUFFERS,
|
||||
check_notify_buffers, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"serializable_buffers", PGC_POSTMASTER, RESOURCES_MEM,
|
||||
gettext_noop("Sets the size of the dedicated buffer pool used for the serializable transaction cache."),
|
||||
NULL,
|
||||
GUC_UNIT_BLOCKS
|
||||
},
|
||||
&serializable_buffers,
|
||||
32, 16, SLRU_MAX_ALLOWED_BUFFERS,
|
||||
check_serial_buffers, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"subtransaction_buffers", PGC_POSTMASTER, RESOURCES_MEM,
|
||||
gettext_noop("Sets the size of the dedicated buffer pool used for the sub-transaction cache."),
|
||||
NULL,
|
||||
GUC_UNIT_BLOCKS
|
||||
},
|
||||
&subtransaction_buffers,
|
||||
0, 0, SLRU_MAX_ALLOWED_BUFFERS,
|
||||
check_subtrans_buffers, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"transaction_buffers", PGC_POSTMASTER, RESOURCES_MEM,
|
||||
gettext_noop("Sets the size of the dedicated buffer pool used for the transaction status cache."),
|
||||
NULL,
|
||||
GUC_UNIT_BLOCKS
|
||||
},
|
||||
&transaction_buffers,
|
||||
0, 0, SLRU_MAX_ALLOWED_BUFFERS,
|
||||
check_transaction_buffers, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"temp_buffers", PGC_USERSET, RESOURCES_MEM,
|
||||
gettext_noop("Sets the maximum number of temporary buffers used by each session."),
|
||||
|
||||
@@ -50,6 +50,15 @@
|
||||
#external_pid_file = '' # write an extra PID file
|
||||
# (change requires restart)
|
||||
|
||||
# - SLRU Buffers (change requires restart) -
|
||||
|
||||
#commit_timestamp_buffers = 0 # memory for pg_commit_ts (0 = auto)
|
||||
#multixact_offset_buffers = 16 # memory for pg_multixact/offsets
|
||||
#multixact_member_buffers = 32 # memory for pg_multixact/members
|
||||
#notify_buffers = 16 # memory for pg_notify
|
||||
#serializable_buffers = 32 # memory for pg_serial
|
||||
#subtransaction_buffers = 0 # memory for pg_subtrans (0 = auto)
|
||||
#transaction_buffers = 0 # memory for pg_xact (0 = auto)
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# CONNECTIONS AND AUTHENTICATION
|
||||
|
||||
Reference in New Issue
Block a user