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

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

Issue 839143002: Roll Chrome into Mojo. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Rebase Created 5 years, 11 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) 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,
11 uint32 initial_packet_burst) 11 uint32 initial_packet_burst)
12 : sender_(sender), 12 : sender_(sender),
13 alarm_granularity_(alarm_granularity), 13 alarm_granularity_(alarm_granularity),
14 initial_packet_burst_(initial_packet_burst), 14 initial_packet_burst_(initial_packet_burst),
15 burst_tokens_(initial_packet_burst), 15 burst_tokens_(initial_packet_burst),
16 last_delayed_packet_sent_time_(QuicTime::Zero()), 16 last_delayed_packet_sent_time_(QuicTime::Zero()),
17 next_packet_send_time_(QuicTime::Zero()), 17 ideal_next_packet_send_time_(QuicTime::Zero()),
18 was_last_send_delayed_(false) { 18 was_last_send_delayed_(false) {
19 } 19 }
20 20
21 PacingSender::~PacingSender() {} 21 PacingSender::~PacingSender() {}
22 22
23 void PacingSender::SetFromConfig(const QuicConfig& config, 23 void PacingSender::SetFromConfig(const QuicConfig& config,
24 bool is_server, 24 bool is_server,
25 bool using_pacing) { 25 bool using_pacing) {
26 DCHECK(using_pacing); 26 DCHECK(using_pacing);
27 sender_->SetFromConfig(config, is_server, using_pacing); 27 sender_->SetFromConfig(config, is_server, using_pacing);
(...skipping 21 matching lines...) Expand all
49 QuicByteCount bytes_in_flight, 49 QuicByteCount bytes_in_flight,
50 QuicPacketSequenceNumber sequence_number, 50 QuicPacketSequenceNumber sequence_number,
51 QuicByteCount bytes, 51 QuicByteCount bytes,
52 HasRetransmittableData has_retransmittable_data) { 52 HasRetransmittableData has_retransmittable_data) {
53 const bool in_flight = 53 const bool in_flight =
54 sender_->OnPacketSent(sent_time, bytes_in_flight, sequence_number, 54 sender_->OnPacketSent(sent_time, bytes_in_flight, sequence_number,
55 bytes, has_retransmittable_data); 55 bytes, has_retransmittable_data);
56 if (has_retransmittable_data != HAS_RETRANSMITTABLE_DATA) { 56 if (has_retransmittable_data != HAS_RETRANSMITTABLE_DATA) {
57 return in_flight; 57 return in_flight;
58 } 58 }
59 if (bytes_in_flight == 0) {
60 // Add more burst tokens anytime the connection is leaving quiescence.
61 burst_tokens_ = initial_packet_burst_;
62 }
59 if (burst_tokens_ > 0) { 63 if (burst_tokens_ > 0) {
60 --burst_tokens_; 64 --burst_tokens_;
61 was_last_send_delayed_ = false; 65 was_last_send_delayed_ = false;
62 last_delayed_packet_sent_time_ = QuicTime::Zero(); 66 last_delayed_packet_sent_time_ = QuicTime::Zero();
63 next_packet_send_time_ = QuicTime::Zero(); 67 ideal_next_packet_send_time_ = QuicTime::Zero();
64 return in_flight; 68 return in_flight;
65 } 69 }
66 // The next packet should be sent as soon as the current packets has been 70 // The next packet should be sent as soon as the current packets has been
67 // transferred. 71 // transferred.
68 QuicTime::Delta delay = PacingRate().TransferTime(bytes); 72 QuicTime::Delta delay = PacingRate().TransferTime(bytes);
69 // If the last send was delayed, and the alarm took a long time to get 73 // If the last send was delayed, and the alarm took a long time to get
70 // invoked, allow the connection to make up for lost time. 74 // invoked, allow the connection to make up for lost time.
71 if (was_last_send_delayed_) { 75 if (was_last_send_delayed_) {
72 next_packet_send_time_ = next_packet_send_time_.Add(delay); 76 ideal_next_packet_send_time_ = ideal_next_packet_send_time_.Add(delay);
73 // The send was application limited if it takes longer than the 77 // The send was application limited if it takes longer than the
74 // pacing delay between sent packets. 78 // pacing delay between sent packets.
75 const bool application_limited = 79 const bool application_limited =
76 last_delayed_packet_sent_time_.IsInitialized() && 80 last_delayed_packet_sent_time_.IsInitialized() &&
77 sent_time > last_delayed_packet_sent_time_.Add(delay); 81 sent_time > last_delayed_packet_sent_time_.Add(delay);
78 const bool making_up_for_lost_time = next_packet_send_time_ <= sent_time; 82 const bool making_up_for_lost_time =
83 ideal_next_packet_send_time_ <= sent_time;
79 // As long as we're making up time and not application limited, 84 // As long as we're making up time and not application limited,
80 // continue to consider the packets delayed, allowing the packets to be 85 // continue to consider the packets delayed, allowing the packets to be
81 // sent immediately. 86 // sent immediately.
82 if (making_up_for_lost_time && !application_limited) { 87 if (making_up_for_lost_time && !application_limited) {
83 last_delayed_packet_sent_time_ = sent_time; 88 last_delayed_packet_sent_time_ = sent_time;
84 } else { 89 } else {
85 was_last_send_delayed_ = false; 90 was_last_send_delayed_ = false;
86 last_delayed_packet_sent_time_ = QuicTime::Zero(); 91 last_delayed_packet_sent_time_ = QuicTime::Zero();
87 } 92 }
88 } else { 93 } else {
89 next_packet_send_time_ = 94 ideal_next_packet_send_time_ = QuicTime::Max(
90 QuicTime::Max(next_packet_send_time_.Add(delay), 95 ideal_next_packet_send_time_.Add(delay), sent_time.Add(delay));
91 sent_time.Add(delay).Subtract(alarm_granularity_));
92 } 96 }
93 return in_flight; 97 return in_flight;
94 } 98 }
95 99
96 void PacingSender::OnRetransmissionTimeout(bool packets_retransmitted) { 100 void PacingSender::OnRetransmissionTimeout(bool packets_retransmitted) {
97 sender_->OnRetransmissionTimeout(packets_retransmitted); 101 sender_->OnRetransmissionTimeout(packets_retransmitted);
98 } 102 }
99 103
100 void PacingSender::RevertRetransmissionTimeout() { 104 void PacingSender::RevertRetransmissionTimeout() {
101 sender_->RevertRetransmissionTimeout(); 105 sender_->RevertRetransmissionTimeout();
102 } 106 }
103 107
104 QuicTime::Delta PacingSender::TimeUntilSend( 108 QuicTime::Delta PacingSender::TimeUntilSend(
105 QuicTime now, 109 QuicTime now,
106 QuicByteCount bytes_in_flight, 110 QuicByteCount bytes_in_flight,
107 HasRetransmittableData has_retransmittable_data) const { 111 HasRetransmittableData has_retransmittable_data) const {
108 QuicTime::Delta time_until_send = 112 QuicTime::Delta time_until_send =
109 sender_->TimeUntilSend(now, bytes_in_flight, has_retransmittable_data); 113 sender_->TimeUntilSend(now, bytes_in_flight, has_retransmittable_data);
110 if (bytes_in_flight == 0) { 114 if (burst_tokens_ > 0 || bytes_in_flight == 0) {
111 // Add more burst tokens anytime the connection is entering quiescence. 115 // Don't pace if we have burst tokens available or leaving quiescence.
112 burst_tokens_ = initial_packet_burst_;
113 }
114 if (burst_tokens_ > 0) {
115 // Don't pace if we have burst tokens available.
116 return time_until_send; 116 return time_until_send;
117 } 117 }
118 118
119 if (!time_until_send.IsZero()) { 119 if (!time_until_send.IsZero()) {
120 DCHECK(time_until_send.IsInfinite()); 120 DCHECK(time_until_send.IsInfinite());
121 // The underlying sender prevents sending. 121 // The underlying sender prevents sending.
122 return time_until_send; 122 return time_until_send;
123 } 123 }
124 124
125 if (has_retransmittable_data == NO_RETRANSMITTABLE_DATA) { 125 if (has_retransmittable_data == NO_RETRANSMITTABLE_DATA) {
126 // Don't pace ACK packets, since they do not count against CWND and do not 126 // Don't pace ACK packets, since they do not count against CWND and do not
127 // cause CWND to grow. 127 // cause CWND to grow.
128 return QuicTime::Delta::Zero(); 128 return QuicTime::Delta::Zero();
129 } 129 }
130 130
131 // If the next send time is within the alarm granularity, send immediately. 131 // If the next send time is within the alarm granularity, send immediately.
132 // TODO(ianswett): This granularity logic ends up sending more packets than 132 if (ideal_next_packet_send_time_ > now.Add(alarm_granularity_)) {
133 // intended in an effort to make up for lost time that wasn't lost.
134 if (next_packet_send_time_ > now.Add(alarm_granularity_)) {
135 DVLOG(1) << "Delaying packet: " 133 DVLOG(1) << "Delaying packet: "
136 << next_packet_send_time_.Subtract(now).ToMicroseconds(); 134 << ideal_next_packet_send_time_.Subtract(now).ToMicroseconds();
137 was_last_send_delayed_ = true; 135 was_last_send_delayed_ = true;
138 return next_packet_send_time_.Subtract(now); 136 return ideal_next_packet_send_time_.Subtract(now);
139 } 137 }
140 138
141 DVLOG(1) << "Sending packet now"; 139 DVLOG(1) << "Sending packet now";
142 return QuicTime::Delta::Zero(); 140 return QuicTime::Delta::Zero();
143 } 141 }
144 142
145 QuicBandwidth PacingSender::PacingRate() const { 143 QuicBandwidth PacingSender::PacingRate() const {
146 return sender_->PacingRate(); 144 return sender_->PacingRate();
147 } 145 }
148 146
(...skipping 23 matching lines...) Expand all
172 170
173 QuicByteCount PacingSender::GetSlowStartThreshold() const { 171 QuicByteCount PacingSender::GetSlowStartThreshold() const {
174 return sender_->GetSlowStartThreshold(); 172 return sender_->GetSlowStartThreshold();
175 } 173 }
176 174
177 CongestionControlType PacingSender::GetCongestionControlType() const { 175 CongestionControlType PacingSender::GetCongestionControlType() const {
178 return sender_->GetCongestionControlType(); 176 return sender_->GetCongestionControlType();
179 } 177 }
180 178
181 } // namespace net 179 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/congestion_control/pacing_sender.h ('k') | net/quic/congestion_control/pacing_sender_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698