aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/transport
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2017-10-16 15:33:55 -0700
committerGravatar GitHub <noreply@github.com>2017-10-16 15:33:55 -0700
commitf00d8fb11246c15115679faab238f9c32787c353 (patch)
tree7c33736dead16f19c8f55a8219d3c5db92ec5b35 /src/core/lib/transport
parent46fde66eee94a11cf3a5ae7210d08041edceb8e7 (diff)
parent7c4412def68c3b4be18bdb1ff4c95a32f2866d32 (diff)
Merge pull request #12895 from ctiller/timer
Have BDP estimator use timers
Diffstat (limited to 'src/core/lib/transport')
-rw-r--r--src/core/lib/transport/bdp_estimator.cc5
-rw-r--r--src/core/lib/transport/bdp_estimator.h18
2 files changed, 4 insertions, 19 deletions
diff --git a/src/core/lib/transport/bdp_estimator.cc b/src/core/lib/transport/bdp_estimator.cc
index 2a1c97c84e..f1597014b1 100644
--- a/src/core/lib/transport/bdp_estimator.cc
+++ b/src/core/lib/transport/bdp_estimator.cc
@@ -33,13 +33,12 @@ BdpEstimator::BdpEstimator(const char *name)
accumulator_(0),
estimate_(65536),
ping_start_time_(gpr_time_0(GPR_CLOCK_MONOTONIC)),
- next_ping_scheduled_(0),
inter_ping_delay_(100.0), // start at 100ms
stable_estimate_count_(0),
bw_est_(0),
name_(name) {}
-void BdpEstimator::CompletePing(grpc_exec_ctx *exec_ctx) {
+grpc_millis BdpEstimator::CompletePing(grpc_exec_ctx *exec_ctx) {
gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
gpr_timespec dt_ts = gpr_time_sub(now, ping_start_time_);
double dt = (double)dt_ts.tv_sec + 1e-9 * (double)dt_ts.tv_nsec;
@@ -79,7 +78,7 @@ void BdpEstimator::CompletePing(grpc_exec_ctx *exec_ctx) {
}
ping_state_ = PingState::UNSCHEDULED;
accumulator_ = 0;
- next_ping_scheduled_ = grpc_exec_ctx_now(exec_ctx) + inter_ping_delay_;
+ return grpc_exec_ctx_now(exec_ctx) + inter_ping_delay_;
}
} // namespace grpc_core
diff --git a/src/core/lib/transport/bdp_estimator.h b/src/core/lib/transport/bdp_estimator.h
index 6447f2d62c..470c127f7f 100644
--- a/src/core/lib/transport/bdp_estimator.h
+++ b/src/core/lib/transport/bdp_estimator.h
@@ -52,18 +52,6 @@ class BdpEstimator {
void AddIncomingBytes(int64_t num_bytes) { accumulator_ += num_bytes; }
- // Returns true if the user should schedule a ping
- bool NeedPing(grpc_exec_ctx *exec_ctx) const {
- switch (ping_state_) {
- case PingState::UNSCHEDULED:
- return grpc_exec_ctx_now(exec_ctx) >= next_ping_scheduled_;
- case PingState::SCHEDULED:
- case PingState::STARTED:
- return false;
- }
- GPR_UNREACHABLE_CODE(return false);
- }
-
// Schedule a ping: call in response to receiving a true from
// grpc_bdp_estimator_add_incoming_bytes once a ping has been scheduled by a
// transport (but not necessarily started)
@@ -91,8 +79,8 @@ class BdpEstimator {
ping_start_time_ = gpr_now(GPR_CLOCK_MONOTONIC);
}
- // Completes a previously started ping
- void CompletePing(grpc_exec_ctx *exec_ctx);
+ // Completes a previously started ping, returns when to schedule the next one
+ grpc_millis CompletePing(grpc_exec_ctx *exec_ctx);
private:
enum class PingState { UNSCHEDULED, SCHEDULED, STARTED };
@@ -102,8 +90,6 @@ class BdpEstimator {
int64_t estimate_;
// when was the current ping started?
gpr_timespec ping_start_time_;
- // when should the next ping start?
- grpc_millis next_ping_scheduled_;
int inter_ping_delay_;
int stable_estimate_count_;
double bw_est_;