postgresql/src/include
Tom Lane 06998eab16 Improve heuristics for compressing the KnownAssignedXids array.
Previously, we'd compress only when the active range of array entries
reached Max(4 * PROCARRAY_MAXPROCS, 2 * pArray->numKnownAssignedXids).
If max_connections is large, the first term could result in not
compressing for a long time, resulting in much wastage of cycles in
hot-standby backends scanning the array to take snapshots.  Get rid
of that term, and just bound it to 2 * pArray->numKnownAssignedXids.

That however creates the opposite risk, that we might spend too much
effort compressing.  Hence, consider compressing only once every 128
commit records.  (This frequency was chosen by benchmarking.  While
we only tried one benchmark scenario, the results seem stable over
a fairly wide range of frequencies.)

Also, force compression when processing RecoveryInfo WAL records
(which should be infrequent); the old code could perform compression
then, but would do so only after the same array-range check as for
the transaction-commit path.

Also, opportunistically run compression if the startup process is about
to wait for WAL, though not oftener than once a second.  This should
prevent cases where we waste lots of time by leaving the array
not-compressed for long intervals due to low WAL traffic.

Lastly, add a simple check to keep us from uselessly compressing
when the array storage is already compact.

Back-patch, as the performance problem is worse in pre-v14 branches
than in HEAD.

Simon Riggs and Michail Nikolaev, with help from Tom Lane and
Andres Freund.

Discussion: https://postgr.es/m/CALdSSPgahNUD_=pB_j=1zSnDBaiOtqVfzo8Ejt5J_k7qZiU1Tw@mail.gmail.com
2022-11-29 15:43:17 -05:00
..
access Force immediate commit after CREATE DATABASE etc in extended protocol. 2022-07-26 13:07:03 -04:00
bootstrap Update copyright for 2021 2021-01-02 13:06:25 -05:00
catalog In extensions, don't replace objects not belonging to the extension. 2022-08-08 11:12:31 -04:00
commands Fix ENABLE/DISABLE TRIGGER to handle recursion correctly 2022-08-05 09:47:11 +02:00
common Expand palloc/pg_malloc API for more type safety 2022-09-14 06:08:34 +02:00
datatype Update copyright for 2021 2021-01-02 13:06:25 -05:00
executor Re-add SPICleanup for ABI compatibility in stable branch 2022-07-18 16:23:48 +02:00
fe_utils Allow db.schema.table patterns, but complain about random garbage. 2022-04-20 11:39:44 -04:00
foreign Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
jit jit: Do not try to shut down LLVM state in case of LLVM triggered errors. 2021-09-13 18:15:28 -07:00
lib Add casts to simplehash.h to silence C++ warnings. 2022-11-03 10:47:31 -04:00
libpq Make check_usermap() parameter names consistent. 2022-09-17 16:54:14 -07:00
mb Fix incautious handling of possibly-miscoded strings in client code. 2021-06-07 14:15:25 -04:00
nodes Fix handling of pending inserts in nodeModifyTable.c. 2022-11-25 17:45:03 +09:00
optimizer Fix incorrect tests for SRFs in relation_can_be_sorted_early(). 2022-08-03 17:33:42 -04:00
parser Rename parser token REF to REF_P to avoid a symbol conflict. 2022-10-16 15:27:04 -04:00
partitioning Fix relcache inconsistency hazard in partition detach 2021-04-22 15:13:25 -04:00
port Get rid of artificial restriction on hash table sizes on Windows. 2021-07-25 14:02:27 -04:00
portability Fix another portability bug in recent pgbench commit. 2021-03-10 23:20:41 +13:00
postmaster Remove temporary files after backend crash 2021-03-18 17:38:28 +01:00
regex Improve memory management in regex compiler. 2021-02-26 13:52:10 -05:00
replication Fix catalog lookup with the wrong snapshot during logical decoding. 2022-08-11 09:45:04 +05:30
rewrite Adjust locations which have an incorrect copyright year 2021-06-04 12:19:50 +12:00
snowball Update snowball 2021-02-19 08:10:15 +01:00
statistics Extended statistics on expressions 2021-03-27 00:01:11 +01:00
storage Improve heuristics for compressing the KnownAssignedXids array. 2022-11-29 15:43:17 -05:00
tcop Centralize the logic for protective copying of utility statements. 2021-06-18 11:22:58 -04:00
tsearch Add comments and a missing CHECK_FOR_INTERRUPTS in ts_headline. 2022-11-21 17:07:07 -05:00
utils Replace RelationOpenSmgr() with RelationGetSmgr(). 2022-11-17 16:54:30 -05:00
.gitignore Refactor dlopen() support 2018-09-06 11:33:04 +02:00
c.h Work around issues in MinGW-64's setjmp/longjmp support. 2021-03-15 12:34:17 -04:00
fmgr.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
funcapi.h Reconsider the handling of procedure OUT parameters. 2021-06-10 17:11:36 -04:00
getaddrinfo.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
getopt_long.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
Makefile Build in some knowledge about foreign-key relationships in the catalogs. 2021-02-02 17:11:55 -05:00
miscadmin.h Get rid of artificial restriction on hash table sizes on Windows. 2021-07-25 14:02:27 -04:00
pg_config_ext.h.in Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_manual.h Rename debug_invalidate_system_caches_always to debug_discard_caches. 2021-07-13 15:01:01 -04:00
pg_config.h.in Suppress warning about stack_base_ptr with late-model GCC. 2022-02-17 22:45:34 -05:00
pg_getopt.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
pg_trace.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
pgstat.h Fix performance regression from session statistics. 2021-09-16 02:10:57 -07:00
pgtar.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
pgtime.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
port.h pg_basebackup: Fix cross-platform tablespace relocation. 2022-10-21 08:39:48 -04:00
postgres_ext.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
postgres_fe.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
postgres.h Fix misleading comments about TOAST access macros. 2021-09-08 14:11:35 -04:00
rusagestub.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
windowapi.h Update copyright for 2021 2021-01-02 13:06:25 -05:00