mirror of
https://github.com/postgres/postgres.git
synced 2025-07-15 19:21:59 +03:00
Separate vacuum cost variables from GUCs
Vacuum code run both by autovacuum workers and a backend doing VACUUM/ANALYZE previously inspected VacuumCostLimit and VacuumCostDelay, which are the global variables backing the GUCs vacuum_cost_limit and vacuum_cost_delay. Autovacuum workers needed to override these variables with their own values, derived from autovacuum_vacuum_cost_limit and autovacuum_vacuum_cost_delay and worker cost limit balancing logic. This led to confusing code which, in some cases, both derived and set a new value of VacuumCostLimit from VacuumCostLimit. In preparation for refreshing these GUC values more often, introduce new, independent global variables and add a function to update them using the GUCs and existing logic. Per suggestion by Kyotaro Horiguchi Author: Melanie Plageman <melanieplageman@gmail.com> Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com> Reviewed-by: Daniel Gustafsson <daniel@yesql.se> Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com> Reviewed-by: Robert Haas <robertmhaas@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/CAAKRu_ZngzqnEODc7LmS1NH04Kt6Y9huSjz5pp7%2BDXhrjDA0gw%40mail.gmail.com
This commit is contained in:
@ -72,6 +72,15 @@ int vacuum_multixact_freeze_table_age;
|
||||
int vacuum_failsafe_age;
|
||||
int vacuum_multixact_failsafe_age;
|
||||
|
||||
/*
|
||||
* Variables for cost-based vacuum delay. The defaults differ between
|
||||
* autovacuum and vacuum. They should be set with the appropriate GUC value in
|
||||
* vacuum code. They are initialized here to the defaults for client backends
|
||||
* executing VACUUM or ANALYZE.
|
||||
*/
|
||||
double vacuum_cost_delay = 0;
|
||||
int vacuum_cost_limit = 200;
|
||||
|
||||
/*
|
||||
* VacuumFailsafeActive is a defined as a global so that we can determine
|
||||
* whether or not to re-enable cost-based vacuum delay when vacuuming a table.
|
||||
@ -514,8 +523,9 @@ vacuum(List *relations, VacuumParams *params, BufferAccessStrategy bstrategy,
|
||||
{
|
||||
ListCell *cur;
|
||||
|
||||
VacuumUpdateCosts();
|
||||
in_vacuum = true;
|
||||
VacuumCostActive = (VacuumCostDelay > 0);
|
||||
VacuumCostActive = (vacuum_cost_delay > 0);
|
||||
VacuumCostBalance = 0;
|
||||
VacuumPageHit = 0;
|
||||
VacuumPageMiss = 0;
|
||||
@ -2244,14 +2254,14 @@ vacuum_delay_point(void)
|
||||
*/
|
||||
if (VacuumSharedCostBalance != NULL)
|
||||
msec = compute_parallel_delay();
|
||||
else if (VacuumCostBalance >= VacuumCostLimit)
|
||||
msec = VacuumCostDelay * VacuumCostBalance / VacuumCostLimit;
|
||||
else if (VacuumCostBalance >= vacuum_cost_limit)
|
||||
msec = vacuum_cost_delay * VacuumCostBalance / vacuum_cost_limit;
|
||||
|
||||
/* Nap if appropriate */
|
||||
if (msec > 0)
|
||||
{
|
||||
if (msec > VacuumCostDelay * 4)
|
||||
msec = VacuumCostDelay * 4;
|
||||
if (msec > vacuum_cost_delay * 4)
|
||||
msec = vacuum_cost_delay * 4;
|
||||
|
||||
pgstat_report_wait_start(WAIT_EVENT_VACUUM_DELAY);
|
||||
pg_usleep(msec * 1000);
|
||||
@ -2268,8 +2278,7 @@ vacuum_delay_point(void)
|
||||
|
||||
VacuumCostBalance = 0;
|
||||
|
||||
/* update balance values for workers */
|
||||
AutoVacuumUpdateDelay();
|
||||
VacuumUpdateCosts();
|
||||
|
||||
/* Might have gotten an interrupt while sleeping */
|
||||
CHECK_FOR_INTERRUPTS();
|
||||
@ -2319,11 +2328,11 @@ compute_parallel_delay(void)
|
||||
/* Compute the total local balance for the current worker */
|
||||
VacuumCostBalanceLocal += VacuumCostBalance;
|
||||
|
||||
if ((shared_balance >= VacuumCostLimit) &&
|
||||
(VacuumCostBalanceLocal > 0.5 * ((double) VacuumCostLimit / nworkers)))
|
||||
if ((shared_balance >= vacuum_cost_limit) &&
|
||||
(VacuumCostBalanceLocal > 0.5 * ((double) vacuum_cost_limit / nworkers)))
|
||||
{
|
||||
/* Compute sleep time based on the local cost balance */
|
||||
msec = VacuumCostDelay * VacuumCostBalanceLocal / VacuumCostLimit;
|
||||
msec = vacuum_cost_delay * VacuumCostBalanceLocal / vacuum_cost_limit;
|
||||
pg_atomic_sub_fetch_u32(VacuumSharedCostBalance, VacuumCostBalanceLocal);
|
||||
VacuumCostBalanceLocal = 0;
|
||||
}
|
||||
|
@ -995,7 +995,8 @@ parallel_vacuum_main(dsm_segment *seg, shm_toc *toc)
|
||||
false);
|
||||
|
||||
/* Set cost-based vacuum delay */
|
||||
VacuumCostActive = (VacuumCostDelay > 0);
|
||||
VacuumCostActive = (vacuum_cost_delay > 0);
|
||||
VacuumUpdateCosts();
|
||||
VacuumCostBalance = 0;
|
||||
VacuumPageHit = 0;
|
||||
VacuumPageMiss = 0;
|
||||
|
Reference in New Issue
Block a user