Use bandwidth estimate to stop increasing bdp estimate (avoids buffer bloat spiral of death)

pull/10720/head
Craig Tiller 8 years ago
parent addd3339e2
commit 42ab2b1753
  1. 16
      src/core/lib/transport/bdp_estimator.c
  2. 3
      src/core/lib/transport/bdp_estimator.h

@ -44,6 +44,7 @@ void grpc_bdp_estimator_init(grpc_bdp_estimator *estimator, const char *name) {
estimator->estimate = 65536; estimator->estimate = 65536;
estimator->ping_state = GRPC_BDP_PING_UNSCHEDULED; estimator->ping_state = GRPC_BDP_PING_UNSCHEDULED;
estimator->name = name; estimator->name = name;
estimator->bw_est = 0;
} }
bool grpc_bdp_estimator_get_estimate(grpc_bdp_estimator *estimator, bool grpc_bdp_estimator_get_estimate(grpc_bdp_estimator *estimator,
@ -84,16 +85,25 @@ void grpc_bdp_estimator_start_ping(grpc_bdp_estimator *estimator) {
GPR_ASSERT(estimator->ping_state == GRPC_BDP_PING_SCHEDULED); GPR_ASSERT(estimator->ping_state == GRPC_BDP_PING_SCHEDULED);
estimator->ping_state = GRPC_BDP_PING_STARTED; estimator->ping_state = GRPC_BDP_PING_STARTED;
estimator->accumulator = 0; estimator->accumulator = 0;
estimator->ping_start_time = gpr_now(GPR_CLOCK_MONOTONIC);
} }
void grpc_bdp_estimator_complete_ping(grpc_bdp_estimator *estimator) { void grpc_bdp_estimator_complete_ping(grpc_bdp_estimator *estimator) {
gpr_timespec dt_ts =
gpr_time_sub(gpr_now(GPR_CLOCK_MONOTONIC), estimator->ping_start_time);
double dt = (double)dt_ts.tv_sec + 1e-9 * (double)dt_ts.tv_nsec;
double bw = dt > 0 ? ((double)estimator->accumulator / dt) : 0;
if (grpc_bdp_estimator_trace) { if (grpc_bdp_estimator_trace) {
gpr_log(GPR_DEBUG, "bdp[%s]:complete acc=%" PRId64 " est=%" PRId64, gpr_log(GPR_DEBUG, "bdp[%s]:complete acc=%" PRId64 " est=%" PRId64
estimator->name, estimator->accumulator, estimator->estimate); " dt=%lf bw=%lfMbs bw_est=%lfMbs",
estimator->name, estimator->accumulator, estimator->estimate, dt,
bw / 125000.0, estimator->bw_est / 125000.0);
} }
GPR_ASSERT(estimator->ping_state == GRPC_BDP_PING_STARTED); GPR_ASSERT(estimator->ping_state == GRPC_BDP_PING_STARTED);
if (estimator->accumulator > 2 * estimator->estimate / 3) { if (estimator->accumulator > 2 * estimator->estimate / 3 &&
bw > estimator->bw_est) {
estimator->estimate *= 2; estimator->estimate *= 2;
estimator->bw_est = bw;
if (grpc_bdp_estimator_trace) { if (grpc_bdp_estimator_trace) {
gpr_log(GPR_DEBUG, "bdp[%s]: estimate increased to %" PRId64, gpr_log(GPR_DEBUG, "bdp[%s]: estimate increased to %" PRId64,
estimator->name, estimator->estimate); estimator->name, estimator->estimate);

@ -34,6 +34,7 @@
#ifndef GRPC_CORE_LIB_TRANSPORT_BDP_ESTIMATOR_H #ifndef GRPC_CORE_LIB_TRANSPORT_BDP_ESTIMATOR_H
#define GRPC_CORE_LIB_TRANSPORT_BDP_ESTIMATOR_H #define GRPC_CORE_LIB_TRANSPORT_BDP_ESTIMATOR_H
#include <grpc/support/time.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
@ -52,6 +53,8 @@ typedef struct grpc_bdp_estimator {
grpc_bdp_estimator_ping_state ping_state; grpc_bdp_estimator_ping_state ping_state;
int64_t accumulator; int64_t accumulator;
int64_t estimate; int64_t estimate;
gpr_timespec ping_start_time;
double bw_est;
const char *name; const char *name;
} grpc_bdp_estimator; } grpc_bdp_estimator;

Loading…
Cancel
Save