Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(840)

Side by Side Diff: net/quic/congestion_control/tcp_cubic_bytes_sender.cc

Issue 1014433002: Land Recent QUIC Changes until 03/09/2015. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@replaces_Perspective_enun_88006458
Patch Set: Rebase - added NET_EXPORT_PRIVATE to fix compiler error Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 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/tcp_cubic_sender.h" 5 #include "net/quic/congestion_control/tcp_cubic_bytes_sender.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/metrics/histogram.h"
10 #include "net/quic/congestion_control/prr_sender.h" 9 #include "net/quic/congestion_control/prr_sender.h"
11 #include "net/quic/congestion_control/rtt_stats.h" 10 #include "net/quic/congestion_control/rtt_stats.h"
12 #include "net/quic/crypto/crypto_protocol.h" 11 #include "net/quic/crypto/crypto_protocol.h"
13 12
14 using std::max; 13 using std::max;
15 using std::min; 14 using std::min;
16 15
17 namespace net { 16 namespace net {
18 17
19 namespace { 18 namespace {
20 // Constants based on TCP defaults. 19 // Constants based on TCP defaults.
21 // The minimum cwnd based on RFC 3782 (TCP NewReno) for cwnd reductions on a 20 // The minimum cwnd based on RFC 3782 (TCP NewReno) for cwnd reductions on a
22 // fast retransmission. The cwnd after a timeout is still 1. 21 // fast retransmission.
23 const QuicPacketCount kMinimumCongestionWindow = 2; 22 const QuicByteCount kMinimumCongestionWindow = 2 * kDefaultTCPMSS;
24 const QuicByteCount kMaxSegmentSize = kDefaultTCPMSS; 23 const QuicByteCount kMaxSegmentSize = kDefaultTCPMSS;
25 const int kMaxBurstLength = 3; 24 const int kMaxBurstLength = 3;
26 const float kRenoBeta = 0.7f; // Reno backoff factor. 25 const float kRenoBeta = 0.7f; // Reno backoff factor.
27 const uint32 kDefaultNumConnections = 2; // N-connection emulation. 26 const uint32 kDefaultNumConnections = 2; // N-connection emulation.
28 } // namespace 27 } // namespace
29 28
30 TcpCubicSender::TcpCubicSender(const QuicClock* clock, 29 TcpCubicBytesSender::TcpCubicBytesSender(
31 const RttStats* rtt_stats, 30 const QuicClock* clock,
32 bool reno, 31 const RttStats* rtt_stats,
33 QuicPacketCount initial_tcp_congestion_window, 32 bool reno,
34 QuicConnectionStats* stats) 33 QuicPacketCount initial_tcp_congestion_window,
34 QuicConnectionStats* stats)
35 : hybrid_slow_start_(clock), 35 : hybrid_slow_start_(clock),
36 cubic_(clock), 36 cubic_(clock),
37 rtt_stats_(rtt_stats), 37 rtt_stats_(rtt_stats),
38 stats_(stats), 38 stats_(stats),
39 reno_(reno), 39 reno_(reno),
40 num_connections_(kDefaultNumConnections), 40 num_connections_(kDefaultNumConnections),
41 num_acked_packets_(0), 41 num_acked_packets_(0),
42 largest_sent_sequence_number_(0), 42 largest_sent_sequence_number_(0),
43 largest_acked_sequence_number_(0), 43 largest_acked_sequence_number_(0),
44 largest_sent_at_last_cutback_(0), 44 largest_sent_at_last_cutback_(0),
45 congestion_window_(initial_tcp_congestion_window), 45 congestion_window_(initial_tcp_congestion_window * kMaxSegmentSize),
46 slowstart_threshold_(std::numeric_limits<uint64>::max()), 46 slowstart_threshold_(std::numeric_limits<uint64>::max()),
47 last_cutback_exited_slowstart_(false), 47 last_cutback_exited_slowstart_(false),
48 clock_(clock) { 48 clock_(clock) {
49 } 49 }
50 50
51 TcpCubicSender::~TcpCubicSender() { 51 TcpCubicBytesSender::~TcpCubicBytesSender() {
52 UMA_HISTOGRAM_COUNTS("Net.QuicSession.FinalTcpCwnd", congestion_window_);
53 } 52 }
54 53
55 void TcpCubicSender::SetFromConfig(const QuicConfig& config, 54 void TcpCubicBytesSender::SetFromConfig(const QuicConfig& config,
56 Perspective perspective, 55 Perspective perspective,
57 bool using_pacing) { 56 bool using_pacing) {
58 if (perspective == Perspective::IS_SERVER) { 57 if (perspective == Perspective::IS_SERVER) {
59 if (config.HasReceivedConnectionOptions() && 58 if (config.HasReceivedConnectionOptions() &&
60 ContainsQuicTag(config.ReceivedConnectionOptions(), kIW10)) { 59 ContainsQuicTag(config.ReceivedConnectionOptions(), kIW10)) {
61 // Initial window experiment. 60 // Initial window experiment.
62 congestion_window_ = 10; 61 congestion_window_ = 10 * kMaxSegmentSize;
63 } 62 }
64 if (using_pacing) { 63 if (using_pacing) {
65 // Disable the ack train mode in hystart when pacing is enabled, since it 64 // Disable the ack train mode in hystart when pacing is enabled, since it
66 // may be falsely triggered. 65 // may be falsely triggered.
67 hybrid_slow_start_.set_ack_train_detection(false); 66 hybrid_slow_start_.set_ack_train_detection(false);
68 } 67 }
69 } 68 }
70 } 69 }
71 70
72 bool TcpCubicSender::ResumeConnectionState( 71 bool TcpCubicBytesSender::ResumeConnectionState(
73 const CachedNetworkParameters& cached_network_params) { 72 const CachedNetworkParameters& cached_network_params) {
74 // If the previous bandwidth estimate is less than an hour old, store in 73 // If the previous bandwidth estimate is less than an hour old, store in
75 // preparation for doing bandwidth resumption. 74 // preparation for doing bandwidth resumption.
76 int64 seconds_since_estimate = 75 int64 seconds_since_estimate =
77 clock_->WallNow().ToUNIXSeconds() - cached_network_params.timestamp(); 76 clock_->WallNow().ToUNIXSeconds() - cached_network_params.timestamp();
78 if (seconds_since_estimate > kNumSecondsPerHour) { 77 if (seconds_since_estimate > kNumSecondsPerHour) {
79 return false; 78 return false;
80 } 79 }
81 80
82 QuicBandwidth bandwidth = QuicBandwidth::FromBytesPerSecond( 81 QuicBandwidth bandwidth = QuicBandwidth::FromBytesPerSecond(
83 cached_network_params.bandwidth_estimate_bytes_per_second()); 82 cached_network_params.bandwidth_estimate_bytes_per_second());
84 QuicTime::Delta rtt_ms = 83 QuicTime::Delta rtt_ms =
85 QuicTime::Delta::FromMilliseconds(cached_network_params.min_rtt_ms()); 84 QuicTime::Delta::FromMilliseconds(cached_network_params.min_rtt_ms());
86 85
87 // Make sure CWND is in appropriate range (in case of bad data). 86 // Make sure CWND is in appropriate range (in case of bad data).
88 QuicPacketCount new_congestion_window = 87 QuicByteCount new_congestion_window = bandwidth.ToBytesPerPeriod(rtt_ms);
89 bandwidth.ToBytesPerPeriod(rtt_ms) / kMaxPacketSize; 88 congestion_window_ =
90 congestion_window_ = max( 89 max(min(new_congestion_window,
91 min(new_congestion_window, kMaxCongestionWindowForBandwidthResumption), 90 kMaxCongestionWindowForBandwidthResumption * kMaxSegmentSize),
92 kMinCongestionWindowForBandwidthResumption); 91 kMinCongestionWindowForBandwidthResumption * kMaxSegmentSize);
93 92
94 // TODO(rjshade): Set appropriate CWND when previous connection was in slow 93 // TODO(rjshade): Set appropriate CWND when previous connection was in slow
95 // start at time of estimate. 94 // start at time of estimate.
96 return true; 95 return true;
97 } 96 }
98 97
99 void TcpCubicSender::SetNumEmulatedConnections(int num_connections) { 98 void TcpCubicBytesSender::SetNumEmulatedConnections(int num_connections) {
100 num_connections_ = max(1, num_connections); 99 num_connections_ = max(1, num_connections);
101 cubic_.SetNumConnections(num_connections_); 100 cubic_.SetNumConnections(num_connections_);
102 } 101 }
103 102
104 float TcpCubicSender::RenoBeta() const { 103 float TcpCubicBytesSender::RenoBeta() const {
105 // kNConnectionBeta is the backoff factor after loss for our N-connection 104 // kNConnectionBeta is the backoff factor after loss for our N-connection
106 // emulation, which emulates the effective backoff of an ensemble of N 105 // emulation, which emulates the effective backoff of an ensemble of N
107 // TCP-Reno connections on a single loss event. The effective multiplier is 106 // TCP-Reno connections on a single loss event. The effective multiplier is
108 // computed as: 107 // computed as:
109 return (num_connections_ - 1 + kRenoBeta) / num_connections_; 108 return (num_connections_ - 1 + kRenoBeta) / num_connections_;
110 } 109 }
111 110
112 void TcpCubicSender::OnCongestionEvent( 111 void TcpCubicBytesSender::OnCongestionEvent(
113 bool rtt_updated, 112 bool rtt_updated,
114 QuicByteCount bytes_in_flight, 113 QuicByteCount bytes_in_flight,
115 const CongestionVector& acked_packets, 114 const CongestionVector& acked_packets,
116 const CongestionVector& lost_packets) { 115 const CongestionVector& lost_packets) {
117 if (rtt_updated && InSlowStart() && 116 if (rtt_updated && InSlowStart() &&
118 hybrid_slow_start_.ShouldExitSlowStart(rtt_stats_->latest_rtt(), 117 hybrid_slow_start_.ShouldExitSlowStart(
119 rtt_stats_->min_rtt(), 118 rtt_stats_->latest_rtt(), rtt_stats_->min_rtt(),
120 congestion_window_)) { 119 congestion_window_ / kMaxSegmentSize)) {
121 slowstart_threshold_ = congestion_window_; 120 slowstart_threshold_ = congestion_window_;
122 } 121 }
123 for (CongestionVector::const_iterator it = lost_packets.begin(); 122 for (CongestionVector::const_iterator it = lost_packets.begin();
124 it != lost_packets.end(); ++it) { 123 it != lost_packets.end(); ++it) {
125 OnPacketLost(it->first, bytes_in_flight); 124 OnPacketLost(it->first, bytes_in_flight);
126 } 125 }
127 for (CongestionVector::const_iterator it = acked_packets.begin(); 126 for (CongestionVector::const_iterator it = acked_packets.begin();
128 it != acked_packets.end(); ++it) { 127 it != acked_packets.end(); ++it) {
129 OnPacketAcked(it->first, it->second.bytes_sent, bytes_in_flight); 128 OnPacketAcked(it->first, it->second.bytes_sent, bytes_in_flight);
130 } 129 }
131 } 130 }
132 131
133 void TcpCubicSender::OnPacketAcked( 132 void TcpCubicBytesSender::OnPacketAcked(
134 QuicPacketSequenceNumber acked_sequence_number, 133 QuicPacketSequenceNumber acked_sequence_number,
135 QuicByteCount acked_bytes, 134 QuicByteCount acked_bytes,
136 QuicByteCount bytes_in_flight) { 135 QuicByteCount bytes_in_flight) {
137 largest_acked_sequence_number_ = max(acked_sequence_number, 136 largest_acked_sequence_number_ =
138 largest_acked_sequence_number_); 137 max(acked_sequence_number, largest_acked_sequence_number_);
139 if (InRecovery()) { 138 if (InRecovery()) {
140 // PRR is used when in recovery. 139 // PRR is used when in recovery.
141 prr_.OnPacketAcked(acked_bytes); 140 prr_.OnPacketAcked(acked_bytes);
142 return; 141 return;
143 } 142 }
144 MaybeIncreaseCwnd(acked_sequence_number, bytes_in_flight); 143 MaybeIncreaseCwnd(acked_sequence_number, acked_bytes, bytes_in_flight);
145 // TODO(ianswett): Should this even be called when not in slow start? 144 // TODO(ianswett): Should this even be called when not in slow start?
146 hybrid_slow_start_.OnPacketAcked(acked_sequence_number, InSlowStart()); 145 hybrid_slow_start_.OnPacketAcked(acked_sequence_number, InSlowStart());
147 } 146 }
148 147
149 void TcpCubicSender::OnPacketLost(QuicPacketSequenceNumber sequence_number, 148 void TcpCubicBytesSender::OnPacketLost(QuicPacketSequenceNumber sequence_number,
150 QuicByteCount bytes_in_flight) { 149 QuicByteCount bytes_in_flight) {
151 // TCP NewReno (RFC6582) says that once a loss occurs, any losses in packets 150 // TCP NewReno (RFC6582) says that once a loss occurs, any losses in packets
152 // already sent should be treated as a single loss event, since it's expected. 151 // already sent should be treated as a single loss event, since it's expected.
153 if (sequence_number <= largest_sent_at_last_cutback_) { 152 if (sequence_number <= largest_sent_at_last_cutback_) {
154 if (last_cutback_exited_slowstart_) { 153 if (last_cutback_exited_slowstart_) {
155 ++stats_->slowstart_packets_lost; 154 ++stats_->slowstart_packets_lost;
156 } 155 }
157 DVLOG(1) << "Ignoring loss for largest_missing:" << sequence_number 156 DVLOG(1) << "Ignoring loss for largest_missing:" << sequence_number
158 << " because it was sent prior to the last CWND cutback."; 157 << " because it was sent prior to the last CWND cutback.";
159 return; 158 return;
160 } 159 }
(...skipping 10 matching lines...) Expand all
171 } else { 170 } else {
172 congestion_window_ = 171 congestion_window_ =
173 cubic_.CongestionWindowAfterPacketLoss(congestion_window_); 172 cubic_.CongestionWindowAfterPacketLoss(congestion_window_);
174 } 173 }
175 slowstart_threshold_ = congestion_window_; 174 slowstart_threshold_ = congestion_window_;
176 // Enforce TCP's minimum congestion window of 2*MSS. 175 // Enforce TCP's minimum congestion window of 2*MSS.
177 if (congestion_window_ < kMinimumCongestionWindow) { 176 if (congestion_window_ < kMinimumCongestionWindow) {
178 congestion_window_ = kMinimumCongestionWindow; 177 congestion_window_ = kMinimumCongestionWindow;
179 } 178 }
180 largest_sent_at_last_cutback_ = largest_sent_sequence_number_; 179 largest_sent_at_last_cutback_ = largest_sent_sequence_number_;
181 // reset packet count from congestion avoidance mode. We start 180 // Reset packet count from congestion avoidance mode. We start counting again
182 // counting again when we're out of recovery. 181 // when we're out of recovery.
183 num_acked_packets_ = 0; 182 num_acked_packets_ = 0;
184 DVLOG(1) << "Incoming loss; congestion window: " << congestion_window_ 183 DVLOG(1) << "Incoming loss; congestion window: " << congestion_window_
185 << " slowstart threshold: " << slowstart_threshold_; 184 << " slowstart threshold: " << slowstart_threshold_;
186 } 185 }
187 186
188 bool TcpCubicSender::OnPacketSent(QuicTime /*sent_time*/, 187 bool TcpCubicBytesSender::OnPacketSent(
189 QuicByteCount /*bytes_in_flight*/, 188 QuicTime /*sent_time*/,
190 QuicPacketSequenceNumber sequence_number, 189 QuicByteCount /*bytes_in_flight*/,
191 QuicByteCount bytes, 190 QuicPacketSequenceNumber sequence_number,
192 HasRetransmittableData is_retransmittable) { 191 QuicByteCount bytes,
192 HasRetransmittableData is_retransmittable) {
193 // Only update bytes_in_flight_ for data packets. 193 // Only update bytes_in_flight_ for data packets.
194 if (is_retransmittable != HAS_RETRANSMITTABLE_DATA) { 194 if (is_retransmittable != HAS_RETRANSMITTABLE_DATA) {
195 return false; 195 return false;
196 } 196 }
197 if (InRecovery()) { 197 if (InRecovery()) {
198 // PRR is used when in recovery. 198 // PRR is used when in recovery.
199 prr_.OnPacketSent(bytes); 199 prr_.OnPacketSent(bytes);
200 } 200 }
201 DCHECK_LT(largest_sent_sequence_number_, sequence_number); 201 DCHECK_LT(largest_sent_sequence_number_, sequence_number);
202 largest_sent_sequence_number_ = sequence_number; 202 largest_sent_sequence_number_ = sequence_number;
203 hybrid_slow_start_.OnPacketSent(sequence_number); 203 hybrid_slow_start_.OnPacketSent(sequence_number);
204 return true; 204 return true;
205 } 205 }
206 206
207 QuicTime::Delta TcpCubicSender::TimeUntilSend( 207 QuicTime::Delta TcpCubicBytesSender::TimeUntilSend(
208 QuicTime /* now */, 208 QuicTime /* now */,
209 QuicByteCount bytes_in_flight, 209 QuicByteCount bytes_in_flight,
210 HasRetransmittableData has_retransmittable_data) const { 210 HasRetransmittableData has_retransmittable_data) const {
211 if (has_retransmittable_data == NO_RETRANSMITTABLE_DATA) { 211 if (has_retransmittable_data == NO_RETRANSMITTABLE_DATA) {
212 // For TCP we can always send an ACK immediately. 212 // For TCP we can always send an ACK immediately.
213 return QuicTime::Delta::Zero(); 213 return QuicTime::Delta::Zero();
214 } 214 }
215 if (InRecovery()) { 215 if (InRecovery()) {
216 // PRR is used when in recovery. 216 // PRR is used when in recovery.
217 return prr_.TimeUntilSend(GetCongestionWindow(), bytes_in_flight, 217 return prr_.TimeUntilSend(GetCongestionWindow(), bytes_in_flight,
218 slowstart_threshold_ * kMaxSegmentSize); 218 slowstart_threshold_);
219 } 219 }
220 if (GetCongestionWindow() > bytes_in_flight) { 220 if (GetCongestionWindow() > bytes_in_flight) {
221 return QuicTime::Delta::Zero(); 221 return QuicTime::Delta::Zero();
222 } 222 }
223 return QuicTime::Delta::Infinite(); 223 return QuicTime::Delta::Infinite();
224 } 224 }
225 225
226 QuicBandwidth TcpCubicSender::PacingRate() const { 226 QuicBandwidth TcpCubicBytesSender::PacingRate() const {
227 // We pace at twice the rate of the underlying sender's bandwidth estimate 227 // We pace at twice the rate of the underlying sender's bandwidth estimate
228 // during slow start and 1.25x during congestion avoidance to ensure pacing 228 // during slow start and 1.25x during congestion avoidance to ensure pacing
229 // doesn't prevent us from filling the window. 229 // doesn't prevent us from filling the window.
230 QuicTime::Delta srtt = rtt_stats_->smoothed_rtt(); 230 QuicTime::Delta srtt = rtt_stats_->smoothed_rtt();
231 if (srtt.IsZero()) { 231 if (srtt.IsZero()) {
232 srtt = QuicTime::Delta::FromMicroseconds(rtt_stats_->initial_rtt_us()); 232 srtt = QuicTime::Delta::FromMicroseconds(rtt_stats_->initial_rtt_us());
233 } 233 }
234 const QuicBandwidth bandwidth = 234 const QuicBandwidth bandwidth =
235 QuicBandwidth::FromBytesAndTimeDelta(GetCongestionWindow(), srtt); 235 QuicBandwidth::FromBytesAndTimeDelta(GetCongestionWindow(), srtt);
236 return bandwidth.Scale(InSlowStart() ? 2 : 1.25); 236 return bandwidth.Scale(InSlowStart() ? 2 : 1.25);
237 } 237 }
238 238
239 QuicBandwidth TcpCubicSender::BandwidthEstimate() const { 239 QuicBandwidth TcpCubicBytesSender::BandwidthEstimate() const {
240 QuicTime::Delta srtt = rtt_stats_->smoothed_rtt(); 240 QuicTime::Delta srtt = rtt_stats_->smoothed_rtt();
241 if (srtt.IsZero()) { 241 if (srtt.IsZero()) {
242 // If we haven't measured an rtt, the bandwidth estimate is unknown. 242 // If we haven't measured an rtt, the bandwidth estimate is unknown.
243 return QuicBandwidth::Zero(); 243 return QuicBandwidth::Zero();
244 } 244 }
245 return QuicBandwidth::FromBytesAndTimeDelta(GetCongestionWindow(), srtt); 245 return QuicBandwidth::FromBytesAndTimeDelta(GetCongestionWindow(), srtt);
246 } 246 }
247 247
248 bool TcpCubicSender::HasReliableBandwidthEstimate() const { 248 bool TcpCubicBytesSender::HasReliableBandwidthEstimate() const {
249 return !InSlowStart() && !InRecovery() && 249 return !InSlowStart() && !InRecovery() &&
250 !rtt_stats_->smoothed_rtt().IsZero();; 250 !rtt_stats_->smoothed_rtt().IsZero();
251 } 251 }
252 252
253 QuicTime::Delta TcpCubicSender::RetransmissionDelay() const { 253 QuicTime::Delta TcpCubicBytesSender::RetransmissionDelay() const {
254 if (rtt_stats_->smoothed_rtt().IsZero()) { 254 if (rtt_stats_->smoothed_rtt().IsZero()) {
255 return QuicTime::Delta::Zero(); 255 return QuicTime::Delta::Zero();
256 } 256 }
257 return rtt_stats_->smoothed_rtt().Add( 257 return rtt_stats_->smoothed_rtt().Add(
258 rtt_stats_->mean_deviation().Multiply(4)); 258 rtt_stats_->mean_deviation().Multiply(4));
259 } 259 }
260 260
261 QuicByteCount TcpCubicSender::GetCongestionWindow() const { 261 QuicByteCount TcpCubicBytesSender::GetCongestionWindow() const {
262 return congestion_window_ * kMaxSegmentSize; 262 return congestion_window_;
263 } 263 }
264 264
265 bool TcpCubicSender::InSlowStart() const { 265 bool TcpCubicBytesSender::InSlowStart() const {
266 return congestion_window_ < slowstart_threshold_; 266 return congestion_window_ < slowstart_threshold_;
267 } 267 }
268 268
269 QuicByteCount TcpCubicSender::GetSlowStartThreshold() const { 269 QuicByteCount TcpCubicBytesSender::GetSlowStartThreshold() const {
270 return slowstart_threshold_ * kMaxSegmentSize; 270 return slowstart_threshold_;
271 } 271 }
272 272
273 bool TcpCubicSender::IsCwndLimited(QuicByteCount bytes_in_flight) const { 273 bool TcpCubicBytesSender::IsCwndLimited(QuicByteCount bytes_in_flight) const {
274 const QuicByteCount congestion_window_bytes = congestion_window_ * 274 if (bytes_in_flight >= congestion_window_) {
275 kMaxSegmentSize;
276 if (bytes_in_flight >= congestion_window_bytes) {
277 return true; 275 return true;
278 } 276 }
279 const QuicByteCount max_burst = kMaxBurstLength * kMaxSegmentSize; 277 const QuicByteCount max_burst = kMaxBurstLength * kMaxSegmentSize;
280 const QuicByteCount available_bytes = 278 const QuicByteCount available_bytes = congestion_window_ - bytes_in_flight;
281 congestion_window_bytes - bytes_in_flight; 279 const bool slow_start_limited =
282 const bool slow_start_limited = InSlowStart() && 280 InSlowStart() && bytes_in_flight > congestion_window_ / 2;
283 bytes_in_flight > congestion_window_bytes / 2;
284 return slow_start_limited || available_bytes <= max_burst; 281 return slow_start_limited || available_bytes <= max_burst;
285 } 282 }
286 283
287 bool TcpCubicSender::InRecovery() const { 284 bool TcpCubicBytesSender::InRecovery() const {
288 return largest_acked_sequence_number_ <= largest_sent_at_last_cutback_ && 285 return largest_acked_sequence_number_ <= largest_sent_at_last_cutback_ &&
289 largest_acked_sequence_number_ != 0; 286 largest_acked_sequence_number_ != 0;
290 } 287 }
291 288
292 // Called when we receive an ack. Normal TCP tracks how many packets one ack 289 // Called when we receive an ack. Normal TCP tracks how many packets one ack
293 // represents, but quic has a separate ack for each packet. 290 // represents, but quic has a separate ack for each packet.
294 void TcpCubicSender::MaybeIncreaseCwnd( 291 void TcpCubicBytesSender::MaybeIncreaseCwnd(
295 QuicPacketSequenceNumber acked_sequence_number, 292 QuicPacketSequenceNumber acked_sequence_number,
293 QuicByteCount acked_bytes,
296 QuicByteCount bytes_in_flight) { 294 QuicByteCount bytes_in_flight) {
297 LOG_IF(DFATAL, InRecovery()) << "Never increase the CWND during recovery."; 295 LOG_IF(DFATAL, InRecovery()) << "Never increase the CWND during recovery.";
298 if (!IsCwndLimited(bytes_in_flight)) { 296 if (!IsCwndLimited(bytes_in_flight)) {
299 // We don't update the congestion window unless we are close to using the 297 // We don't update the congestion window unless we are close to using the
300 // window we have available. 298 // window we have available.
301 return; 299 return;
302 } 300 }
303 if (InSlowStart()) { 301 if (InSlowStart()) {
304 // TCP slow start, exponential growth, increase by one for each ACK. 302 // TCP slow start, exponential growth, increase by one for each ACK.
305 ++congestion_window_; 303 congestion_window_ += kMaxSegmentSize;
306 DVLOG(1) << "Slow start; congestion window: " << congestion_window_ 304 DVLOG(1) << "Slow start; congestion window: " << congestion_window_
307 << " slowstart threshold: " << slowstart_threshold_; 305 << " slowstart threshold: " << slowstart_threshold_;
308 return; 306 return;
309 } 307 }
310 // Congestion avoidance 308 // Congestion avoidance.
311 if (reno_) { 309 if (reno_) {
312 // Classic Reno congestion avoidance. 310 // Classic Reno congestion avoidance.
313 ++num_acked_packets_; 311 ++num_acked_packets_;
314 // Divide by num_connections to smoothly increase the CWND at a faster 312 // Divide by num_connections to smoothly increase the CWND at a faster rate
315 // rate than conventional Reno. 313 // than conventional Reno.
316 if (num_acked_packets_ * num_connections_ >= congestion_window_) { 314 if (num_acked_packets_ * num_connections_ >=
317 ++congestion_window_; 315 congestion_window_ / kMaxSegmentSize) {
316 congestion_window_ += kMaxSegmentSize;
318 num_acked_packets_ = 0; 317 num_acked_packets_ = 0;
319 } 318 }
320 319
321 DVLOG(1) << "Reno; congestion window: " << congestion_window_ 320 DVLOG(1) << "Reno; congestion window: " << congestion_window_
322 << " slowstart threshold: " << slowstart_threshold_ 321 << " slowstart threshold: " << slowstart_threshold_
323 << " congestion window count: " << num_acked_packets_; 322 << " congestion window count: " << num_acked_packets_;
324 } else { 323 } else {
325 congestion_window_ = cubic_.CongestionWindowAfterAck(congestion_window_, 324 congestion_window_ = cubic_.CongestionWindowAfterAck(
326 rtt_stats_->min_rtt()); 325 acked_bytes, congestion_window_, rtt_stats_->min_rtt());
327 DVLOG(1) << "Cubic; congestion window: " << congestion_window_ 326 DVLOG(1) << "Cubic; congestion window: " << congestion_window_
328 << " slowstart threshold: " << slowstart_threshold_; 327 << " slowstart threshold: " << slowstart_threshold_;
329 } 328 }
330 } 329 }
331 330
332 void TcpCubicSender::OnRetransmissionTimeout(bool packets_retransmitted) { 331 void TcpCubicBytesSender::OnRetransmissionTimeout(bool packets_retransmitted) {
333 largest_sent_at_last_cutback_ = 0; 332 largest_sent_at_last_cutback_ = 0;
334 if (!packets_retransmitted) { 333 if (!packets_retransmitted) {
335 return; 334 return;
336 } 335 }
337 cubic_.Reset(); 336 cubic_.Reset();
338 hybrid_slow_start_.Restart(); 337 hybrid_slow_start_.Restart();
339 slowstart_threshold_ = congestion_window_ / 2; 338 slowstart_threshold_ = congestion_window_ / 2;
340 congestion_window_ = kMinimumCongestionWindow; 339 congestion_window_ = kMinimumCongestionWindow;
341 } 340 }
342 341
343 CongestionControlType TcpCubicSender::GetCongestionControlType() const { 342 CongestionControlType TcpCubicBytesSender::GetCongestionControlType() const {
344 return reno_ ? kReno : kCubic; 343 return reno_ ? kReno : kCubic;
345 } 344 }
346 345
347 } // namespace net 346 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/congestion_control/tcp_cubic_bytes_sender.h ('k') | net/quic/congestion_control/tcp_cubic_bytes_sender_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698