| 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/tcp_cubic_sender.h" | 5 #include "net/quic/congestion_control/tcp_cubic_sender.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "net/quic/congestion_control/rtt_stats.h" | 10 #include "net/quic/congestion_control/rtt_stats.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 bool reno, | 31 bool reno, |
| 32 QuicPacketCount max_tcp_congestion_window, | 32 QuicPacketCount max_tcp_congestion_window, |
| 33 QuicConnectionStats* stats) | 33 QuicConnectionStats* stats) |
| 34 : hybrid_slow_start_(clock), | 34 : hybrid_slow_start_(clock), |
| 35 cubic_(clock, stats), | 35 cubic_(clock, stats), |
| 36 rtt_stats_(rtt_stats), | 36 rtt_stats_(rtt_stats), |
| 37 stats_(stats), | 37 stats_(stats), |
| 38 reno_(reno), | 38 reno_(reno), |
| 39 num_connections_(2), | 39 num_connections_(2), |
| 40 congestion_window_count_(0), | 40 congestion_window_count_(0), |
| 41 receive_window_(kDefaultSocketReceiveBuffer), | |
| 42 prr_out_(0), | 41 prr_out_(0), |
| 43 prr_delivered_(0), | 42 prr_delivered_(0), |
| 44 ack_count_since_loss_(0), | 43 ack_count_since_loss_(0), |
| 45 bytes_in_flight_before_loss_(0), | 44 bytes_in_flight_before_loss_(0), |
| 46 largest_sent_sequence_number_(0), | 45 largest_sent_sequence_number_(0), |
| 47 largest_acked_sequence_number_(0), | 46 largest_acked_sequence_number_(0), |
| 48 largest_sent_at_last_cutback_(0), | 47 largest_sent_at_last_cutback_(0), |
| 49 congestion_window_(kInitialCongestionWindow), | 48 congestion_window_(kInitialCongestionWindow), |
| 50 previous_congestion_window_(0), | 49 previous_congestion_window_(0), |
| 51 slowstart_threshold_(max_tcp_congestion_window), | 50 slowstart_threshold_(max_tcp_congestion_window), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 65 // Initial window experiment. Ignore the initial congestion | 64 // Initial window experiment. Ignore the initial congestion |
| 66 // window suggested by the client and use the default ICWND of | 65 // window suggested by the client and use the default ICWND of |
| 67 // 10 instead. | 66 // 10 instead. |
| 68 congestion_window_ = kInitialCongestionWindow; | 67 congestion_window_ = kInitialCongestionWindow; |
| 69 } else if (config.HasReceivedInitialCongestionWindow()) { | 68 } else if (config.HasReceivedInitialCongestionWindow()) { |
| 70 // Set the initial window size. | 69 // Set the initial window size. |
| 71 congestion_window_ = min(kMaxInitialWindow, | 70 congestion_window_ = min(kMaxInitialWindow, |
| 72 config.ReceivedInitialCongestionWindow()); | 71 config.ReceivedInitialCongestionWindow()); |
| 73 } | 72 } |
| 74 } | 73 } |
| 75 if (config.HasReceivedSocketReceiveBuffer()) { | |
| 76 // Set the initial socket receive buffer size in bytes. | |
| 77 receive_window_ = config.ReceivedSocketReceiveBuffer(); | |
| 78 } | |
| 79 } | 74 } |
| 80 | 75 |
| 81 void TcpCubicSender::SetNumEmulatedConnections(int num_connections) { | 76 void TcpCubicSender::SetNumEmulatedConnections(int num_connections) { |
| 82 num_connections_ = max(1, num_connections); | 77 num_connections_ = max(1, num_connections); |
| 83 cubic_.SetNumConnections(num_connections_); | 78 cubic_.SetNumConnections(num_connections_); |
| 84 } | 79 } |
| 85 | 80 |
| 86 void TcpCubicSender::OnIncomingQuicCongestionFeedbackFrame( | |
| 87 const QuicCongestionFeedbackFrame& feedback, | |
| 88 QuicTime feedback_receive_time) { | |
| 89 if (feedback.type == kTCP) { | |
| 90 receive_window_ = feedback.tcp.receive_window; | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 void TcpCubicSender::OnCongestionEvent( | 81 void TcpCubicSender::OnCongestionEvent( |
| 95 bool rtt_updated, | 82 bool rtt_updated, |
| 96 QuicByteCount bytes_in_flight, | 83 QuicByteCount bytes_in_flight, |
| 97 const CongestionVector& acked_packets, | 84 const CongestionVector& acked_packets, |
| 98 const CongestionVector& lost_packets) { | 85 const CongestionVector& lost_packets) { |
| 99 if (rtt_updated && InSlowStart() && | 86 if (rtt_updated && InSlowStart() && |
| 100 hybrid_slow_start_.ShouldExitSlowStart(rtt_stats_->latest_rtt(), | 87 hybrid_slow_start_.ShouldExitSlowStart(rtt_stats_->latest_rtt(), |
| 101 rtt_stats_->MinRtt(), | 88 rtt_stats_->MinRtt(), |
| 102 congestion_window_)) { | 89 congestion_window_)) { |
| 103 slowstart_threshold_ = congestion_window_; | 90 slowstart_threshold_ = congestion_window_; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 QuicTime /* now */, | 173 QuicTime /* now */, |
| 187 QuicByteCount bytes_in_flight, | 174 QuicByteCount bytes_in_flight, |
| 188 HasRetransmittableData has_retransmittable_data) const { | 175 HasRetransmittableData has_retransmittable_data) const { |
| 189 if (has_retransmittable_data == NO_RETRANSMITTABLE_DATA) { | 176 if (has_retransmittable_data == NO_RETRANSMITTABLE_DATA) { |
| 190 // For TCP we can always send an ACK immediately. | 177 // For TCP we can always send an ACK immediately. |
| 191 return QuicTime::Delta::Zero(); | 178 return QuicTime::Delta::Zero(); |
| 192 } | 179 } |
| 193 if (InRecovery()) { | 180 if (InRecovery()) { |
| 194 return PrrTimeUntilSend(bytes_in_flight); | 181 return PrrTimeUntilSend(bytes_in_flight); |
| 195 } | 182 } |
| 196 if (SendWindow() > bytes_in_flight) { | 183 if (GetCongestionWindow() > bytes_in_flight) { |
| 197 return QuicTime::Delta::Zero(); | 184 return QuicTime::Delta::Zero(); |
| 198 } | 185 } |
| 199 return QuicTime::Delta::Infinite(); | 186 return QuicTime::Delta::Infinite(); |
| 200 } | 187 } |
| 201 | 188 |
| 202 QuicByteCount TcpCubicSender::SendWindow() const { | |
| 203 // What's the current send window in bytes. | |
| 204 return min(receive_window_, GetCongestionWindow()); | |
| 205 } | |
| 206 | |
| 207 QuicBandwidth TcpCubicSender::PacingRate() const { | 189 QuicBandwidth TcpCubicSender::PacingRate() const { |
| 208 // We pace at twice the rate of the underlying sender's bandwidth estimate | 190 // We pace at twice the rate of the underlying sender's bandwidth estimate |
| 209 // during slow start and 1.25x during congestion avoidance to ensure pacing | 191 // during slow start and 1.25x during congestion avoidance to ensure pacing |
| 210 // doesn't prevent us from filling the window. | 192 // doesn't prevent us from filling the window. |
| 211 return BandwidthEstimate().Scale(InSlowStart() ? 2 : 1.25); | 193 return BandwidthEstimate().Scale(InSlowStart() ? 2 : 1.25); |
| 212 } | 194 } |
| 213 | 195 |
| 214 QuicBandwidth TcpCubicSender::BandwidthEstimate() const { | 196 QuicBandwidth TcpCubicSender::BandwidthEstimate() const { |
| 215 if (rtt_stats_->SmoothedRtt().IsZero()) { | 197 if (rtt_stats_->SmoothedRtt().IsZero()) { |
| 216 LOG(DFATAL) << "In BandwidthEstimate(), smoothed RTT is zero!"; | 198 LOG(DFATAL) << "In BandwidthEstimate(), smoothed RTT is zero!"; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 ++ack_count_since_loss_; | 327 ++ack_count_since_loss_; |
| 346 } | 328 } |
| 347 | 329 |
| 348 QuicTime::Delta TcpCubicSender::PrrTimeUntilSend( | 330 QuicTime::Delta TcpCubicSender::PrrTimeUntilSend( |
| 349 QuicByteCount bytes_in_flight) const { | 331 QuicByteCount bytes_in_flight) const { |
| 350 DCHECK(InRecovery()); | 332 DCHECK(InRecovery()); |
| 351 // Return QuicTime::Zero In order to ensure limited transmit always works. | 333 // Return QuicTime::Zero In order to ensure limited transmit always works. |
| 352 if (prr_out_ == 0 || bytes_in_flight < kMaxSegmentSize) { | 334 if (prr_out_ == 0 || bytes_in_flight < kMaxSegmentSize) { |
| 353 return QuicTime::Delta::Zero(); | 335 return QuicTime::Delta::Zero(); |
| 354 } | 336 } |
| 355 if (SendWindow() > bytes_in_flight) { | 337 if (GetCongestionWindow() > bytes_in_flight) { |
| 356 // During PRR-SSRB, limit outgoing packets to 1 extra MSS per ack, instead | 338 // During PRR-SSRB, limit outgoing packets to 1 extra MSS per ack, instead |
| 357 // of sending the entire available window. This prevents burst retransmits | 339 // of sending the entire available window. This prevents burst retransmits |
| 358 // when more packets are lost than the CWND reduction. | 340 // when more packets are lost than the CWND reduction. |
| 359 // limit = MAX(prr_delivered - prr_out, DeliveredData) + MSS | 341 // limit = MAX(prr_delivered - prr_out, DeliveredData) + MSS |
| 360 if (prr_delivered_ + ack_count_since_loss_ * kMaxSegmentSize <= prr_out_) { | 342 if (prr_delivered_ + ack_count_since_loss_ * kMaxSegmentSize <= prr_out_) { |
| 361 return QuicTime::Delta::Infinite(); | 343 return QuicTime::Delta::Infinite(); |
| 362 } | 344 } |
| 363 return QuicTime::Delta::Zero(); | 345 return QuicTime::Delta::Zero(); |
| 364 } | 346 } |
| 365 // Implement Proportional Rate Reduction (RFC6937) | 347 // Implement Proportional Rate Reduction (RFC6937) |
| 366 // Checks a simplified version of the PRR formula that doesn't use division: | 348 // Checks a simplified version of the PRR formula that doesn't use division: |
| 367 // AvailableSendWindow = | 349 // AvailableSendWindow = |
| 368 // CEIL(prr_delivered * ssthresh / BytesInFlightAtLoss) - prr_sent | 350 // CEIL(prr_delivered * ssthresh / BytesInFlightAtLoss) - prr_sent |
| 369 if (prr_delivered_ * slowstart_threshold_ * kMaxSegmentSize > | 351 if (prr_delivered_ * slowstart_threshold_ * kMaxSegmentSize > |
| 370 prr_out_ * bytes_in_flight_before_loss_) { | 352 prr_out_ * bytes_in_flight_before_loss_) { |
| 371 return QuicTime::Delta::Zero(); | 353 return QuicTime::Delta::Zero(); |
| 372 } | 354 } |
| 373 return QuicTime::Delta::Infinite(); | 355 return QuicTime::Delta::Infinite(); |
| 374 } | 356 } |
| 375 | 357 |
| 376 CongestionControlType TcpCubicSender::GetCongestionControlType() const { | 358 CongestionControlType TcpCubicSender::GetCongestionControlType() const { |
| 377 return reno_ ? kReno : kCubic; | 359 return reno_ ? kReno : kCubic; |
| 378 } | 360 } |
| 379 | 361 |
| 380 } // namespace net | 362 } // namespace net |
| OLD | NEW |