diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 3a5bf1bf797..b8aa324e518 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -239,6 +239,8 @@ int ReservedBackends; #define MAXLISTEN 64 static pgsocket ListenSocket[MAXLISTEN]; +unsigned char *ForkLock = NULL; + /* * Set by the -o option */ @@ -4498,6 +4500,10 @@ BackendStartup(Port *port) #ifdef EXEC_BACKEND pid = backend_forkexec(port); #else /* !EXEC_BACKEND */ + + if (gp_enable_fork_sleep) + pg_usleep(gp_enable_fork_sleep * 1000 /*ms*/); + pid = fork_process(); if (pid == 0) /* child */ { diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c index 158aca09ce0..e303e8d77af 100644 --- a/src/backend/storage/ipc/ipci.c +++ b/src/backend/storage/ipc/ipci.c @@ -372,6 +372,11 @@ CreateSharedMemoryAndSemaphores(int port) if (gp_enable_resqueue_priority) BackoffStateInit(); + if (gp_enable_fork_sleep) { + /* Create ProcStructLock spinlock, too */ + ForkLock = (slock_t *) ShmemAlloc(sizeof(slock_t)); + SpinLockInit(ForkLock); + } /* Initialize dynamic shared memory facilities. */ if (!IsUnderPostmaster) diff --git a/src/backend/utils/misc/guc_gp.c b/src/backend/utils/misc/guc_gp.c index 5203116d76e..99a0d578a87 100644 --- a/src/backend/utils/misc/guc_gp.c +++ b/src/backend/utils/misc/guc_gp.c @@ -215,6 +215,7 @@ static char *gp_resource_manager_str; /* Backoff-related GUCs */ bool gp_enable_resqueue_priority; +int gp_enable_fork_sleep; int gp_resqueue_priority_local_interval; int gp_resqueue_priority_sweeper_interval; int gp_resqueue_priority_inactivity_timeout; @@ -1743,7 +1744,6 @@ struct config_bool ConfigureNamesBool_gp[] = true, NULL, NULL, NULL }, - { {"debug_resource_group", PGC_USERSET, DEVELOPER_OPTIONS, gettext_noop("Prints resource groups debug logs."), @@ -3339,6 +3339,19 @@ struct config_bool ConfigureNamesBool_gp[] = struct config_int ConfigureNamesInt_gp[] = { + + { + {"gp_enable_fork_sleep", PGC_USERSET, RESOURCES_MGM, + gettext_noop("Enables priority scheduling."), + gettext_noop("Enables priority scheduling."), + GUC_UNIT_S | GUC_NOT_IN_SAMPLE + }, + &gp_enable_fork_sleep, + 1000, 0, 72000, + NULL, NULL, NULL + }, + + { {"readable_external_table_timeout", PGC_USERSET, EXTERNAL_TABLES, gettext_noop("Cancel the query if no data read within N seconds."), diff --git a/src/include/postmaster/backoff.h b/src/include/postmaster/backoff.h index 2f23c9825fd..2a13c52a80f 100644 --- a/src/include/postmaster/backoff.h +++ b/src/include/postmaster/backoff.h @@ -12,6 +12,7 @@ /* GUCs */ extern bool gp_enable_resqueue_priority; +extern int gp_enable_fork_sleep; extern int gp_resqueue_priority_local_interval; extern int gp_resqueue_priority_sweeper_interval; extern int gp_resqueue_priority_inactivity_timeout; diff --git a/src/include/postmaster/postmaster.h b/src/include/postmaster/postmaster.h index 54a2f1d6919..44a3bde6cf0 100644 --- a/src/include/postmaster/postmaster.h +++ b/src/include/postmaster/postmaster.h @@ -55,6 +55,8 @@ extern int postmaster_alive_fds[2]; extern const char *progname; extern PGDLLIMPORT const char *progname; +extern unsigned char *ForkLock; + extern void PostmasterMain(int argc, char *argv[]) __attribute__((noreturn)); extern void ClosePostmasterPorts(bool am_syslogger); diff --git a/src/include/utils/sync_guc_name.h b/src/include/utils/sync_guc_name.h index 82a9b3733d2..984275be057 100644 --- a/src/include/utils/sync_guc_name.h +++ b/src/include/utils/sync_guc_name.h @@ -23,6 +23,7 @@ "gp_enable_mk_sort", "gp_enable_motion_mk_sort", "gp_enable_segment_copy_checking", + "gp_enable_fork_sleep", "gp_external_enable_filter_pushdown", "gp_gpperfmon_send_interval", "gp_hashagg_default_nbatches",