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