aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib
diff options
context:
space:
mode:
authorGravatar jiangtaoli2016 <jiangtao@google.com>2017-05-09 11:14:02 -0700
committerGravatar jiangtaoli2016 <jiangtao@google.com>2017-05-09 11:14:02 -0700
commit876f2905452466f54242c0f584ce216b34dcd9f7 (patch)
treee959790d81306abf22b094efa4b53e663bfcd33c /src/core/lib
parent2d56f27349aa3263a7ddb86897bf6cbc77becf39 (diff)
parent786c76e1b3759a8e4a7f9d6a30e664e519b60439 (diff)
Merge branch 'master' into handshaker
Diffstat (limited to 'src/core/lib')
-rw-r--r--src/core/lib/transport/bdp_estimator.c19
-rw-r--r--src/core/lib/transport/bdp_estimator.h3
2 files changed, 18 insertions, 4 deletions
diff --git a/src/core/lib/transport/bdp_estimator.c b/src/core/lib/transport/bdp_estimator.c
index e1483677fd..536694214e 100644
--- a/src/core/lib/transport/bdp_estimator.c
+++ b/src/core/lib/transport/bdp_estimator.c
@@ -44,6 +44,7 @@ void grpc_bdp_estimator_init(grpc_bdp_estimator *estimator, const char *name) {
estimator->estimate = 65536;
estimator->ping_state = GRPC_BDP_PING_UNSCHEDULED;
estimator->name = name;
+ estimator->bw_est = 0;
}
bool grpc_bdp_estimator_get_estimate(grpc_bdp_estimator *estimator,
@@ -84,16 +85,26 @@ void grpc_bdp_estimator_start_ping(grpc_bdp_estimator *estimator) {
GPR_ASSERT(estimator->ping_state == GRPC_BDP_PING_SCHEDULED);
estimator->ping_state = GRPC_BDP_PING_STARTED;
estimator->accumulator = 0;
+ estimator->ping_start_time = gpr_now(GPR_CLOCK_MONOTONIC);
}
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) {
- gpr_log(GPR_DEBUG, "bdp[%s]:complete acc=%" PRId64 " est=%" PRId64,
- estimator->name, estimator->accumulator, estimator->estimate);
+ gpr_log(GPR_DEBUG, "bdp[%s]:complete acc=%" PRId64 " est=%" PRId64
+ " 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);
- if (estimator->accumulator > 2 * estimator->estimate / 3) {
- estimator->estimate *= 2;
+ if (estimator->accumulator > 2 * estimator->estimate / 3 &&
+ bw > estimator->bw_est) {
+ estimator->estimate =
+ GPR_MAX(estimator->accumulator, estimator->estimate * 2);
+ estimator->bw_est = bw;
if (grpc_bdp_estimator_trace) {
gpr_log(GPR_DEBUG, "bdp[%s]: estimate increased to %" PRId64,
estimator->name, estimator->estimate);
diff --git a/src/core/lib/transport/bdp_estimator.h b/src/core/lib/transport/bdp_estimator.h
index df8d1f6fc0..752bee1abd 100644
--- a/src/core/lib/transport/bdp_estimator.h
+++ b/src/core/lib/transport/bdp_estimator.h
@@ -34,6 +34,7 @@
#ifndef GRPC_CORE_LIB_TRANSPORT_BDP_ESTIMATOR_H
#define GRPC_CORE_LIB_TRANSPORT_BDP_ESTIMATOR_H
+#include <grpc/support/time.h>
#include <stdbool.h>
#include <stdint.h>
@@ -52,6 +53,8 @@ typedef struct grpc_bdp_estimator {
grpc_bdp_estimator_ping_state ping_state;
int64_t accumulator;
int64_t estimate;
+ gpr_timespec ping_start_time;
+ double bw_est;
const char *name;
} grpc_bdp_estimator;