Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(889)

Unified Diff: net/quic/congestion_control/rtt_stats.cc

Issue 188333003: Land Recent QUIC Changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compilation error - added NET_EXPORT_PRIVATE to QuicFixedUint32 Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/quic/congestion_control/rtt_stats.h ('k') | net/quic/congestion_control/send_algorithm_interface.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/congestion_control/rtt_stats.cc
diff --git a/net/quic/congestion_control/rtt_stats.cc b/net/quic/congestion_control/rtt_stats.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8f9e1d1910ac9dd77ee319dbe47db6ab6ff692d2
--- /dev/null
+++ b/net/quic/congestion_control/rtt_stats.cc
@@ -0,0 +1,81 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/quic/congestion_control/rtt_stats.h"
+
+namespace net {
+
+namespace {
+
+// Default initial rtt used before any samples are received.
+const int kInitialRttMs = 100;
+const float kAlpha = 0.125f;
+const float kOneMinusAlpha = (1 - kAlpha);
+const float kBeta = 0.25f;
+const float kOneMinusBeta = (1 - kBeta);
+
+}
+
+RttStats::RttStats()
+ : latest_rtt_(QuicTime::Delta::Zero()),
+ min_rtt_(QuicTime::Delta::Zero()),
+ smoothed_rtt_(QuicTime::Delta::Zero()),
+ mean_deviation_(QuicTime::Delta::Zero()),
+ initial_rtt_us_(kInitialRttMs * base::Time::kMicrosecondsPerMillisecond) {
+}
+
+bool RttStats::HasUpdates() const {
+ return !smoothed_rtt_.IsZero();
+}
+
+// Updates the RTT based on a new sample.
+void RttStats::UpdateRtt(QuicTime::Delta send_delta,
+ QuicTime::Delta ack_delay) {
+ QuicTime::Delta rtt_sample(QuicTime::Delta::Zero());
+ if (send_delta > ack_delay) {
+ rtt_sample = send_delta.Subtract(ack_delay);
+ } else if (!HasUpdates()) {
+ // Even though we received information from the peer suggesting
+ // an invalid (negative) RTT, we can use the send delta as an
+ // approximation until we get a better estimate.
+ rtt_sample = send_delta;
+ }
+
+ if (rtt_sample.IsInfinite() || rtt_sample.IsZero()) {
+ DVLOG(1) << "Ignoring rtt, because it's "
+ << (rtt_sample.IsZero() ? "Zero" : "Infinite");
+ return;
+ }
+ // RTT can't be negative.
+ DCHECK_LT(0, rtt_sample.ToMicroseconds());
+
+ latest_rtt_ = rtt_sample;
+ // First time call or link delay decreases.
+ if (min_rtt_.IsZero() || min_rtt_ > rtt_sample) {
+ min_rtt_ = rtt_sample;
+ }
+ // First time call.
+ if (!HasUpdates()) {
+ smoothed_rtt_ = rtt_sample;
+ mean_deviation_ = QuicTime::Delta::FromMicroseconds(
+ rtt_sample.ToMicroseconds() / 2);
+ } else {
+ mean_deviation_ = QuicTime::Delta::FromMicroseconds(
+ kOneMinusBeta * mean_deviation_.ToMicroseconds() +
+ kBeta * std::abs(smoothed_rtt_.Subtract(rtt_sample).ToMicroseconds()));
+ smoothed_rtt_ = smoothed_rtt_.Multiply(kOneMinusAlpha).Add(
+ rtt_sample.Multiply(kAlpha));
+ DVLOG(1) << "Cubic; smoothed_rtt(us):" << smoothed_rtt_.ToMicroseconds()
+ << " mean_deviation(us):" << mean_deviation_.ToMicroseconds();
+ }
+}
+
+QuicTime::Delta RttStats::SmoothedRtt() const {
+ if (!HasUpdates()) {
+ return QuicTime::Delta::FromMicroseconds(initial_rtt_us_);
+ }
+ return smoothed_rtt_;
+}
+
+} // namespace net
« no previous file with comments | « net/quic/congestion_control/rtt_stats.h ('k') | net/quic/congestion_control/send_algorithm_interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698