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

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

Issue 12334063: Land recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more EXPECT_FALSE Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
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/paced_sender.h" 5 #include "net/quic/congestion_control/paced_sender.h"
6 6
7 #include "net/quic/quic_protocol.h" 7 #include "net/quic/quic_protocol.h"
8 8
9 namespace net { 9 namespace net {
10 10
11 // To prevent too aggressive pacing we allow the following packet burst size. 11 // To prevent too aggressive pacing we allow the following packet burst size.
12 const int64 kMinPacketBurstSize = 2; 12 const int64 kMinPacketBurstSize = 2;
13 // Max estimated time between calls to TimeUntilSend and 13 // Max estimated time between calls to TimeUntilSend and
14 // AvailableCongestionWindow. 14 // AvailableCongestionWindow.
15 const int64 kMaxSchedulingDelayUs = 2000; 15 const int64 kMaxSchedulingDelayUs = 2000;
16 16
17 PacedSender::PacedSender(const QuicClock* clock, QuicBandwidth estimate) 17 PacedSender::PacedSender(QuicBandwidth estimate)
18 : leaky_bucket_(clock, estimate), 18 : leaky_bucket_(estimate),
19 pace_(estimate) { 19 pace_(estimate) {
20 } 20 }
21 21
22 void PacedSender::UpdateBandwidthEstimate(QuicBandwidth estimate) { 22 void PacedSender::UpdateBandwidthEstimate(QuicTime now,
23 leaky_bucket_.SetDrainingRate(estimate); 23 QuicBandwidth estimate) {
24 leaky_bucket_.SetDrainingRate(now, estimate);
24 pace_ = estimate; 25 pace_ = estimate;
25 } 26 }
26 27
27 void PacedSender::SentPacket(QuicByteCount bytes) { 28 void PacedSender::SentPacket(QuicTime now, QuicByteCount bytes) {
28 leaky_bucket_.Add(bytes); 29 leaky_bucket_.Add(now, bytes);
29 } 30 }
30 31
31 QuicTime::Delta PacedSender::TimeUntilSend(QuicTime::Delta time_until_send) { 32 QuicTime::Delta PacedSender::TimeUntilSend(QuicTime now,
33 QuicTime::Delta time_until_send) {
32 if (time_until_send.ToMicroseconds() >= kMaxSchedulingDelayUs) { 34 if (time_until_send.ToMicroseconds() >= kMaxSchedulingDelayUs) {
33 return time_until_send; 35 return time_until_send;
34 } 36 }
35 // Pace the data. 37 // Pace the data.
36 QuicByteCount pacing_window = pace_.ToBytesPerPeriod( 38 QuicByteCount pacing_window = pace_.ToBytesPerPeriod(
37 QuicTime::Delta::FromMicroseconds(kMaxSchedulingDelayUs)); 39 QuicTime::Delta::FromMicroseconds(kMaxSchedulingDelayUs));
38 QuicByteCount min_window_size = kMinPacketBurstSize * kMaxPacketSize; 40 QuicByteCount min_window_size = kMinPacketBurstSize * kMaxPacketSize;
39 pacing_window = std::max(pacing_window, min_window_size); 41 pacing_window = std::max(pacing_window, min_window_size);
40 42
41 if (pacing_window > leaky_bucket_.BytesPending()) { 43 if (pacing_window > leaky_bucket_.BytesPending(now)) {
42 // We have not filled our pacing window yet. 44 // We have not filled our pacing window yet.
43 return time_until_send; 45 return time_until_send;
44 } 46 }
45 return leaky_bucket_.TimeRemaining(); 47 return leaky_bucket_.TimeRemaining(now);
46 }
47
48 QuicByteCount PacedSender::AvailableWindow(
49 QuicByteCount available_congestion_window) {
50 QuicByteCount accuracy_window = pace_.ToBytesPerPeriod(
51 QuicTime::Delta::FromMicroseconds(kMaxSchedulingDelayUs));
52 QuicByteCount min_burst_window = kMinPacketBurstSize * kMaxPacketSize;
53 DLOG(INFO) << "Available congestion window:" << available_congestion_window
54 << " accuracy window:" << accuracy_window
55 << " min burst window:" << min_burst_window;
56
57 // Should we limit the window to pace the data?
58 if (available_congestion_window > min_burst_window &&
59 available_congestion_window > accuracy_window) {
60 // Max window depends on estimated bandwidth; higher bandwidth => larger
61 // burst we also consider our timing accuracy. An accuracy of 1 ms will
62 // allow us to send up to 19.2Mbit/s with 2 packets per burst.
63 available_congestion_window = std::max(min_burst_window, accuracy_window);
64 QuicByteCount bytes_pending = leaky_bucket_.BytesPending();
65 if (bytes_pending > available_congestion_window) {
66 return 0;
67 }
68 available_congestion_window -= bytes_pending;
69 }
70 return available_congestion_window;
71 } 48 }
72 49
73 } // namespace net 50 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/congestion_control/paced_sender.h ('k') | net/quic/congestion_control/paced_sender_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698