From e98d3858197c774db532dcac5fe9d7a1b24fb761 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 15 Nov 2022 09:34:07 +0100 Subject: [PATCH] MINOR: deinit: add a "quick-exit" option to bypass the deinit step Once in a while we spot a bug in the deinit code that is complex, especially when it has to deal with incomplete initializations, and the ability to bypass this step has regularly been raised. In addition for fast-reloading setups it could theoretically save some time. Tests have shown that very large configs can barely save ~100-150ms by skipping the deinit step. However the ability not to crash if a bug is encountered can occasionally help. This patch adds an option to do exactly this. It's obviously not enabled by default and the documentation discourages from using it, but this might be useful in the future. --- doc/configuration.txt | 9 +++++++++ include/haproxy/global-t.h | 1 + src/cfgparse-global.c | 5 +++++ src/haproxy.c | 4 ++++ 4 files changed, 19 insertions(+) diff --git a/doc/configuration.txt b/doc/configuration.txt index cef8e7a8f..7ce7ae5e0 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -3238,6 +3238,15 @@ anonkey from the CLI command "set global-key". See also command line argument "-dC" in the management manual. +quick-exit + This speeds up the old process exit upon reload by skipping the releasing of + memory objects and listeners, since all of these are reclaimed by the + operating system at the process' death. The gains are only marginal (in the + order of a few hundred milliseconds for huge configurations at most). The + main target usage in fact is when a bug is spotted in the deinit() code, as + this allows to bypass it. It is better not to use this unless instructed to + do so by developers. + quiet Do not display any message during startup. It is equivalent to the command- line argument "-q". diff --git a/include/haproxy/global-t.h b/include/haproxy/global-t.h index 1c7f45b3a..0cdb361ae 100644 --- a/include/haproxy/global-t.h +++ b/include/haproxy/global-t.h @@ -77,6 +77,7 @@ #define GTUNE_IDLE_POOL_SHARED (1<<20) #define GTUNE_DISABLE_H2_WEBSOCKET (1<<21) #define GTUNE_DISABLE_ACTIVE_CLOSE (1<<22) +#define GTUNE_QUICK_EXIT (1<<23) /* SSL server verify mode */ enum { diff --git a/src/cfgparse-global.c b/src/cfgparse-global.c index 62de1013a..6cc4afe13 100644 --- a/src/cfgparse-global.c +++ b/src/cfgparse-global.c @@ -1221,6 +1221,11 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm) env++; } } + else if (strcmp(args[0], "quick-exit") == 0) { + if (alertif_too_many_args(0, file, linenum, args, &err_code)) + goto out; + global.tune.options |= GTUNE_QUICK_EXIT; + } else if (strcmp(args[0], "strict-limits") == 0) { /* "no strict-limits" or "strict-limits" */ if (alertif_too_many_args(0, file, linenum, args, &err_code)) goto out; diff --git a/src/haproxy.c b/src/haproxy.c index 806497062..9f5e75f53 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -2637,6 +2637,10 @@ void deinit(void) struct cfg_postparser *pprs, *pprsb; int cur_fd; + /* the user may want to skip this phase */ + if (global.tune.options & GTUNE_QUICK_EXIT) + return; + /* At this point the listeners state is weird: * - most listeners are still bound and referenced in their protocol * - some might be zombies that are not in their proto anymore, but