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 <algorithm> | 10 #include <algorithm> |
(...skipping 20 matching lines...) Expand all Loading... |
31 void UpdateRtt(QuicTime::Delta send_delta, | 31 void UpdateRtt(QuicTime::Delta send_delta, |
32 QuicTime::Delta ack_delay, | 32 QuicTime::Delta ack_delay, |
33 QuicTime now); | 33 QuicTime now); |
34 | 34 |
35 // Forces RttStats to sample a new recent min rtt within the next | 35 // Forces RttStats to sample a new recent min rtt within the next |
36 // |num_samples| UpdateRtt calls. | 36 // |num_samples| UpdateRtt calls. |
37 void SampleNewRecentMinRtt(uint32 num_samples); | 37 void SampleNewRecentMinRtt(uint32 num_samples); |
38 | 38 |
39 QuicTime::Delta SmoothedRtt() const; | 39 QuicTime::Delta SmoothedRtt() const; |
40 | 40 |
41 int64 initial_rtt_us() const { | 41 int64 initial_rtt_us() const { return initial_rtt_us_; } |
42 return initial_rtt_us_; | |
43 } | |
44 | 42 |
45 // Sets an initial RTT to be used for SmoothedRtt before any RTT updates. | 43 // Sets an initial RTT to be used for SmoothedRtt before any RTT updates. |
46 void set_initial_rtt_us(int64 initial_rtt_us) { | 44 void set_initial_rtt_us(int64 initial_rtt_us) { |
47 initial_rtt_us_ = initial_rtt_us; | 45 initial_rtt_us_ = initial_rtt_us; |
48 } | 46 } |
49 | 47 |
50 QuicTime::Delta latest_rtt() const { | 48 QuicTime::Delta latest_rtt() const { return latest_rtt_; } |
51 return latest_rtt_; | |
52 } | |
53 | 49 |
54 // Returns the min_rtt for the entire connection. | 50 // Returns the min_rtt for the entire connection. |
55 QuicTime::Delta min_rtt() const { | 51 QuicTime::Delta min_rtt() const { return min_rtt_; } |
56 return min_rtt_; | |
57 } | |
58 | 52 |
59 // Returns the min_rtt since SampleNewRecentMinRtt has been called, or the | 53 // Returns the min_rtt since SampleNewRecentMinRtt has been called, or the |
60 // min_rtt for the entire connection if SampleNewMinRtt was never called. | 54 // min_rtt for the entire connection if SampleNewMinRtt was never called. |
61 QuicTime::Delta recent_min_rtt() const { | 55 QuicTime::Delta recent_min_rtt() const { return recent_min_rtt_.rtt; } |
62 return recent_min_rtt_.rtt; | |
63 } | |
64 | 56 |
65 QuicTime::Delta mean_deviation() const { | 57 QuicTime::Delta mean_deviation() const { return mean_deviation_; } |
66 return mean_deviation_; | |
67 } | |
68 | 58 |
69 // Sets how old a recent min rtt sample can be. | 59 // Sets how old a recent min rtt sample can be. |
70 void set_recent_min_rtt_window(QuicTime::Delta recent_min_rtt_window) { | 60 void set_recent_min_rtt_window(QuicTime::Delta recent_min_rtt_window) { |
71 recent_min_rtt_window_ = recent_min_rtt_window; | 61 recent_min_rtt_window_ = recent_min_rtt_window; |
72 } | 62 } |
73 | 63 |
74 private: | 64 private: |
75 friend class test::RttStatsPeer; | 65 friend class test::RttStatsPeer; |
76 | 66 |
77 // Used to track a sampled RTT window. | 67 // Used to track a sampled RTT window. |
78 struct RttSample { | 68 struct RttSample { |
79 RttSample() : rtt(QuicTime::Delta::Zero()), time(QuicTime::Zero()) { } | 69 RttSample() : rtt(QuicTime::Delta::Zero()), time(QuicTime::Zero()) {} |
80 RttSample(QuicTime::Delta rtt, QuicTime time) : rtt(rtt), time(time) { } | 70 RttSample(QuicTime::Delta rtt, QuicTime time) : rtt(rtt), time(time) {} |
81 | 71 |
82 QuicTime::Delta rtt; | 72 QuicTime::Delta rtt; |
83 QuicTime time; // Time the rtt sample was recorded. | 73 QuicTime time; // Time the rtt sample was recorded. |
84 }; | 74 }; |
85 | 75 |
86 // Implements the resampling algorithm and the windowed min rtt algorithm. | 76 // Implements the resampling algorithm and the windowed min rtt algorithm. |
87 void UpdateRecentMinRtt(QuicTime::Delta rtt_sample, QuicTime now); | 77 void UpdateRecentMinRtt(QuicTime::Delta rtt_sample, QuicTime now); |
88 | 78 |
89 QuicTime::Delta latest_rtt_; | 79 QuicTime::Delta latest_rtt_; |
90 QuicTime::Delta min_rtt_; | 80 QuicTime::Delta min_rtt_; |
91 QuicTime::Delta smoothed_rtt_; | 81 QuicTime::Delta smoothed_rtt_; |
92 // Mean RTT deviation during this session. | 82 // Mean RTT deviation during this session. |
93 // Approximation of standard deviation, the error is roughly 1.25 times | 83 // Approximation of standard deviation, the error is roughly 1.25 times |
94 // larger than the standard deviation, for a normally distributed signal. | 84 // larger than the standard deviation, for a normally distributed signal. |
95 QuicTime::Delta mean_deviation_; | 85 QuicTime::Delta mean_deviation_; |
96 int64 initial_rtt_us_; | 86 int64 initial_rtt_us_; |
97 | 87 |
98 RttSample new_min_rtt_; | 88 RttSample new_min_rtt_; |
99 uint32 num_min_rtt_samples_remaining_; | 89 uint32 num_min_rtt_samples_remaining_; |
100 | 90 |
101 // State variables for Kathleen Nichols MinRTT algorithm. | 91 // State variables for Kathleen Nichols MinRTT algorithm. |
102 QuicTime::Delta recent_min_rtt_window_; | 92 QuicTime::Delta recent_min_rtt_window_; |
103 RttSample recent_min_rtt_; // a in the windowed algorithm. | 93 RttSample recent_min_rtt_; // a in the windowed algorithm. |
104 RttSample half_window_rtt_; // b in the sampled algorithm. | 94 RttSample half_window_rtt_; // b in the sampled algorithm. |
105 RttSample quarter_window_rtt_; // c in the sampled algorithm. | 95 RttSample quarter_window_rtt_; // c in the sampled algorithm. |
106 | 96 |
107 DISALLOW_COPY_AND_ASSIGN(RttStats); | 97 DISALLOW_COPY_AND_ASSIGN(RttStats); |
108 }; | 98 }; |
109 | 99 |
110 } // namespace net | 100 } // namespace net |
111 | 101 |
112 #endif // NET_QUIC_CONGESTION_CONTROL_RTT_STATS_H_ | 102 #endif // NET_QUIC_CONGESTION_CONTROL_RTT_STATS_H_ |
OLD | NEW |