| 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 // A convenience class to store rtt samples and calculate smoothed rtt. | 5 // A convenience class to store rtt samples and calculate smoothed rtt. |
| 6 | 6 |
| 7 #ifndef NET_QUIC_CONGESTION_CONTROL_RTT_STATS_H_ | 7 #ifndef NET_QUIC_CONGESTION_CONTROL_RTT_STATS_H_ |
| 8 #define NET_QUIC_CONGESTION_CONTROL_RTT_STATS_H_ | 8 #define NET_QUIC_CONGESTION_CONTROL_RTT_STATS_H_ |
| 9 | 9 |
| 10 #include <stdint.h> |
| 11 |
| 10 #include <algorithm> | 12 #include <algorithm> |
| 11 | 13 |
| 12 #include "base/basictypes.h" | 14 #include "base/macros.h" |
| 13 #include "net/quic/quic_protocol.h" | 15 #include "net/quic/quic_protocol.h" |
| 14 #include "net/quic/quic_time.h" | 16 #include "net/quic/quic_time.h" |
| 15 | 17 |
| 16 namespace net { | 18 namespace net { |
| 17 | 19 |
| 18 namespace test { | 20 namespace test { |
| 19 class RttStatsPeer; | 21 class RttStatsPeer; |
| 20 } // namespace test | 22 } // namespace test |
| 21 | 23 |
| 22 class NET_EXPORT_PRIVATE RttStats { | 24 class NET_EXPORT_PRIVATE RttStats { |
| 23 public: | 25 public: |
| 24 RttStats(); | 26 RttStats(); |
| 25 | 27 |
| 26 // Updates the RTT from an incoming ack which is received |send_delta| after | 28 // Updates the RTT from an incoming ack which is received |send_delta| after |
| 27 // the packet is sent and the peer reports the ack being delayed |ack_delay|. | 29 // the packet is sent and the peer reports the ack being delayed |ack_delay|. |
| 28 void UpdateRtt(QuicTime::Delta send_delta, | 30 void UpdateRtt(QuicTime::Delta send_delta, |
| 29 QuicTime::Delta ack_delay, | 31 QuicTime::Delta ack_delay, |
| 30 QuicTime now); | 32 QuicTime now); |
| 31 | 33 |
| 32 // Causes the smoothed_rtt to be increased to the latest_rtt if the latest_rtt | 34 // Causes the smoothed_rtt to be increased to the latest_rtt if the latest_rtt |
| 33 // is larger. The mean deviation is increased to the most recent deviation if | 35 // is larger. The mean deviation is increased to the most recent deviation if |
| 34 // it's larger. | 36 // it's larger. |
| 35 void ExpireSmoothedMetrics(); | 37 void ExpireSmoothedMetrics(); |
| 36 | 38 |
| 37 // Forces RttStats to sample a new recent min rtt within the next | 39 // Forces RttStats to sample a new recent min rtt within the next |
| 38 // |num_samples| UpdateRtt calls. | 40 // |num_samples| UpdateRtt calls. |
| 39 void SampleNewRecentMinRtt(uint32 num_samples); | 41 void SampleNewRecentMinRtt(uint32_t num_samples); |
| 40 | 42 |
| 41 // Called when connection migrates and rtt measurement needs to be reset. | 43 // Called when connection migrates and rtt measurement needs to be reset. |
| 42 void OnConnectionMigration(); | 44 void OnConnectionMigration(); |
| 43 | 45 |
| 44 // Returns the EWMA smoothed RTT for the connection. | 46 // Returns the EWMA smoothed RTT for the connection. |
| 45 // May return Zero if no valid updates have occurred. | 47 // May return Zero if no valid updates have occurred. |
| 46 QuicTime::Delta smoothed_rtt() const { return smoothed_rtt_; } | 48 QuicTime::Delta smoothed_rtt() const { return smoothed_rtt_; } |
| 47 | 49 |
| 48 int64 initial_rtt_us() const { return initial_rtt_us_; } | 50 int64_t initial_rtt_us() const { return initial_rtt_us_; } |
| 49 | 51 |
| 50 // Sets an initial RTT to be used for SmoothedRtt before any RTT updates. | 52 // Sets an initial RTT to be used for SmoothedRtt before any RTT updates. |
| 51 void set_initial_rtt_us(int64 initial_rtt_us) { | 53 void set_initial_rtt_us(int64_t initial_rtt_us) { |
| 52 if (initial_rtt_us <= 0) { | 54 if (initial_rtt_us <= 0) { |
| 53 LOG(DFATAL) << "Attempt to set initial rtt to <= 0."; | 55 LOG(DFATAL) << "Attempt to set initial rtt to <= 0."; |
| 54 return; | 56 return; |
| 55 } | 57 } |
| 56 initial_rtt_us_ = initial_rtt_us; | 58 initial_rtt_us_ = initial_rtt_us; |
| 57 } | 59 } |
| 58 | 60 |
| 59 // The most recent rtt measurement. | 61 // The most recent rtt measurement. |
| 60 // May return Zero if no valid updates have occurred. | 62 // May return Zero if no valid updates have occurred. |
| 61 QuicTime::Delta latest_rtt() const { return latest_rtt_; } | 63 QuicTime::Delta latest_rtt() const { return latest_rtt_; } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 90 // Implements the resampling algorithm and the windowed min rtt algorithm. | 92 // Implements the resampling algorithm and the windowed min rtt algorithm. |
| 91 void UpdateRecentMinRtt(QuicTime::Delta rtt_sample, QuicTime now); | 93 void UpdateRecentMinRtt(QuicTime::Delta rtt_sample, QuicTime now); |
| 92 | 94 |
| 93 QuicTime::Delta latest_rtt_; | 95 QuicTime::Delta latest_rtt_; |
| 94 QuicTime::Delta min_rtt_; | 96 QuicTime::Delta min_rtt_; |
| 95 QuicTime::Delta smoothed_rtt_; | 97 QuicTime::Delta smoothed_rtt_; |
| 96 // Mean RTT deviation during this session. | 98 // Mean RTT deviation during this session. |
| 97 // Approximation of standard deviation, the error is roughly 1.25 times | 99 // Approximation of standard deviation, the error is roughly 1.25 times |
| 98 // larger than the standard deviation, for a normally distributed signal. | 100 // larger than the standard deviation, for a normally distributed signal. |
| 99 QuicTime::Delta mean_deviation_; | 101 QuicTime::Delta mean_deviation_; |
| 100 int64 initial_rtt_us_; | 102 int64_t initial_rtt_us_; |
| 101 | 103 |
| 102 RttSample new_min_rtt_; | 104 RttSample new_min_rtt_; |
| 103 uint32 num_min_rtt_samples_remaining_; | 105 uint32_t num_min_rtt_samples_remaining_; |
| 104 | 106 |
| 105 // State variables for Kathleen Nichols MinRTT algorithm. | 107 // State variables for Kathleen Nichols MinRTT algorithm. |
| 106 QuicTime::Delta recent_min_rtt_window_; | 108 QuicTime::Delta recent_min_rtt_window_; |
| 107 RttSample recent_min_rtt_; // a in the windowed algorithm. | 109 RttSample recent_min_rtt_; // a in the windowed algorithm. |
| 108 RttSample half_window_rtt_; // b in the sampled algorithm. | 110 RttSample half_window_rtt_; // b in the sampled algorithm. |
| 109 RttSample quarter_window_rtt_; // c in the sampled algorithm. | 111 RttSample quarter_window_rtt_; // c in the sampled algorithm. |
| 110 | 112 |
| 111 DISALLOW_COPY_AND_ASSIGN(RttStats); | 113 DISALLOW_COPY_AND_ASSIGN(RttStats); |
| 112 }; | 114 }; |
| 113 | 115 |
| 114 } // namespace net | 116 } // namespace net |
| 115 | 117 |
| 116 #endif // NET_QUIC_CONGESTION_CONTROL_RTT_STATS_H_ | 118 #endif // NET_QUIC_CONGESTION_CONTROL_RTT_STATS_H_ |
| OLD | NEW |