| 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/core/congestion_control/rtt_stats.h" | 5 #include "net/quic/core/congestion_control/rtt_stats.h" |
| 6 | 6 |
| 7 #include <cstdlib> // std::abs | 7 #include <cstdlib> // std::abs |
| 8 | 8 |
| 9 #include "net/quic/platform/api/quic_logging.h" | |
| 10 | |
| 11 namespace net { | 9 namespace net { |
| 12 | 10 |
| 13 namespace { | 11 namespace { |
| 14 | 12 |
| 15 // Default initial rtt used before any samples are received. | 13 // Default initial rtt used before any samples are received. |
| 16 const int kInitialRttMs = 100; | 14 const int kInitialRttMs = 100; |
| 17 const float kAlpha = 0.125f; | 15 const float kAlpha = 0.125f; |
| 18 const float kOneMinusAlpha = (1 - kAlpha); | 16 const float kOneMinusAlpha = (1 - kAlpha); |
| 19 const float kBeta = 0.25f; | 17 const float kBeta = 0.25f; |
| 20 const float kOneMinusBeta = (1 - kBeta); | 18 const float kOneMinusBeta = (1 - kBeta); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 34 mean_deviation_, QuicTime::Delta::FromMicroseconds(std::abs( | 32 mean_deviation_, QuicTime::Delta::FromMicroseconds(std::abs( |
| 35 (smoothed_rtt_ - latest_rtt_).ToMicroseconds()))); | 33 (smoothed_rtt_ - latest_rtt_).ToMicroseconds()))); |
| 36 smoothed_rtt_ = std::max(smoothed_rtt_, latest_rtt_); | 34 smoothed_rtt_ = std::max(smoothed_rtt_, latest_rtt_); |
| 37 } | 35 } |
| 38 | 36 |
| 39 // Updates the RTT based on a new sample. | 37 // Updates the RTT based on a new sample. |
| 40 void RttStats::UpdateRtt(QuicTime::Delta send_delta, | 38 void RttStats::UpdateRtt(QuicTime::Delta send_delta, |
| 41 QuicTime::Delta ack_delay, | 39 QuicTime::Delta ack_delay, |
| 42 QuicTime now) { | 40 QuicTime now) { |
| 43 if (send_delta.IsInfinite() || send_delta <= QuicTime::Delta::Zero()) { | 41 if (send_delta.IsInfinite() || send_delta <= QuicTime::Delta::Zero()) { |
| 44 QUIC_LOG_FIRST_N(WARNING, 3) | 42 LOG(WARNING) << "Ignoring measured send_delta, because it's is " |
| 45 << "Ignoring measured send_delta, because it's is " | 43 << "either infinite, zero, or negative. send_delta = " |
| 46 << "either infinite, zero, or negative. send_delta = " | 44 << send_delta.ToMicroseconds(); |
| 47 << send_delta.ToMicroseconds(); | |
| 48 return; | 45 return; |
| 49 } | 46 } |
| 50 | 47 |
| 51 // Update min_rtt_ first. min_rtt_ does not use an rtt_sample corrected for | 48 // Update min_rtt_ first. min_rtt_ does not use an rtt_sample corrected for |
| 52 // ack_delay but the raw observed send_delta, since poor clock granularity at | 49 // ack_delay but the raw observed send_delta, since poor clock granularity at |
| 53 // the client may cause a high ack_delay to result in underestimation of the | 50 // the client may cause a high ack_delay to result in underestimation of the |
| 54 // min_rtt_. | 51 // min_rtt_. |
| 55 if (min_rtt_.IsZero() || min_rtt_ > send_delta) { | 52 if (min_rtt_.IsZero() || min_rtt_ > send_delta) { |
| 56 min_rtt_ = send_delta; | 53 min_rtt_ = send_delta; |
| 57 } | 54 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 69 // First time call. | 66 // First time call. |
| 70 if (smoothed_rtt_.IsZero()) { | 67 if (smoothed_rtt_.IsZero()) { |
| 71 smoothed_rtt_ = rtt_sample; | 68 smoothed_rtt_ = rtt_sample; |
| 72 mean_deviation_ = | 69 mean_deviation_ = |
| 73 QuicTime::Delta::FromMicroseconds(rtt_sample.ToMicroseconds() / 2); | 70 QuicTime::Delta::FromMicroseconds(rtt_sample.ToMicroseconds() / 2); |
| 74 } else { | 71 } else { |
| 75 mean_deviation_ = QuicTime::Delta::FromMicroseconds(static_cast<int64_t>( | 72 mean_deviation_ = QuicTime::Delta::FromMicroseconds(static_cast<int64_t>( |
| 76 kOneMinusBeta * mean_deviation_.ToMicroseconds() + | 73 kOneMinusBeta * mean_deviation_.ToMicroseconds() + |
| 77 kBeta * std::abs((smoothed_rtt_ - rtt_sample).ToMicroseconds()))); | 74 kBeta * std::abs((smoothed_rtt_ - rtt_sample).ToMicroseconds()))); |
| 78 smoothed_rtt_ = kOneMinusAlpha * smoothed_rtt_ + kAlpha * rtt_sample; | 75 smoothed_rtt_ = kOneMinusAlpha * smoothed_rtt_ + kAlpha * rtt_sample; |
| 79 QUIC_DVLOG(1) << " smoothed_rtt(us):" << smoothed_rtt_.ToMicroseconds() | 76 DVLOG(1) << " smoothed_rtt(us):" << smoothed_rtt_.ToMicroseconds() |
| 80 << " mean_deviation(us):" << mean_deviation_.ToMicroseconds(); | 77 << " mean_deviation(us):" << mean_deviation_.ToMicroseconds(); |
| 81 } | 78 } |
| 82 } | 79 } |
| 83 | 80 |
| 84 void RttStats::OnConnectionMigration() { | 81 void RttStats::OnConnectionMigration() { |
| 85 latest_rtt_ = QuicTime::Delta::Zero(); | 82 latest_rtt_ = QuicTime::Delta::Zero(); |
| 86 min_rtt_ = QuicTime::Delta::Zero(); | 83 min_rtt_ = QuicTime::Delta::Zero(); |
| 87 smoothed_rtt_ = QuicTime::Delta::Zero(); | 84 smoothed_rtt_ = QuicTime::Delta::Zero(); |
| 88 mean_deviation_ = QuicTime::Delta::Zero(); | 85 mean_deviation_ = QuicTime::Delta::Zero(); |
| 89 initial_rtt_us_ = kInitialRttMs * kNumMicrosPerMilli; | 86 initial_rtt_us_ = kInitialRttMs * kNumMicrosPerMilli; |
| 90 } | 87 } |
| 91 | 88 |
| 92 } // namespace net | 89 } // namespace net |
| OLD | NEW |