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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 if (has_retransmittable_data != HAS_RETRANSMITTABLE_DATA) { | 55 if (has_retransmittable_data != HAS_RETRANSMITTABLE_DATA) { |
56 return in_flight; | 56 return in_flight; |
57 } | 57 } |
58 if (burst_tokens_ > 0) { | 58 if (burst_tokens_ > 0) { |
59 --burst_tokens_; | 59 --burst_tokens_; |
60 was_last_send_delayed_ = false; | 60 was_last_send_delayed_ = false; |
61 last_delayed_packet_sent_time_ = QuicTime::Zero(); | 61 last_delayed_packet_sent_time_ = QuicTime::Zero(); |
62 next_packet_send_time_ = QuicTime::Zero(); | 62 next_packet_send_time_ = QuicTime::Zero(); |
63 return in_flight; | 63 return in_flight; |
64 } | 64 } |
65 // The next packet should be sent as soon as the current packets has | 65 // The next packet should be sent as soon as the current packets has been |
66 // been transferred. We pace at twice the rate of the underlying | 66 // transferred. |
67 // sender's bandwidth estimate during slow start and 1.25x during congestion | 67 QuicTime::Delta delay = PacingRate().TransferTime(bytes); |
68 // avoidance to ensure pacing doesn't prevent us from filling the window. | |
69 const float kPacingAggression = sender_->InSlowStart() ? 2 : 1.25; | |
70 QuicTime::Delta delay = | |
71 BandwidthEstimate().Scale(kPacingAggression).TransferTime(bytes); | |
72 // If the last send was delayed, and the alarm took a long time to get | 68 // If the last send was delayed, and the alarm took a long time to get |
73 // invoked, allow the connection to make up for lost time. | 69 // invoked, allow the connection to make up for lost time. |
74 if (was_last_send_delayed_) { | 70 if (was_last_send_delayed_) { |
75 next_packet_send_time_ = next_packet_send_time_.Add(delay); | 71 next_packet_send_time_ = next_packet_send_time_.Add(delay); |
76 // The send was application limited if it takes longer than the | 72 // The send was application limited if it takes longer than the |
77 // pacing delay between sent packets. | 73 // pacing delay between sent packets. |
78 const bool application_limited = | 74 const bool application_limited = |
79 last_delayed_packet_sent_time_.IsInitialized() && | 75 last_delayed_packet_sent_time_.IsInitialized() && |
80 sent_time > last_delayed_packet_sent_time_.Add(delay); | 76 sent_time > last_delayed_packet_sent_time_.Add(delay); |
81 const bool making_up_for_lost_time = next_packet_send_time_ <= sent_time; | 77 const bool making_up_for_lost_time = next_packet_send_time_ <= sent_time; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 DVLOG(1) << "Delaying packet: " | 134 DVLOG(1) << "Delaying packet: " |
139 << next_packet_send_time_.Subtract(now).ToMicroseconds(); | 135 << next_packet_send_time_.Subtract(now).ToMicroseconds(); |
140 was_last_send_delayed_ = true; | 136 was_last_send_delayed_ = true; |
141 return next_packet_send_time_.Subtract(now); | 137 return next_packet_send_time_.Subtract(now); |
142 } | 138 } |
143 | 139 |
144 DVLOG(1) << "Sending packet now"; | 140 DVLOG(1) << "Sending packet now"; |
145 return QuicTime::Delta::Zero(); | 141 return QuicTime::Delta::Zero(); |
146 } | 142 } |
147 | 143 |
| 144 QuicBandwidth PacingSender::PacingRate() const { |
| 145 return sender_->PacingRate(); |
| 146 } |
| 147 |
148 QuicBandwidth PacingSender::BandwidthEstimate() const { | 148 QuicBandwidth PacingSender::BandwidthEstimate() const { |
149 return sender_->BandwidthEstimate(); | 149 return sender_->BandwidthEstimate(); |
150 } | 150 } |
151 | 151 |
152 bool PacingSender::HasReliableBandwidthEstimate() const { | 152 bool PacingSender::HasReliableBandwidthEstimate() const { |
153 return sender_->HasReliableBandwidthEstimate(); | 153 return sender_->HasReliableBandwidthEstimate(); |
154 } | 154 } |
155 | 155 |
156 QuicTime::Delta PacingSender::RetransmissionDelay() const { | 156 QuicTime::Delta PacingSender::RetransmissionDelay() const { |
157 return sender_->RetransmissionDelay(); | 157 return sender_->RetransmissionDelay(); |
(...skipping 13 matching lines...) Expand all Loading... |
171 | 171 |
172 QuicByteCount PacingSender::GetSlowStartThreshold() const { | 172 QuicByteCount PacingSender::GetSlowStartThreshold() const { |
173 return sender_->GetSlowStartThreshold(); | 173 return sender_->GetSlowStartThreshold(); |
174 } | 174 } |
175 | 175 |
176 CongestionControlType PacingSender::GetCongestionControlType() const { | 176 CongestionControlType PacingSender::GetCongestionControlType() const { |
177 return sender_->GetCongestionControlType(); | 177 return sender_->GetCongestionControlType(); |
178 } | 178 } |
179 | 179 |
180 } // namespace net | 180 } // namespace net |
OLD | NEW |