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> | 10 #include <stdint.h> |
11 | 11 |
12 #include <algorithm> | 12 #include <algorithm> |
13 | 13 |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "net/base/net_export.h" | 15 #include "net/base/net_export.h" |
16 #include "net/quic/core/congestion_control/windowed_filter.h" | |
17 #include "net/quic/core/quic_bug_tracker.h" | 16 #include "net/quic/core/quic_bug_tracker.h" |
18 #include "net/quic/core/quic_protocol.h" | 17 #include "net/quic/core/quic_protocol.h" |
19 #include "net/quic/core/quic_time.h" | 18 #include "net/quic/core/quic_time.h" |
20 | 19 |
21 namespace net { | 20 namespace net { |
22 | 21 |
23 namespace test { | 22 namespace test { |
24 class RttStatsPeer; | 23 class RttStatsPeer; |
25 } // namespace test | 24 } // namespace test |
26 | 25 |
27 class NET_EXPORT_PRIVATE RttStats { | 26 class NET_EXPORT_PRIVATE RttStats { |
28 public: | 27 public: |
29 RttStats(); | 28 RttStats(); |
30 | 29 |
31 // Updates the RTT from an incoming ack which is received |send_delta| after | 30 // Updates the RTT from an incoming ack which is received |send_delta| after |
32 // the packet is sent and the peer reports the ack being delayed |ack_delay|. | 31 // the packet is sent and the peer reports the ack being delayed |ack_delay|. |
33 void UpdateRtt(QuicTime::Delta send_delta, | 32 void UpdateRtt(QuicTime::Delta send_delta, |
34 QuicTime::Delta ack_delay, | 33 QuicTime::Delta ack_delay, |
35 QuicTime now); | 34 QuicTime now); |
36 | 35 |
37 // Causes the smoothed_rtt to be increased to the latest_rtt if the latest_rtt | 36 // Causes the smoothed_rtt to be increased to the latest_rtt if the latest_rtt |
38 // is larger. The mean deviation is increased to the most recent deviation if | 37 // is larger. The mean deviation is increased to the most recent deviation if |
39 // it's larger. | 38 // it's larger. |
40 void ExpireSmoothedMetrics(); | 39 void ExpireSmoothedMetrics(); |
41 | 40 |
42 // Forces RttStats to sample a new windowed min rtt within the next | |
43 // |num_samples| UpdateRtt calls. | |
44 void SampleNewWindowedMinRtt(uint32_t num_samples); | |
45 | |
46 // Called when connection migrates and rtt measurement needs to be reset. | 41 // Called when connection migrates and rtt measurement needs to be reset. |
47 void OnConnectionMigration(); | 42 void OnConnectionMigration(); |
48 | 43 |
49 // Returns the EWMA smoothed RTT for the connection. | 44 // Returns the EWMA smoothed RTT for the connection. |
50 // May return Zero if no valid updates have occurred. | 45 // May return Zero if no valid updates have occurred. |
51 QuicTime::Delta smoothed_rtt() const { return smoothed_rtt_; } | 46 QuicTime::Delta smoothed_rtt() const { return smoothed_rtt_; } |
52 | 47 |
53 // Returns the EWMA smoothed RTT prior to the most recent RTT sample. | 48 // Returns the EWMA smoothed RTT prior to the most recent RTT sample. |
54 QuicTime::Delta previous_srtt() const { return previous_srtt_; } | 49 QuicTime::Delta previous_srtt() const { return previous_srtt_; } |
55 | 50 |
(...skipping 11 matching lines...) Expand all Loading... |
67 // The most recent rtt measurement. | 62 // The most recent rtt measurement. |
68 // May return Zero if no valid updates have occurred. | 63 // May return Zero if no valid updates have occurred. |
69 QuicTime::Delta latest_rtt() const { return latest_rtt_; } | 64 QuicTime::Delta latest_rtt() const { return latest_rtt_; } |
70 | 65 |
71 // Returns the min_rtt for the entire connection. | 66 // Returns the min_rtt for the entire connection. |
72 // May return Zero if no valid updates have occurred. | 67 // May return Zero if no valid updates have occurred. |
73 QuicTime::Delta min_rtt() const { return min_rtt_; } | 68 QuicTime::Delta min_rtt() const { return min_rtt_; } |
74 | 69 |
75 QuicTime::Delta mean_deviation() const { return mean_deviation_; } | 70 QuicTime::Delta mean_deviation() const { return mean_deviation_; } |
76 | 71 |
77 QuicTime::Delta WindowedMinRtt() { return windowed_min_rtt_.GetBest(); } | |
78 | |
79 private: | 72 private: |
80 friend class test::RttStatsPeer; | 73 friend class test::RttStatsPeer; |
81 | 74 |
82 // Updates the windowed min rtt. Also forces a new windowed_min_rtt sample, | |
83 // if set by a call to SampleNewWindowedMinRtt() above. | |
84 void UpdateWindowedMinRtt(QuicTime::Delta rtt_sample, QuicTime now); | |
85 | |
86 QuicTime::Delta latest_rtt_; | 75 QuicTime::Delta latest_rtt_; |
87 QuicTime::Delta min_rtt_; | 76 QuicTime::Delta min_rtt_; |
88 QuicTime::Delta smoothed_rtt_; | 77 QuicTime::Delta smoothed_rtt_; |
89 QuicTime::Delta previous_srtt_; | 78 QuicTime::Delta previous_srtt_; |
90 // Mean RTT deviation during this session. | 79 // Mean RTT deviation during this session. |
91 // Approximation of standard deviation, the error is roughly 1.25 times | 80 // Approximation of standard deviation, the error is roughly 1.25 times |
92 // larger than the standard deviation, for a normally distributed signal. | 81 // larger than the standard deviation, for a normally distributed signal. |
93 QuicTime::Delta mean_deviation_; | 82 QuicTime::Delta mean_deviation_; |
94 int64_t initial_rtt_us_; | 83 int64_t initial_rtt_us_; |
95 | 84 |
96 // Variables used to force a new windowed_min_rtt measurement within | |
97 // num_samples_for_forced_min_. | |
98 QuicTime::Delta forced_windowed_min_rtt_; | |
99 QuicTime forced_windowed_min_rtt_time_; | |
100 uint32_t num_samples_for_forced_min_; | |
101 | |
102 // Windowed min_rtt. | |
103 WindowedFilter<QuicTime::Delta, | |
104 MinFilter<QuicTime::Delta>, | |
105 QuicTime, | |
106 QuicTime::Delta> | |
107 windowed_min_rtt_; | |
108 | |
109 DISALLOW_COPY_AND_ASSIGN(RttStats); | 85 DISALLOW_COPY_AND_ASSIGN(RttStats); |
110 }; | 86 }; |
111 | 87 |
112 } // namespace net | 88 } // namespace net |
113 | 89 |
114 #endif // NET_QUIC_CONGESTION_CONTROL_RTT_STATS_H_ | 90 #endif // NET_QUIC_CONGESTION_CONTROL_RTT_STATS_H_ |
OLD | NEW |