[master] 94bd48863 cli: New debug.shutdown.delay command

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Nov 15 14:57:07 UTC 2021


commit 94bd48863b035ce300187ed7739ded53bd891388
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Fri Oct 22 16:00:25 2021 +0200

    cli: New debug.shutdown.delay command
    
    For the purpose of simulating a workload where the cache process takes
    significant time to shut down.

diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c
index 39b2dace5..095279dc3 100644
--- a/bin/varnishd/cache/cache_main.c
+++ b/bin/varnishd/cache/cache_main.c
@@ -48,6 +48,8 @@
 #include "common/heritage.h"
 
 #include "vcli_serve.h"
+#include "vnum.h"
+#include "vtim.h"
 #include "vrnd.h"
 
 #include "hash/hash_slinger.h"
@@ -56,6 +58,7 @@ int cache_shutdown = 0;
 
 volatile struct params		*cache_param;
 static pthread_mutex_t		cache_vrnd_mtx;
+static vtim_dur			shutdown_delay = 0;
 
 pthread_mutexattr_t mtxattr_errorcheck;
 
@@ -224,6 +227,18 @@ cli_debug_xid(struct cli *cli, const char * const *av, void *priv)
 	VCLI_Out(cli, "XID is %u", vxid_base);
 }
 
+/*
+ * Artificially slow down the process shutdown.
+ */
+static void v_matchproto_(cli_func_t)
+cli_debug_shutdown_delay(struct cli *cli, const char * const *av, void *priv)
+{
+
+	(void)cli;
+	(void)priv;
+	shutdown_delay = VNUM_duration(av[2]);
+}
+
 /*
  * Default to seed=1, this is the only seed value POSIXl guarantees will
  * result in a reproducible random number sequence.
@@ -241,8 +256,9 @@ cli_debug_srandom(struct cli *cli, const char * const *av, void *priv)
 }
 
 static struct cli_proto debug_cmds[] = {
-	{ CLICMD_DEBUG_XID,			"d", cli_debug_xid },
-	{ CLICMD_DEBUG_SRANDOM,			"d", cli_debug_srandom },
+	{ CLICMD_DEBUG_XID,		"d", cli_debug_xid },
+	{ CLICMD_DEBUG_SHUTDOWN_DELAY,	"d", cli_debug_shutdown_delay },
+	{ CLICMD_DEBUG_SRANDOM,		"d", cli_debug_srandom },
 	{ NULL }
 };
 
@@ -434,6 +450,10 @@ child_main(int sigmagic, size_t altstksz)
 	CLI_Run();
 
 	cache_shutdown = 1;
+
+	if (shutdown_delay > 0)
+		VTIM_sleep(shutdown_delay);
+
 	VCA_Shutdown();
 	BAN_Shutdown();
 	EXP_Shutdown();
diff --git a/include/tbl/cli_cmds.h b/include/tbl/cli_cmds.h
index 9537833f6..7134c0c20 100644
--- a/include/tbl/cli_cmds.h
+++ b/include/tbl/cli_cmds.h
@@ -359,6 +359,15 @@ CLI_CMD(DEBUG_REQPOOLFAIL,
 	"allocations will fail.",
 	1, 1
 )
+
+CLI_CMD(DEBUG_SHUTDOWN_DELAY,
+	"debug.shutdown.delay",
+	"debug.shutdown.delay",
+	"Add a delay to the child process shutdown.",
+	"",
+	1, 1
+)
+
 CLI_CMD(DEBUG_XID,
 	"debug.xid",
 	"debug.xid",


More information about the varnish-commit mailing list