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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 } | 91 } |
92 } | 92 } |
93 | 93 |
94 void TcpCubicSender::OnCongestionEvent( | 94 void TcpCubicSender::OnCongestionEvent( |
95 bool rtt_updated, | 95 bool rtt_updated, |
96 QuicByteCount bytes_in_flight, | 96 QuicByteCount bytes_in_flight, |
97 const CongestionVector& acked_packets, | 97 const CongestionVector& acked_packets, |
98 const CongestionVector& lost_packets) { | 98 const CongestionVector& lost_packets) { |
99 if (rtt_updated && InSlowStart() && | 99 if (rtt_updated && InSlowStart() && |
100 hybrid_slow_start_.ShouldExitSlowStart(rtt_stats_->latest_rtt(), | 100 hybrid_slow_start_.ShouldExitSlowStart(rtt_stats_->latest_rtt(), |
101 rtt_stats_->min_rtt(), | 101 rtt_stats_->MinRtt(), |
102 congestion_window_)) { | 102 congestion_window_)) { |
103 slowstart_threshold_ = congestion_window_; | 103 slowstart_threshold_ = congestion_window_; |
104 } | 104 } |
105 for (CongestionVector::const_iterator it = lost_packets.begin(); | 105 for (CongestionVector::const_iterator it = lost_packets.begin(); |
106 it != lost_packets.end(); ++it) { | 106 it != lost_packets.end(); ++it) { |
107 OnPacketLost(it->first, bytes_in_flight); | 107 OnPacketLost(it->first, bytes_in_flight); |
108 } | 108 } |
109 for (CongestionVector::const_iterator it = acked_packets.begin(); | 109 for (CongestionVector::const_iterator it = acked_packets.begin(); |
110 it != acked_packets.end(); ++it) { | 110 it != acked_packets.end(); ++it) { |
111 OnPacketAcked(it->first, it->second.bytes_sent, bytes_in_flight); | 111 OnPacketAcked(it->first, it->second.bytes_sent, bytes_in_flight); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 return QuicTime::Delta::Zero(); | 197 return QuicTime::Delta::Zero(); |
198 } | 198 } |
199 return QuicTime::Delta::Infinite(); | 199 return QuicTime::Delta::Infinite(); |
200 } | 200 } |
201 | 201 |
202 QuicByteCount TcpCubicSender::SendWindow() const { | 202 QuicByteCount TcpCubicSender::SendWindow() const { |
203 // What's the current send window in bytes. | 203 // What's the current send window in bytes. |
204 return min(receive_window_, GetCongestionWindow()); | 204 return min(receive_window_, GetCongestionWindow()); |
205 } | 205 } |
206 | 206 |
| 207 QuicBandwidth TcpCubicSender::PacingRate() const { |
| 208 // 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 |
| 210 // doesn't prevent us from filling the window. |
| 211 return BandwidthEstimate().Scale(InSlowStart() ? 2 : 1.25); |
| 212 } |
| 213 |
207 QuicBandwidth TcpCubicSender::BandwidthEstimate() const { | 214 QuicBandwidth TcpCubicSender::BandwidthEstimate() const { |
| 215 if (rtt_stats_->SmoothedRtt().IsZero()) { |
| 216 LOG(DFATAL) << "In BandwidthEstimate(), smoothed RTT is zero!"; |
| 217 return QuicBandwidth::Zero(); |
| 218 } |
208 return QuicBandwidth::FromBytesAndTimeDelta(GetCongestionWindow(), | 219 return QuicBandwidth::FromBytesAndTimeDelta(GetCongestionWindow(), |
209 rtt_stats_->SmoothedRtt()); | 220 rtt_stats_->SmoothedRtt()); |
210 } | 221 } |
211 | 222 |
212 bool TcpCubicSender::HasReliableBandwidthEstimate() const { | 223 bool TcpCubicSender::HasReliableBandwidthEstimate() const { |
213 return !InSlowStart() && !InRecovery(); | 224 return !InSlowStart() && !InRecovery(); |
214 } | 225 } |
215 | 226 |
216 QuicTime::Delta TcpCubicSender::RetransmissionDelay() const { | 227 QuicTime::Delta TcpCubicSender::RetransmissionDelay() const { |
217 if (!rtt_stats_->HasUpdates()) { | 228 if (!rtt_stats_->HasUpdates()) { |
218 return QuicTime::Delta::Zero(); | 229 return QuicTime::Delta::Zero(); |
219 } | 230 } |
220 return QuicTime::Delta::FromMicroseconds( | 231 return rtt_stats_->SmoothedRtt().Add( |
221 rtt_stats_->SmoothedRtt().ToMicroseconds() + | 232 rtt_stats_->mean_deviation().Multiply(4)); |
222 4 * rtt_stats_->mean_deviation().ToMicroseconds()); | |
223 } | 233 } |
224 | 234 |
225 QuicByteCount TcpCubicSender::GetCongestionWindow() const { | 235 QuicByteCount TcpCubicSender::GetCongestionWindow() const { |
226 return congestion_window_ * kMaxSegmentSize; | 236 return congestion_window_ * kMaxSegmentSize; |
227 } | 237 } |
228 | 238 |
229 bool TcpCubicSender::InSlowStart() const { | 239 bool TcpCubicSender::InSlowStart() const { |
230 return congestion_window_ < slowstart_threshold_; | 240 return congestion_window_ < slowstart_threshold_; |
231 } | 241 } |
232 | 242 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 ++congestion_window_; | 297 ++congestion_window_; |
288 congestion_window_count_ = 0; | 298 congestion_window_count_ = 0; |
289 } | 299 } |
290 | 300 |
291 DVLOG(1) << "Reno; congestion window: " << congestion_window_ | 301 DVLOG(1) << "Reno; congestion window: " << congestion_window_ |
292 << " slowstart threshold: " << slowstart_threshold_ | 302 << " slowstart threshold: " << slowstart_threshold_ |
293 << " congestion window count: " << congestion_window_count_; | 303 << " congestion window count: " << congestion_window_count_; |
294 } else { | 304 } else { |
295 congestion_window_ = min(max_tcp_congestion_window_, | 305 congestion_window_ = min(max_tcp_congestion_window_, |
296 cubic_.CongestionWindowAfterAck( | 306 cubic_.CongestionWindowAfterAck( |
297 congestion_window_, rtt_stats_->min_rtt())); | 307 congestion_window_, rtt_stats_->MinRtt())); |
298 DVLOG(1) << "Cubic; congestion window: " << congestion_window_ | 308 DVLOG(1) << "Cubic; congestion window: " << congestion_window_ |
299 << " slowstart threshold: " << slowstart_threshold_; | 309 << " slowstart threshold: " << slowstart_threshold_; |
300 } | 310 } |
301 } | 311 } |
302 | 312 |
303 void TcpCubicSender::OnRetransmissionTimeout(bool packets_retransmitted) { | 313 void TcpCubicSender::OnRetransmissionTimeout(bool packets_retransmitted) { |
304 largest_sent_at_last_cutback_ = 0; | 314 largest_sent_at_last_cutback_ = 0; |
305 if (!packets_retransmitted) { | 315 if (!packets_retransmitted) { |
306 return; | 316 return; |
307 } | 317 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 return QuicTime::Delta::Zero(); | 371 return QuicTime::Delta::Zero(); |
362 } | 372 } |
363 return QuicTime::Delta::Infinite(); | 373 return QuicTime::Delta::Infinite(); |
364 } | 374 } |
365 | 375 |
366 CongestionControlType TcpCubicSender::GetCongestionControlType() const { | 376 CongestionControlType TcpCubicSender::GetCongestionControlType() const { |
367 return reno_ ? kReno : kCubic; | 377 return reno_ ? kReno : kCubic; |
368 } | 378 } |
369 | 379 |
370 } // namespace net | 380 } // namespace net |
OLD | NEW |