| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/pacing_sender.h" | 5 #include "net/quic/congestion_control/pacing_sender.h" |
| 6 | 6 |
| 7 namespace net { | 7 namespace net { |
| 8 | 8 |
| 9 PacingSender::PacingSender(SendAlgorithmInterface* sender, | 9 PacingSender::PacingSender(SendAlgorithmInterface* sender, |
| 10 QuicTime::Delta alarm_granularity, | 10 QuicTime::Delta alarm_granularity, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 feedback, feedback_receive_time); | 34 feedback, feedback_receive_time); |
| 35 } | 35 } |
| 36 | 36 |
| 37 void PacingSender::OnCongestionEvent(bool rtt_updated, | 37 void PacingSender::OnCongestionEvent(bool rtt_updated, |
| 38 QuicByteCount bytes_in_flight, | 38 QuicByteCount bytes_in_flight, |
| 39 const CongestionMap& acked_packets, | 39 const CongestionMap& acked_packets, |
| 40 const CongestionMap& lost_packets) { | 40 const CongestionMap& lost_packets) { |
| 41 if (rtt_updated) { | 41 if (rtt_updated) { |
| 42 has_valid_rtt_ = true; | 42 has_valid_rtt_ = true; |
| 43 } | 43 } |
| 44 if (bytes_in_flight == 0) { | |
| 45 // Add more burst tokens anytime the connection is entering quiescence. | |
| 46 burst_tokens_ = initial_packet_burst_; | |
| 47 } | |
| 48 sender_->OnCongestionEvent( | 44 sender_->OnCongestionEvent( |
| 49 rtt_updated, bytes_in_flight, acked_packets, lost_packets); | 45 rtt_updated, bytes_in_flight, acked_packets, lost_packets); |
| 50 } | 46 } |
| 51 | 47 |
| 52 bool PacingSender::OnPacketSent( | 48 bool PacingSender::OnPacketSent( |
| 53 QuicTime sent_time, | 49 QuicTime sent_time, |
| 54 QuicByteCount bytes_in_flight, | 50 QuicByteCount bytes_in_flight, |
| 55 QuicPacketSequenceNumber sequence_number, | 51 QuicPacketSequenceNumber sequence_number, |
| 56 QuicByteCount bytes, | 52 QuicByteCount bytes, |
| 57 HasRetransmittableData has_retransmittable_data) { | 53 HasRetransmittableData has_retransmittable_data) { |
| 58 // Only pace data packets once we have an updated RTT. | 54 // Only pace data packets once we have an updated RTT. |
| 59 const bool in_flight = | 55 const bool in_flight = |
| 60 sender_->OnPacketSent(sent_time, bytes_in_flight, sequence_number, | 56 sender_->OnPacketSent(sent_time, bytes_in_flight, sequence_number, |
| 61 bytes, has_retransmittable_data); | 57 bytes, has_retransmittable_data); |
| 62 if (has_retransmittable_data != HAS_RETRANSMITTABLE_DATA || !has_valid_rtt_) { | 58 if (has_retransmittable_data != HAS_RETRANSMITTABLE_DATA || !has_valid_rtt_) { |
| 63 return in_flight; | 59 return in_flight; |
| 64 } | 60 } |
| 65 if (burst_tokens_ > 0) { | 61 if (burst_tokens_ > 0) { |
| 66 --burst_tokens_; | 62 --burst_tokens_; |
| 67 was_last_send_delayed_ = false; | 63 was_last_send_delayed_ = false; |
| 68 last_delayed_packet_sent_time_ = QuicTime::Zero(); | 64 last_delayed_packet_sent_time_ = QuicTime::Zero(); |
| 69 next_packet_send_time_ = QuicTime::Zero(); | 65 next_packet_send_time_ = QuicTime::Zero(); |
| 70 return in_flight; | 66 return in_flight; |
| 71 } | 67 } |
| 72 // The next packet should be sent as soon as the current packets has | 68 // The next packet should be sent as soon as the current packets has |
| 73 // been transferred. We pace at twice the rate of the underlying | 69 // been transferred. We pace at twice the rate of the underlying |
| 74 // sender's bandwidth estimate to help ensure that pacing doesn't become | 70 // sender's bandwidth estimate during slow start and 1.25x during congestion |
| 75 // a bottleneck. | 71 // avoidance to ensure pacing doesn't prevent us from filling the window. |
| 76 const float kPacingAggression = 2; | 72 const float kPacingAggression = sender_->InSlowStart() ? 2 : 1.25; |
| 77 QuicTime::Delta delay = | 73 QuicTime::Delta delay = |
| 78 BandwidthEstimate().Scale(kPacingAggression).TransferTime(bytes); | 74 BandwidthEstimate().Scale(kPacingAggression).TransferTime(bytes); |
| 79 // If the last send was delayed, and the alarm took a long time to get | 75 // If the last send was delayed, and the alarm took a long time to get |
| 80 // invoked, allow the connection to make up for lost time. | 76 // invoked, allow the connection to make up for lost time. |
| 81 if (was_last_send_delayed_) { | 77 if (was_last_send_delayed_) { |
| 82 next_packet_send_time_ = next_packet_send_time_.Add(delay); | 78 next_packet_send_time_ = next_packet_send_time_.Add(delay); |
| 83 // The send was application limited if it takes longer than the | 79 // The send was application limited if it takes longer than the |
| 84 // pacing delay between sent packets. | 80 // pacing delay between sent packets. |
| 85 const bool application_limited = | 81 const bool application_limited = |
| 86 last_delayed_packet_sent_time_.IsInitialized() && | 82 last_delayed_packet_sent_time_.IsInitialized() && |
| (...skipping 27 matching lines...) Expand all Loading... |
| 114 QuicTime::Delta PacingSender::TimeUntilSend( | 110 QuicTime::Delta PacingSender::TimeUntilSend( |
| 115 QuicTime now, | 111 QuicTime now, |
| 116 QuicByteCount bytes_in_flight, | 112 QuicByteCount bytes_in_flight, |
| 117 HasRetransmittableData has_retransmittable_data) const { | 113 HasRetransmittableData has_retransmittable_data) const { |
| 118 QuicTime::Delta time_until_send = | 114 QuicTime::Delta time_until_send = |
| 119 sender_->TimeUntilSend(now, bytes_in_flight, has_retransmittable_data); | 115 sender_->TimeUntilSend(now, bytes_in_flight, has_retransmittable_data); |
| 120 if (!has_valid_rtt_) { | 116 if (!has_valid_rtt_) { |
| 121 // Don't pace if we don't have an updated RTT estimate. | 117 // Don't pace if we don't have an updated RTT estimate. |
| 122 return time_until_send; | 118 return time_until_send; |
| 123 } | 119 } |
| 120 if (bytes_in_flight == 0) { |
| 121 // Add more burst tokens anytime the connection is entering quiescence. |
| 122 burst_tokens_ = initial_packet_burst_; |
| 123 } |
| 124 if (burst_tokens_ > 0) { | 124 if (burst_tokens_ > 0) { |
| 125 // Don't pace if we have burst tokens available. | 125 // Don't pace if we have burst tokens available. |
| 126 return time_until_send; | 126 return time_until_send; |
| 127 } | 127 } |
| 128 | 128 |
| 129 if (!time_until_send.IsZero()) { | 129 if (!time_until_send.IsZero()) { |
| 130 DCHECK(time_until_send.IsInfinite()); | 130 DCHECK(time_until_send.IsInfinite()); |
| 131 // The underlying sender prevents sending. | 131 // The underlying sender prevents sending. |
| 132 return time_until_send; | 132 return time_until_send; |
| 133 } | 133 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 159 } | 159 } |
| 160 | 160 |
| 161 QuicTime::Delta PacingSender::RetransmissionDelay() const { | 161 QuicTime::Delta PacingSender::RetransmissionDelay() const { |
| 162 return sender_->RetransmissionDelay(); | 162 return sender_->RetransmissionDelay(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 QuicByteCount PacingSender::GetCongestionWindow() const { | 165 QuicByteCount PacingSender::GetCongestionWindow() const { |
| 166 return sender_->GetCongestionWindow(); | 166 return sender_->GetCongestionWindow(); |
| 167 } | 167 } |
| 168 | 168 |
| 169 bool PacingSender::InSlowStart() const { |
| 170 return sender_->InSlowStart(); |
| 171 } |
| 172 |
| 173 QuicByteCount PacingSender::GetSlowStartThreshold() const { |
| 174 return sender_->GetSlowStartThreshold(); |
| 175 } |
| 176 |
| 169 } // namespace net | 177 } // namespace net |
| OLD | NEW |