OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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_bytes.h" | 5 #include "net/quic/congestion_control/cubic_bytes.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <cmath> | 9 #include <cmath> |
10 | 10 |
11 #include "base/basictypes.h" | |
12 #include "base/logging.h" | 11 #include "base/logging.h" |
13 #include "net/quic/quic_protocol.h" | 12 #include "net/quic/quic_protocol.h" |
14 | 13 |
15 using std::max; | 14 using std::max; |
16 | 15 |
17 namespace net { | 16 namespace net { |
18 | 17 |
19 namespace { | 18 namespace { |
20 | 19 |
21 // Constants based on TCP defaults. | 20 // Constants based on TCP defaults. |
22 // The following constants are in 2^10 fractions of a second instead of ms to | 21 // The following constants are in 2^10 fractions of a second instead of ms to |
23 // allow a 10 shift right to divide. | 22 // allow a 10 shift right to divide. |
24 const int kCubeScale = 40; // 1024*1024^3 (first 1024 is from 0.100^3) | 23 const int kCubeScale = 40; // 1024*1024^3 (first 1024 is from 0.100^3) |
25 // where 0.100 is 100 ms which is the scaling | 24 // where 0.100 is 100 ms which is the scaling |
26 // round trip time. | 25 // round trip time. |
27 const int kCubeCongestionWindowScale = 410; | 26 const int kCubeCongestionWindowScale = 410; |
28 // The cube factor for packets in bytes. | 27 // The cube factor for packets in bytes. |
29 const uint64 kCubeFactor = | 28 const uint64_t kCubeFactor = |
30 (UINT64_C(1) << kCubeScale) / kCubeCongestionWindowScale / kDefaultTCPMSS; | 29 (UINT64_C(1) << kCubeScale) / kCubeCongestionWindowScale / kDefaultTCPMSS; |
31 | 30 |
32 const uint32 kDefaultNumConnections = 2; | 31 const uint32_t kDefaultNumConnections = 2; |
33 const float kBeta = 0.7f; // Default Cubic backoff factor. | 32 const float kBeta = 0.7f; // Default Cubic backoff factor. |
34 // 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 |
35 // 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 |
36 // new concurrent flows and speed up convergence. | 35 // new concurrent flows and speed up convergence. |
37 const float kBetaLastMax = 0.85f; | 36 const float kBetaLastMax = 0.85f; |
38 | 37 |
39 } // namespace | 38 } // namespace |
40 | 39 |
41 CubicBytes::CubicBytes(const QuicClock* clock) | 40 CubicBytes::CubicBytes(const QuicClock* clock) |
42 : clock_(clock), | 41 : clock_(clock), |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 // First ACK after a loss event. | 123 // First ACK after a loss event. |
125 DVLOG(1) << "Start of epoch"; | 124 DVLOG(1) << "Start of epoch"; |
126 epoch_ = current_time; // Start of epoch. | 125 epoch_ = current_time; // Start of epoch. |
127 acked_bytes_count_ = acked_bytes; // Reset count. | 126 acked_bytes_count_ = acked_bytes; // Reset count. |
128 // Reset estimated_tcp_congestion_window_ to be in sync with cubic. | 127 // Reset estimated_tcp_congestion_window_ to be in sync with cubic. |
129 estimated_tcp_congestion_window_ = current_congestion_window; | 128 estimated_tcp_congestion_window_ = current_congestion_window; |
130 if (last_max_congestion_window_ <= current_congestion_window) { | 129 if (last_max_congestion_window_ <= current_congestion_window) { |
131 time_to_origin_point_ = 0; | 130 time_to_origin_point_ = 0; |
132 origin_point_congestion_window_ = current_congestion_window; | 131 origin_point_congestion_window_ = current_congestion_window; |
133 } else { | 132 } else { |
134 time_to_origin_point_ = | 133 time_to_origin_point_ = static_cast<uint32_t>( |
135 static_cast<uint32>(cbrt(kCubeFactor * (last_max_congestion_window_ - | 134 cbrt(kCubeFactor * |
136 current_congestion_window))); | 135 (last_max_congestion_window_ - current_congestion_window))); |
137 origin_point_congestion_window_ = last_max_congestion_window_; | 136 origin_point_congestion_window_ = last_max_congestion_window_; |
138 } | 137 } |
139 } | 138 } |
140 // Change the time unit from microseconds to 2^10 fractions per second. Take | 139 // Change the time unit from microseconds to 2^10 fractions per second. Take |
141 // the round trip time in account. This is done to allow us to use shift as a | 140 // the round trip time in account. This is done to allow us to use shift as a |
142 // divide operator. | 141 // divide operator. |
143 int64 elapsed_time = | 142 int64_t elapsed_time = |
144 (current_time.Add(delay_min).Subtract(epoch_).ToMicroseconds() << 10) / | 143 (current_time.Add(delay_min).Subtract(epoch_).ToMicroseconds() << 10) / |
145 kNumMicrosPerSecond; | 144 kNumMicrosPerSecond; |
146 | 145 |
147 int64 offset = time_to_origin_point_ - elapsed_time; | 146 int64_t offset = time_to_origin_point_ - elapsed_time; |
148 QuicByteCount delta_congestion_window = | 147 QuicByteCount delta_congestion_window = |
149 ((kCubeCongestionWindowScale * offset * offset * offset) >> kCubeScale) * | 148 ((kCubeCongestionWindowScale * offset * offset * offset) >> kCubeScale) * |
150 kDefaultTCPMSS; | 149 kDefaultTCPMSS; |
151 | 150 |
152 QuicByteCount target_congestion_window = | 151 QuicByteCount target_congestion_window = |
153 origin_point_congestion_window_ - delta_congestion_window; | 152 origin_point_congestion_window_ - delta_congestion_window; |
154 | 153 |
155 DCHECK_LT(0u, estimated_tcp_congestion_window_); | 154 DCHECK_LT(0u, estimated_tcp_congestion_window_); |
156 // Increase the window by Alpha * 1 MSS of bytes every time we ack an | 155 // Increase the window by Alpha * 1 MSS of bytes every time we ack an |
157 // estimated tcp window of bytes. | 156 // estimated tcp window of bytes. |
158 estimated_tcp_congestion_window_ += acked_bytes_count_ * | 157 estimated_tcp_congestion_window_ += acked_bytes_count_ * |
159 (Alpha() * kDefaultTCPMSS) / | 158 (Alpha() * kDefaultTCPMSS) / |
160 estimated_tcp_congestion_window_; | 159 estimated_tcp_congestion_window_; |
161 acked_bytes_count_ = 0; | 160 acked_bytes_count_ = 0; |
162 | 161 |
163 // We have a new cubic congestion window. | 162 // We have a new cubic congestion window. |
164 last_target_congestion_window_ = target_congestion_window; | 163 last_target_congestion_window_ = target_congestion_window; |
165 | 164 |
166 // Compute target congestion_window based on cubic target and estimated TCP | 165 // Compute target congestion_window based on cubic target and estimated TCP |
167 // congestion_window, use highest (fastest). | 166 // congestion_window, use highest (fastest). |
168 if (target_congestion_window < estimated_tcp_congestion_window_) { | 167 if (target_congestion_window < estimated_tcp_congestion_window_) { |
169 target_congestion_window = estimated_tcp_congestion_window_; | 168 target_congestion_window = estimated_tcp_congestion_window_; |
170 } | 169 } |
171 | 170 |
172 DVLOG(1) << "Final target congestion_window: " << target_congestion_window; | 171 DVLOG(1) << "Final target congestion_window: " << target_congestion_window; |
173 return target_congestion_window; | 172 return target_congestion_window; |
174 } | 173 } |
175 | 174 |
176 } // namespace net | 175 } // namespace net |
OLD | NEW |