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

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

Issue 2130103002: Landing Recent QUIC changes until 2016-07-02 02:45 UTC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/send_algorithm_simulator.h" 5 #include "net/quic/congestion_control/send_algorithm_simulator.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <limits> 9 #include <limits>
10 10
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 pending_transfers_.back().sender->RecordStats(); 91 pending_transfers_.back().sender->RecordStats();
92 } 92 }
93 93
94 void SendAlgorithmSimulator::TransferBytes() { 94 void SendAlgorithmSimulator::TransferBytes() {
95 TransferBytes(std::numeric_limits<uint64_t>::max(), 95 TransferBytes(std::numeric_limits<uint64_t>::max(),
96 QuicTime::Delta::Infinite()); 96 QuicTime::Delta::Infinite());
97 } 97 }
98 98
99 void SendAlgorithmSimulator::TransferBytes(QuicByteCount max_bytes, 99 void SendAlgorithmSimulator::TransferBytes(QuicByteCount max_bytes,
100 QuicTime::Delta max_time) { 100 QuicTime::Delta max_time) {
101 const QuicTime end_time = 101 const QuicTime end_time = max_time.IsInfinite()
102 max_time.IsInfinite() ? QuicTime::Zero().Add(QuicTime::Delta::Infinite()) 102 ? QuicTime::Zero() + QuicTime::Delta::Infinite()
103 : clock_->Now().Add(max_time); 103 : clock_->Now() + max_time;
104 QuicByteCount bytes_sent = 0; 104 QuicByteCount bytes_sent = 0;
105 while (!pending_transfers_.empty() && clock_->Now() < end_time && 105 while (!pending_transfers_.empty() && clock_->Now() < end_time &&
106 bytes_sent < max_bytes) { 106 bytes_sent < max_bytes) {
107 // Determine the times of next send and of the next ack arrival. 107 // Determine the times of next send and of the next ack arrival.
108 PacketEvent send_event = NextSendEvent(); 108 PacketEvent send_event = NextSendEvent();
109 PacketEvent ack_event = NextAckEvent(); 109 PacketEvent ack_event = NextAckEvent();
110 // If both times are infinite, fire a TLP. 110 // If both times are infinite, fire a TLP.
111 if (ack_event.time_delta.IsInfinite() && 111 if (ack_event.time_delta.IsInfinite() &&
112 send_event.time_delta.IsInfinite()) { 112 send_event.time_delta.IsInfinite()) {
113 DVLOG(1) << "Both times are infinite, simulating a TLP."; 113 DVLOG(1) << "Both times are infinite, simulating a TLP.";
(...skipping 24 matching lines...) Expand all
138 SendAlgorithmSimulator::PacketEvent SendAlgorithmSimulator::NextSendEvent() { 138 SendAlgorithmSimulator::PacketEvent SendAlgorithmSimulator::NextSendEvent() {
139 QuicTime::Delta next_send_time = QuicTime::Delta::Infinite(); 139 QuicTime::Delta next_send_time = QuicTime::Delta::Infinite();
140 Transfer* transfer = nullptr; 140 Transfer* transfer = nullptr;
141 for (vector<Transfer>::iterator it = pending_transfers_.begin(); 141 for (vector<Transfer>::iterator it = pending_transfers_.begin();
142 it != pending_transfers_.end(); ++it) { 142 it != pending_transfers_.end(); ++it) {
143 // If we've already sent enough bytes, wait for them to be acked. 143 // If we've already sent enough bytes, wait for them to be acked.
144 if (it->bytes_acked + it->bytes_in_flight >= it->num_bytes) { 144 if (it->bytes_acked + it->bytes_in_flight >= it->num_bytes) {
145 continue; 145 continue;
146 } 146 }
147 // If the flow hasn't started, use the start time. 147 // If the flow hasn't started, use the start time.
148 QuicTime::Delta transfer_send_time = it->start_time.Subtract(clock_->Now()); 148 QuicTime::Delta transfer_send_time = it->start_time - clock_->Now();
149 if (clock_->Now() >= it->start_time) { 149 if (clock_->Now() >= it->start_time) {
150 transfer_send_time = it->sender->send_algorithm->TimeUntilSend( 150 transfer_send_time = it->sender->send_algorithm->TimeUntilSend(
151 clock_->Now(), it->bytes_in_flight); 151 clock_->Now(), it->bytes_in_flight);
152 } 152 }
153 if (transfer_send_time < next_send_time) { 153 if (transfer_send_time < next_send_time) {
154 next_send_time = transfer_send_time; 154 next_send_time = transfer_send_time;
155 transfer = &(*it); 155 transfer = &(*it);
156 } 156 }
157 } 157 }
158 DVLOG(1) << "NextSendTime returning delta(ms):" 158 DVLOG(1) << "NextSendTime returning delta(ms):"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 // Skip over any packets less than or equal to last_acked. 218 // Skip over any packets less than or equal to last_acked.
219 if (it->packet_number <= last_acked) { 219 if (it->packet_number <= last_acked) {
220 continue; 220 continue;
221 } 221 }
222 // Lost packets don't trigger an ack. 222 // Lost packets don't trigger an ack.
223 if (it->lost) { 223 if (it->lost) {
224 continue; 224 continue;
225 } 225 }
226 DCHECK_LT(*next_acked, it->packet_number); 226 DCHECK_LT(*next_acked, it->packet_number);
227 // Consider a delayed ack for the current next_acked. 227 // Consider a delayed ack for the current next_acked.
228 if (ack_delay < it->ack_time.Subtract(clock_->Now())) { 228 if (ack_delay < it->ack_time - clock_->Now()) {
229 break; 229 break;
230 } 230 }
231 *next_acked = it->packet_number; 231 *next_acked = it->packet_number;
232 ack_delay = it->ack_time.Subtract(clock_->Now()); 232 ack_delay = it->ack_time - clock_->Now();
233 if (HasRecentLostPackets(transfer, *next_acked) || 233 if (HasRecentLostPackets(transfer, *next_acked) ||
234 (*next_acked - last_acked) >= 2) { 234 (*next_acked - last_acked) >= 2) {
235 break; 235 break;
236 } 236 }
237 ack_delay = ack_delay.Add(delayed_ack_timer_); 237 ack_delay = ack_delay + delayed_ack_timer_;
238 } 238 }
239 239
240 DVLOG(1) << "FindNextAck found next_acked_:" << transfer->sender->next_acked 240 DVLOG(1) << "FindNextAck found next_acked_:" << transfer->sender->next_acked
241 << " last_acked:" << transfer->sender->last_acked 241 << " last_acked:" << transfer->sender->last_acked
242 << " ack_time(ms):" << ack_delay.ToMilliseconds(); 242 << " ack_time(ms):" << ack_delay.ToMilliseconds();
243 return ack_delay; 243 return ack_delay;
244 } 244 }
245 245
246 bool SendAlgorithmSimulator::HasRecentLostPackets( 246 bool SendAlgorithmSimulator::HasRecentLostPackets(
247 const Transfer* transfer, 247 const Transfer* transfer,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 // This packet has been acked or lost, remove it from sent_packets_. 301 // This packet has been acked or lost, remove it from sent_packets_.
302 largest_observed = *it; 302 largest_observed = *it;
303 sent_packets_.erase(it++); 303 sent_packets_.erase(it++);
304 } 304 }
305 305
306 DCHECK(!largest_observed.lost); 306 DCHECK(!largest_observed.lost);
307 DVLOG(1) << "Updating RTT from send_time:" 307 DVLOG(1) << "Updating RTT from send_time:"
308 << largest_observed.send_time.ToDebuggingValue() 308 << largest_observed.send_time.ToDebuggingValue()
309 << " to ack_time:" << largest_observed.ack_time.ToDebuggingValue(); 309 << " to ack_time:" << largest_observed.ack_time.ToDebuggingValue();
310 QuicTime::Delta measured_rtt = 310 QuicTime::Delta measured_rtt =
311 largest_observed.ack_time.Subtract(largest_observed.send_time); 311 largest_observed.ack_time - largest_observed.send_time;
312 DCHECK_GE(measured_rtt.ToMicroseconds(), rtt_.ToMicroseconds()); 312 DCHECK_GE(measured_rtt.ToMicroseconds(), rtt_.ToMicroseconds());
313 sender->rtt_stats->UpdateRtt(measured_rtt, QuicTime::Delta::Zero(), 313 sender->rtt_stats->UpdateRtt(measured_rtt, QuicTime::Delta::Zero(),
314 clock_->Now()); 314 clock_->Now());
315 sender->send_algorithm->OnCongestionEvent(true, transfer->bytes_in_flight, 315 sender->send_algorithm->OnCongestionEvent(true, transfer->bytes_in_flight,
316 acked_packets, lost_packets); 316 acked_packets, lost_packets);
317 DCHECK_LE(kPacketSize * (acked_packets.size() + lost_packets.size()), 317 DCHECK_LE(kPacketSize * (acked_packets.size() + lost_packets.size()),
318 transfer->bytes_in_flight); 318 transfer->bytes_in_flight);
319 transfer->bytes_in_flight -= 319 transfer->bytes_in_flight -=
320 kPacketSize * (acked_packets.size() + lost_packets.size()); 320 kPacketSize * (acked_packets.size() + lost_packets.size());
321 321
322 sender->RecordStats(); 322 sender->RecordStats();
323 transfer->bytes_acked += acked_packets.size() * kPacketSize; 323 transfer->bytes_acked += acked_packets.size() * kPacketSize;
324 transfer->bytes_lost += lost_packets.size() * kPacketSize; 324 transfer->bytes_lost += lost_packets.size() * kPacketSize;
325 if (transfer->bytes_acked >= transfer->num_bytes) { 325 if (transfer->bytes_acked >= transfer->num_bytes) {
326 // Remove completed transfers and record transfer bandwidth. 326 // Remove completed transfers and record transfer bandwidth.
327 QuicTime::Delta transfer_time = 327 QuicTime::Delta transfer_time = clock_->Now() - transfer->start_time;
328 clock_->Now().Subtract(transfer->start_time);
329 sender->last_transfer_loss_rate = 328 sender->last_transfer_loss_rate =
330 static_cast<float>(transfer->bytes_lost) / 329 static_cast<float>(transfer->bytes_lost) /
331 (transfer->bytes_lost + transfer->bytes_acked); 330 (transfer->bytes_lost + transfer->bytes_acked);
332 sender->last_transfer_bandwidth = QuicBandwidth::FromBytesAndTimeDelta( 331 sender->last_transfer_bandwidth = QuicBandwidth::FromBytesAndTimeDelta(
333 transfer->num_bytes, transfer_time); 332 transfer->num_bytes, transfer_time);
334 DCHECK_GE(bandwidth_.ToBitsPerSecond(), 333 DCHECK_GE(bandwidth_.ToBitsPerSecond(),
335 sender->last_transfer_bandwidth.ToBitsPerSecond()); 334 sender->last_transfer_bandwidth.ToBitsPerSecond());
336 for (vector<Transfer>::iterator it = pending_transfers_.begin(); 335 for (vector<Transfer>::iterator it = pending_transfers_.begin();
337 it != pending_transfers_.end(); ++it) { 336 it != pending_transfers_.end(); ++it) {
338 if (transfer == &(*it)) { 337 if (transfer == &(*it)) {
(...skipping 27 matching lines...) Expand all
366 loss_correlation_ * std::numeric_limits<uint64_t>::max() > 365 loss_correlation_ * std::numeric_limits<uint64_t>::max() >
367 simple_random_.RandUint64()) { 366 simple_random_.RandUint64()) {
368 packet_lost = true; 367 packet_lost = true;
369 } 368 }
370 DVLOG(1) << "losing packet:" << sender->last_sent 369 DVLOG(1) << "losing packet:" << sender->last_sent
371 << " name:" << transfer->name << " due to random loss."; 370 << " name:" << transfer->name << " due to random loss.";
372 371
373 // If the number of bytes in flight are less than the bdp, there's 372 // If the number of bytes in flight are less than the bdp, there's
374 // no buffering delay. Bytes lost from the buffer are not counted. 373 // no buffering delay. Bytes lost from the buffer are not counted.
375 QuicByteCount bdp = bandwidth_.ToBytesPerPeriod(rtt_); 374 QuicByteCount bdp = bandwidth_.ToBytesPerPeriod(rtt_);
376 QuicTime ack_time = clock_->Now().Add(rtt_).Add(sender->additional_rtt); 375 QuicTime ack_time = clock_->Now() + rtt_ + sender->additional_rtt;
377 if (kPacketSize > bdp) { 376 if (kPacketSize > bdp) {
378 ack_time = ack_time.Add(bandwidth_.TransferTime(kPacketSize - bdp)); 377 ack_time = ack_time + bandwidth_.TransferTime(kPacketSize - bdp);
379 } 378 }
380 QuicTime queue_ack_time = sent_packets_.empty() 379 QuicTime queue_ack_time = sent_packets_.empty()
381 ? QuicTime::Zero() 380 ? QuicTime::Zero()
382 : sent_packets_.back().ack_time.Add( 381 : sent_packets_.back().ack_time +
383 bandwidth_.TransferTime(kPacketSize)); 382 bandwidth_.TransferTime(kPacketSize);
384 ack_time = QuicTime::Max(ack_time, queue_ack_time); 383 ack_time = QuicTime::Max(ack_time, queue_ack_time);
385 sent_packets_.push_back(SentPacket(sender->last_sent, clock_->Now(), 384 sent_packets_.push_back(SentPacket(sender->last_sent, clock_->Now(),
386 ack_time, packet_lost, transfer)); 385 ack_time, packet_lost, transfer));
387 } else { 386 } else {
388 DVLOG(1) << "losing packet:" << sender->last_sent 387 DVLOG(1) << "losing packet:" << sender->last_sent
389 << " name:" << transfer->name << " because the buffer was full."; 388 << " name:" << transfer->name << " because the buffer was full.";
390 } 389 }
391 transfer->bytes_in_flight += kPacketSize; 390 transfer->bytes_in_flight += kPacketSize;
392 } 391 }
393 392
394 } // namespace net 393 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/congestion_control/send_algorithm_interface.cc ('k') | net/quic/congestion_control/tcp_cubic_sender_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698