diff --git a/doc/environment_variables.md b/doc/environment_variables.md index c5fb2664980..0163235d63e 100644 --- a/doc/environment_variables.md +++ b/doc/environment_variables.md @@ -120,10 +120,10 @@ some configuration as environment variables that can be set. perform name resolution - ares - a DNS resolver based around the c-ares library -* GRPC_DISABLE_CHANNEL_CONNECTIVITY_WATCHER - The channel connectivity watcher uses one extra thread to check the channel - state every 500 ms on the client side. It can help reconnect disconnected - client channels (mostly due to idleness), so that the next RPC on this channel - won't fail. Set to 1 to turn off this watcher and save a thread. Please note - this is a temporary work-around, it will be removed in the future once we have - support for automatically reestablishing failed connections. +* GRPC_CLIENT_CHANNEL_BACKUP_POLL_INTERVAL_MS + Default: 500 + Declares the interval between two backup polls on client channels. These polls + are run in the timer thread so that gRPC can process connection failures while + there is no active polling thread. They help reconnect disconnected client + channels (mostly due to idleness), so that the next RPC on this channel won't + fail. Set to 0 to turn off the backup polls. diff --git a/src/core/ext/filters/client_channel/backup_poller.cc b/src/core/ext/filters/client_channel/backup_poller.cc index 36b55ebf9a6..784e75624bb 100644 --- a/src/core/ext/filters/client_channel/backup_poller.cc +++ b/src/core/ext/filters/client_channel/backup_poller.cc @@ -31,7 +31,7 @@ #include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/completion_queue.h" -#define DEFAULT_POLLING_INTERVAL_MS 500 +#define DEFAULT_POLL_INTERVAL_MS 500 typedef struct backup_poller { grpc_timer polling_timer; @@ -46,14 +46,18 @@ typedef struct backup_poller { static gpr_once g_once = GPR_ONCE_INIT; static gpr_mu g_poller_mu; static backup_poller* g_poller = NULL; +static int g_poll_interval_ms = DEFAULT_POLL_INTERVAL_MS; -static void init_g_poller_mu() { gpr_mu_init(&g_poller_mu); } - -static bool is_disabled() { - char* env = gpr_getenv("GRPC_DISABLE_CHANNEL_backup_poller"); - bool disabled = gpr_is_true(env); +static void init_g_poller_mu() { + gpr_mu_init(&g_poller_mu); + char* env = gpr_getenv("GRPC_CLIENT_CHANNEL_BACKUP_POLL_INTERVAL_MS"); + if (env != NULL) { + int poll_interval_ms = gpr_parse_nonnegative_int(env); + if (poll_interval_ms != -1) { + g_poll_interval_ms = poll_interval_ms; + } + } gpr_free(env); - return disabled; } static bool backup_poller_shutdown_unref(grpc_exec_ctx* exec_ctx, @@ -103,14 +107,15 @@ static void run_poller(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { GRPC_LOG_IF_ERROR("Run client channel backup poller", err); grpc_timer_init( exec_ctx, &p->polling_timer, - gpr_time_add( - now, gpr_time_from_millis(DEFAULT_POLLING_INTERVAL_MS, GPR_TIMESPAN)), + gpr_time_add(now, gpr_time_from_millis(g_poll_interval_ms, GPR_TIMESPAN)), &p->run_poller_closure, now); } void grpc_client_channel_start_backup_polling( grpc_exec_ctx* exec_ctx, grpc_pollset_set* interested_parties) { - if (is_disabled()) return; + if (g_poll_interval_ms == 0) { + return; + } gpr_once_init(&g_once, init_g_poller_mu); gpr_mu_lock(&g_poller_mu); if (g_poller == NULL) { @@ -123,11 +128,10 @@ void grpc_client_channel_start_backup_polling( GRPC_CLOSURE_INIT(&g_poller->run_poller_closure, run_poller, g_poller, grpc_schedule_on_exec_ctx); gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); - grpc_timer_init( - exec_ctx, &g_poller->polling_timer, - gpr_time_add(now, gpr_time_from_millis(DEFAULT_POLLING_INTERVAL_MS, - GPR_TIMESPAN)), - &g_poller->run_poller_closure, now); + grpc_timer_init(exec_ctx, &g_poller->polling_timer, + gpr_time_add(now, gpr_time_from_millis(g_poll_interval_ms, + GPR_TIMESPAN)), + &g_poller->run_poller_closure, now); } gpr_ref(&g_poller->refs); gpr_mu_unlock(&g_poller_mu); @@ -137,7 +141,9 @@ void grpc_client_channel_start_backup_polling( void grpc_client_channel_stop_backup_polling( grpc_exec_ctx* exec_ctx, grpc_pollset_set* interested_parties) { - if (is_disabled()) return; + if (g_poll_interval_ms == 0) { + return; + } grpc_pollset_set_del_pollset(exec_ctx, interested_parties, g_poller->pollset); g_poller_unref(exec_ctx); }