OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/congestion_control/cubic.h" | 5 #include "net/quic/congestion_control/cubic.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "net/quic/congestion_control/cube_root.h" | 12 #include "net/quic/congestion_control/cube_root.h" |
13 #include "net/quic/quic_protocol.h" | 13 #include "net/quic/quic_protocol.h" |
14 | 14 |
15 using std::max; | 15 using std::max; |
16 | 16 |
17 namespace net { | 17 namespace net { |
18 | 18 |
19 namespace { | 19 namespace { |
| 20 |
20 // Constants based on TCP defaults. | 21 // Constants based on TCP defaults. |
21 // The following constants are in 2^10 fractions of a second instead of ms to | 22 // The following constants are in 2^10 fractions of a second instead of ms to |
22 // allow a 10 shift right to divide. | 23 // allow a 10 shift right to divide. |
23 const int kCubeScale = 40; // 1024*1024^3 (first 1024 is from 0.100^3) | 24 const int kCubeScale = 40; // 1024*1024^3 (first 1024 is from 0.100^3) |
24 // where 0.100 is 100 ms which is the scaling | 25 // where 0.100 is 100 ms which is the scaling |
25 // round trip time. | 26 // round trip time. |
26 const int kCubeCongestionWindowScale = 410; | 27 const int kCubeCongestionWindowScale = 410; |
27 const uint64 kCubeFactor = (GG_UINT64_C(1) << kCubeScale) / | 28 const uint64 kCubeFactor = (GG_UINT64_C(1) << kCubeScale) / |
28 kCubeCongestionWindowScale; | 29 kCubeCongestionWindowScale; |
29 | 30 |
30 const uint32 kNumConnections = 2; | 31 const uint32 kNumConnections = 2; |
31 const float kBeta = 0.7f; // Default Cubic backoff factor. | 32 const float kBeta = 0.7f; // Default Cubic backoff factor. |
32 // Additional backoff factor when loss occurs in the concave part of the Cubic | 33 // Additional backoff factor when loss occurs in the concave part of the Cubic |
33 // curve. This additional backoff factor is expected to give up bandwidth to | 34 // curve. This additional backoff factor is expected to give up bandwidth to |
34 // new concurrent flows and speed up convergence. | 35 // new concurrent flows and speed up convergence. |
35 const float kBetaLastMax = 0.85f; | 36 const float kBetaLastMax = 0.85f; |
36 | 37 |
37 // kNConnectionBeta is the backoff factor after loss for our N-connection | 38 // kNConnectionBeta is the backoff factor after loss for our N-connection |
38 // emulation, which emulates the effective backoff of an ensemble of N TCP-Reno | 39 // emulation, which emulates the effective backoff of an ensemble of N TCP-Reno |
39 // connections on a single loss event. The effective multiplier is computed as: | 40 // connections on a single loss event. The effective multiplier is computed as: |
40 const float kNConnectionBeta = (kNumConnections - 1 + kBeta) / kNumConnections; | 41 const float kNConnectionBeta = (kNumConnections - 1 + kBeta) / kNumConnections; |
41 | 42 |
42 // TCPFriendly alpha is described in Section 3.3 of the CUBIC paper. Note that | 43 // TCPFriendly alpha is described in Section 3.3 of the CUBIC paper. Note that |
43 // kBeta here is a cwnd multiplier, and is equal to 1-beta from the CUBIC paper. | 44 // kBeta here is a cwnd multiplier, and is equal to 1-beta from the CUBIC paper. |
44 // We derive the equivalent kNConnectionAlpha for an N-connection emulation as: | 45 // We derive the equivalent kNConnectionAlpha for an N-connection emulation as: |
45 const float kNConnectionAlpha = 3 * kNumConnections * kNumConnections * | 46 const float kNConnectionAlpha = 3 * kNumConnections * kNumConnections * |
46 (1 - kNConnectionBeta) / (1 + kNConnectionBeta); | 47 (1 - kNConnectionBeta) / (1 + kNConnectionBeta); |
47 // TODO(jri): Compute kNConnectionBeta and kNConnectionAlpha from | 48 // TODO(jri): Compute kNConnectionBeta and kNConnectionAlpha from |
48 // number of active streams. | 49 // number of active streams. |
| 50 |
49 } // namespace | 51 } // namespace |
50 | 52 |
51 Cubic::Cubic(const QuicClock* clock) | 53 Cubic::Cubic(const QuicClock* clock, QuicConnectionStats* stats) |
52 : clock_(clock), | 54 : clock_(clock), |
53 epoch_(QuicTime::Zero()), | 55 epoch_(QuicTime::Zero()), |
54 last_update_time_(QuicTime::Zero()) { | 56 last_update_time_(QuicTime::Zero()), |
| 57 stats_(stats) { |
55 Reset(); | 58 Reset(); |
56 } | 59 } |
57 | 60 |
58 void Cubic::Reset() { | 61 void Cubic::Reset() { |
59 epoch_ = QuicTime::Zero(); // Reset time. | 62 epoch_ = QuicTime::Zero(); // Reset time. |
60 last_update_time_ = QuicTime::Zero(); // Reset time. | 63 last_update_time_ = QuicTime::Zero(); // Reset time. |
61 last_congestion_window_ = 0; | 64 last_congestion_window_ = 0; |
62 last_max_congestion_window_ = 0; | 65 last_max_congestion_window_ = 0; |
63 acked_packets_count_ = 0; | 66 acked_packets_count_ = 0; |
64 estimated_tcp_congestion_window_ = 0; | 67 estimated_tcp_congestion_window_ = 0; |
65 origin_point_congestion_window_ = 0; | 68 origin_point_congestion_window_ = 0; |
66 time_to_origin_point_ = 0; | 69 time_to_origin_point_ = 0; |
67 last_target_congestion_window_ = 0; | 70 last_target_congestion_window_ = 0; |
68 } | 71 } |
69 | 72 |
| 73 void Cubic::UpdateCongestionControlStats( |
| 74 QuicTcpCongestionWindow new_cubic_mode_cwnd, |
| 75 QuicTcpCongestionWindow new_reno_mode_cwnd) { |
| 76 if (last_congestion_window_ < new_cubic_mode_cwnd) { |
| 77 // Congestion window will increase in cubic mode. |
| 78 stats_->cwnd_increase_cubic_mode += new_cubic_mode_cwnd - |
| 79 last_congestion_window_; |
| 80 if (new_cubic_mode_cwnd <= new_reno_mode_cwnd) { |
| 81 // Congestion window increase in reno mode is higher or equal to cubic |
| 82 // mode's increase. |
| 83 stats_->cwnd_increase_reno_mode += new_reno_mode_cwnd - |
| 84 last_congestion_window_; |
| 85 } |
| 86 } else if (last_congestion_window_ < new_reno_mode_cwnd) { |
| 87 // No cwnd increase in cubic mode, but cwnd will increase in reno mode. |
| 88 stats_->cwnd_increase_reno_mode += new_reno_mode_cwnd - |
| 89 last_congestion_window_; |
| 90 } |
| 91 } |
| 92 |
70 QuicTcpCongestionWindow Cubic::CongestionWindowAfterPacketLoss( | 93 QuicTcpCongestionWindow Cubic::CongestionWindowAfterPacketLoss( |
71 QuicTcpCongestionWindow current_congestion_window) { | 94 QuicTcpCongestionWindow current_congestion_window) { |
72 if (current_congestion_window < last_max_congestion_window_) { | 95 if (current_congestion_window < last_max_congestion_window_) { |
73 // We never reached the old max, so assume we are competing with another | 96 // We never reached the old max, so assume we are competing with another |
74 // flow. Use our extra back off factor to allow the other flow to go up. | 97 // flow. Use our extra back off factor to allow the other flow to go up. |
75 last_max_congestion_window_ = | 98 last_max_congestion_window_ = |
76 static_cast<int>(kBetaLastMax * current_congestion_window); | 99 static_cast<int>(kBetaLastMax * current_congestion_window); |
77 } else { | 100 } else { |
78 last_max_congestion_window_ = current_congestion_window; | 101 last_max_congestion_window_ = current_congestion_window; |
79 } | 102 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 (current_time.Add(delay_min).Subtract(epoch_).ToMicroseconds() << 10) / | 143 (current_time.Add(delay_min).Subtract(epoch_).ToMicroseconds() << 10) / |
121 base::Time::kMicrosecondsPerSecond; | 144 base::Time::kMicrosecondsPerSecond; |
122 | 145 |
123 int64 offset = time_to_origin_point_ - elapsed_time; | 146 int64 offset = time_to_origin_point_ - elapsed_time; |
124 QuicTcpCongestionWindow delta_congestion_window = (kCubeCongestionWindowScale | 147 QuicTcpCongestionWindow delta_congestion_window = (kCubeCongestionWindowScale |
125 * offset * offset * offset) >> kCubeScale; | 148 * offset * offset * offset) >> kCubeScale; |
126 | 149 |
127 QuicTcpCongestionWindow target_congestion_window = | 150 QuicTcpCongestionWindow target_congestion_window = |
128 origin_point_congestion_window_ - delta_congestion_window; | 151 origin_point_congestion_window_ - delta_congestion_window; |
129 | 152 |
130 // We have a new cubic congestion window. | |
131 last_target_congestion_window_ = target_congestion_window; | |
132 | |
133 DCHECK_LT(0u, estimated_tcp_congestion_window_); | 153 DCHECK_LT(0u, estimated_tcp_congestion_window_); |
134 // With dynamic beta/alpha based on number of active streams, it is possible | 154 // With dynamic beta/alpha based on number of active streams, it is possible |
135 // for the required_ack_count to become much lower than acked_packets_count_ | 155 // for the required_ack_count to become much lower than acked_packets_count_ |
136 // suddenly, leading to more than one iteration through the following loop. | 156 // suddenly, leading to more than one iteration through the following loop. |
137 while (true) { | 157 while (true) { |
138 // Update estimated TCP congestion_window. | 158 // Update estimated TCP congestion_window. |
139 uint32 required_ack_count = | 159 uint32 required_ack_count = |
140 estimated_tcp_congestion_window_ / kNConnectionAlpha; | 160 estimated_tcp_congestion_window_ / kNConnectionAlpha; |
141 if (acked_packets_count_ < required_ack_count) { | 161 if (acked_packets_count_ < required_ack_count) { |
142 break; | 162 break; |
143 } | 163 } |
144 acked_packets_count_ -= required_ack_count; | 164 acked_packets_count_ -= required_ack_count; |
145 estimated_tcp_congestion_window_++; | 165 estimated_tcp_congestion_window_++; |
146 } | 166 } |
147 | 167 |
| 168 // Update cubic mode and reno mode stats in QuicConnectionStats. |
| 169 UpdateCongestionControlStats(target_congestion_window, |
| 170 estimated_tcp_congestion_window_); |
| 171 |
| 172 // We have a new cubic congestion window. |
| 173 last_target_congestion_window_ = target_congestion_window; |
| 174 |
148 // Compute target congestion_window based on cubic target and estimated TCP | 175 // Compute target congestion_window based on cubic target and estimated TCP |
149 // congestion_window, use highest (fastest). | 176 // congestion_window, use highest (fastest). |
150 if (target_congestion_window < estimated_tcp_congestion_window_) { | 177 if (target_congestion_window < estimated_tcp_congestion_window_) { |
151 target_congestion_window = estimated_tcp_congestion_window_; | 178 target_congestion_window = estimated_tcp_congestion_window_; |
152 } | 179 } |
153 DVLOG(1) << "Target congestion_window:" << target_congestion_window; | 180 |
| 181 DVLOG(1) << "Target congestion_window: " << target_congestion_window; |
154 return target_congestion_window; | 182 return target_congestion_window; |
155 } | 183 } |
156 | 184 |
157 } // namespace net | 185 } // namespace net |
OLD | NEW |