| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/congestion_control/rtt_stats.h" | 5 #include "net/quic/congestion_control/rtt_stats.h" |
| 6 | 6 |
| 7 using std::max; |
| 8 |
| 7 namespace net { | 9 namespace net { |
| 8 | 10 |
| 9 namespace { | 11 namespace { |
| 10 | 12 |
| 11 // Default initial rtt used before any samples are received. | 13 // Default initial rtt used before any samples are received. |
| 12 const int kInitialRttMs = 100; | 14 const int kInitialRttMs = 100; |
| 13 const float kAlpha = 0.125f; | 15 const float kAlpha = 0.125f; |
| 14 const float kOneMinusAlpha = (1 - kAlpha); | 16 const float kOneMinusAlpha = (1 - kAlpha); |
| 15 const float kBeta = 0.25f; | 17 const float kBeta = 0.25f; |
| 16 const float kOneMinusBeta = (1 - kBeta); | 18 const float kOneMinusBeta = (1 - kBeta); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 30 | 32 |
| 31 bool RttStats::HasUpdates() const { | 33 bool RttStats::HasUpdates() const { |
| 32 return !smoothed_rtt_.IsZero(); | 34 return !smoothed_rtt_.IsZero(); |
| 33 } | 35 } |
| 34 | 36 |
| 35 void RttStats::SampleNewRecentMinRtt(uint32 num_samples) { | 37 void RttStats::SampleNewRecentMinRtt(uint32 num_samples) { |
| 36 num_min_rtt_samples_remaining_ = num_samples; | 38 num_min_rtt_samples_remaining_ = num_samples; |
| 37 new_min_rtt_ = RttSample(); | 39 new_min_rtt_ = RttSample(); |
| 38 } | 40 } |
| 39 | 41 |
| 42 void RttStats::ExpireSmoothedMetrics() { |
| 43 mean_deviation_ = max(mean_deviation_, latest_rtt_.Subtract(smoothed_rtt_)); |
| 44 smoothed_rtt_ = max(smoothed_rtt_, latest_rtt_); |
| 45 } |
| 46 |
| 40 // Updates the RTT based on a new sample. | 47 // Updates the RTT based on a new sample. |
| 41 void RttStats::UpdateRtt(QuicTime::Delta send_delta, | 48 void RttStats::UpdateRtt(QuicTime::Delta send_delta, |
| 42 QuicTime::Delta ack_delay, | 49 QuicTime::Delta ack_delay, |
| 43 QuicTime now) { | 50 QuicTime now) { |
| 44 QuicTime::Delta rtt_sample(QuicTime::Delta::Zero()); | 51 QuicTime::Delta rtt_sample(QuicTime::Delta::Zero()); |
| 45 if (send_delta > ack_delay) { | 52 if (send_delta > ack_delay) { |
| 46 rtt_sample = send_delta.Subtract(ack_delay); | 53 rtt_sample = send_delta.Subtract(ack_delay); |
| 47 } else if (!HasUpdates()) { | 54 } else if (!HasUpdates()) { |
| 48 // Even though we received information from the peer suggesting | 55 // Even though we received information from the peer suggesting |
| 49 // an invalid (negative) RTT, we can use the send delta as an | 56 // an invalid (negative) RTT, we can use the send delta as an |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 } | 127 } |
| 121 | 128 |
| 122 QuicTime::Delta RttStats::SmoothedRtt() const { | 129 QuicTime::Delta RttStats::SmoothedRtt() const { |
| 123 if (!HasUpdates()) { | 130 if (!HasUpdates()) { |
| 124 return QuicTime::Delta::FromMicroseconds(initial_rtt_us_); | 131 return QuicTime::Delta::FromMicroseconds(initial_rtt_us_); |
| 125 } | 132 } |
| 126 return smoothed_rtt_; | 133 return smoothed_rtt_; |
| 127 } | 134 } |
| 128 | 135 |
| 129 } // namespace net | 136 } // namespace net |
| OLD | NEW |