From a16877bf24fd80a421cf96d8807dea6953accb94 Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Mon, 17 Apr 2017 10:57:09 +0900 Subject: [PATCH 2/2] Add a new GUC parameter apply_worker_launch_interval. Specify the inteval of launching logical replication apply worker. --- doc/src/sgml/config.sgml | 22 +++++++++++++++++----- src/backend/replication/logical/launcher.c | 16 +++++++++------- src/backend/utils/misc/guc.c | 13 +++++++++++++ src/backend/utils/misc/postgresql.conf.sample | 1 + src/include/replication/logicallauncher.h | 1 + 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index f584431..92e8b0f 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -3420,11 +3420,6 @@ ANY num_sync ( @@ -3497,6 +3492,23 @@ ANY num_sync ( + apply_worker_launch_interval (integer) + + apply_worker_launch_interval configuration parameter + + + + + Specify the number of milliseconds after which a logical replication apply + worker launched. + + + The default value is 5 seconds. Units are milliseconds if not specified. + + + + diff --git a/src/backend/replication/logical/launcher.c b/src/backend/replication/logical/launcher.c index 2d663f6..6db8793 100644 --- a/src/backend/replication/logical/launcher.c +++ b/src/backend/replication/logical/launcher.c @@ -58,6 +58,7 @@ int max_logical_replication_workers = 4; int max_sync_workers_per_subscription = 2; +int apply_worker_launch_interval = 5000; LogicalRepWorker *MyLogicalRepWorker = NULL; @@ -684,9 +685,9 @@ ApplyLauncherMain(Datum main_arg) now = GetCurrentTimestamp(); - /* Limit the start retry to once a wal_retrieve_retry_interval */ + /* Limit the start retry to once a apply_worker_launch_interval */ if (TimestampDifferenceExceeds(last_start_time, now, - wal_retrieve_retry_interval)) + apply_worker_launch_interval)) { /* Use temporary context for the database list and worker info. */ subctx = AllocSetContextCreate(TopMemoryContext, @@ -714,7 +715,7 @@ ApplyLauncherMain(Datum main_arg) logicalrep_worker_launch(sub->dbid, sub->oid, sub->name, sub->owner, InvalidOid); last_start_time = now; - wait_time = wal_retrieve_retry_interval; + wait_time = apply_worker_launch_interval; /* Limit to one worker per mainloop cycle. */ break; } @@ -729,11 +730,12 @@ ApplyLauncherMain(Datum main_arg) { /* * The wait in previous cycle was interrupted in less than - * wal_retrieve_retry_interval since last worker was started, - * this usually means crash of the worker, so we should retry - * in wal_retrieve_retry_interval again. + * apply_worker_launch_interval since last + * worker was started, this usually means crash of the worker, + * so we should retry in apply_worker_launch_interval + * again. */ - wait_time = wal_retrieve_retry_interval; + wait_time = apply_worker_launch_interval; } /* Wait for more work. */ diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 378bad2..31e76e9 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -2547,6 +2547,19 @@ static struct config_int ConfigureNamesInt[] = }, { + {"apply_worker_launch_interval", + PGC_SIGHUP, + REPLICATION_SUBSCRIBERS, + gettext_noop("Sets the time to wait before launching aply woker."), + NULL, + GUC_UNIT_MS, + }, + &apply_worker_launch_interval, + 5000, 1, INT_MAX, + NULL, NULL, NULL + }, + + { {"log_rotation_age", PGC_SIGHUP, LOGGING_WHERE, gettext_noop("Automatic log file rotation will occur after N minutes."), NULL, diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample index 20b5bb7..7bebd63 100644 --- a/src/backend/utils/misc/postgresql.conf.sample +++ b/src/backend/utils/misc/postgresql.conf.sample @@ -280,6 +280,7 @@ #max_sync_workers_per_subscription = 2 # taken from max_logical_replication_workers #apply_worker_timeout = 60s # time that apply worker waits for # communication from publisher# +#apply_worker_launch_interval = 5s # time to wait before start apply worker #------------------------------------------------------------------------------ diff --git a/src/include/replication/logicallauncher.h b/src/include/replication/logicallauncher.h index 060946a..696a9e5 100644 --- a/src/include/replication/logicallauncher.h +++ b/src/include/replication/logicallauncher.h @@ -14,6 +14,7 @@ extern int max_logical_replication_workers; extern int max_sync_workers_per_subscription; +extern int apply_worker_launch_interval; extern void ApplyLauncherRegister(void); extern void ApplyLauncherMain(Datum main_arg); -- 2.8.1