Skip to content

Commit

Permalink
scheduler: make backoff base and cap configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Abilio Marques <[email protected]>
  • Loading branch information
abiliojr committed Dec 16, 2020
1 parent 4138b63 commit 66c77a4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions include/fluent-bit/flb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ struct flb_config {
int grace; /* Grace on shutdown */
flb_pipefd_t flush_fd; /* Timer FD associated to flush */

int backoff_base;
int backoff_cap;

int daemon; /* Run as a daemon ? */
flb_pipefd_t shutdown_fd; /* Shutdown FD, 5 seconds */

Expand Down Expand Up @@ -236,6 +239,8 @@ enum conf_type {

#define FLB_CONF_STR_FLUSH "Flush"
#define FLB_CONF_STR_GRACE "Grace"
#define FLB_CONF_STR_BACKOFF_BASE "Backoff_Base"
#define FLB_CONF_STR_BACKOFF_CAP "Backoff_Cap"
#define FLB_CONF_STR_DAEMON "Daemon"
#define FLB_CONF_STR_LOGFILE "Log_File"
#define FLB_CONF_STR_LOGLEVEL "Log_Level"
Expand Down
10 changes: 10 additions & 0 deletions src/flb_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ struct flb_service_config service_configs[] = {
FLB_CONF_TYPE_INT,
offsetof(struct flb_config, grace)},

{FLB_CONF_STR_BACKOFF_BASE,
FLB_CONF_TYPE_INT,
offsetof(struct flb_config, backoff_base)},

{FLB_CONF_STR_BACKOFF_CAP,
FLB_CONF_TYPE_INT,
offsetof(struct flb_config, backoff_cap)},

{FLB_CONF_STR_DAEMON,
FLB_CONF_TYPE_BOOL,
offsetof(struct flb_config, daemon)},
Expand Down Expand Up @@ -152,6 +160,8 @@ struct flb_config *flb_config_init()
config->kernel = flb_kernel_info();
config->verbose = 3;
config->grace = 5;
config->backoff_base = FLB_SCHED_BASE;
config->backoff_cap = FLB_SCHED_CAP;
config->exit_status_code = 0;

#ifdef FLB_HAVE_HTTP_SERVER
Expand Down
8 changes: 6 additions & 2 deletions src/flb_scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,12 @@ int flb_sched_request_create(struct flb_config *config, void *data, int tries)
timer->event.mask = MK_EVENT_EMPTY;

/* Get suggested wait_time for this request */
seconds = backoff_full_jitter(FLB_SCHED_BASE, FLB_SCHED_CAP, tries);
seconds += 1;
if (config->backoff_base <= 0 || config->backoff_cap <= 0 || config->backoff_base > config->backoff_cap) {
flb_error("[sched] invalid backoff limits");
return -1;
}

seconds = backoff_full_jitter(config->backoff_base, config->backoff_cap, tries);

/* Populare request */
request->fd = -1;
Expand Down
2 changes: 2 additions & 0 deletions src/flb_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ void flb_utils_print_setup(struct flb_config *config)
flb_info(" flush time | %f seconds", config->flush);
flb_info(" grace | %i seconds", config->grace);
flb_info(" daemon | %i", config->daemon);
flb_info(" backoff base | %i seconds", config->backoff_base);
flb_info(" backoff cap | %i seconds", config->backoff_cap);

/* Inputs */
flb_info("___________");
Expand Down

0 comments on commit 66c77a4

Please sign in to comment.