Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / net / quic / congestion_control / hybrid_slow_start.cc
blobd6a47e4ed6df1da47c855b11348168ae9ed4c940
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
3 // found in the LICENSE file.
5 #include "net/quic/congestion_control/hybrid_slow_start.h"
7 #include <algorithm>
9 using std::max;
10 using std::min;
12 namespace net {
14 // Note(pwestin): the magic clamping numbers come from the original code in
15 // tcp_cubic.c.
16 const int64 kHybridStartLowWindow = 16;
17 // Number of delay samples for detecting the increase of delay.
18 const uint32 kHybridStartMinSamples = 8;
19 // Exit slow start if the min rtt has increased by more than 1/8th.
20 const int kHybridStartDelayFactorExp = 3; // 2^3 = 8
21 // The original paper specifies 2 and 8ms, but those have changed over time.
22 const int64 kHybridStartDelayMinThresholdUs = 4000;
23 const int64 kHybridStartDelayMaxThresholdUs = 16000;
25 HybridSlowStart::HybridSlowStart()
26 : started_(false),
27 hystart_found_(NOT_FOUND),
28 last_sent_sequence_number_(0),
29 end_sequence_number_(0),
30 rtt_sample_count_(0),
31 current_min_rtt_(QuicTime::Delta::Zero()) {
34 void HybridSlowStart::OnPacketAcked(
35 QuicPacketSequenceNumber acked_sequence_number, bool in_slow_start) {
36 // OnPacketAcked gets invoked after ShouldExitSlowStart, so it's best to end
37 // the round when the final packet of the burst is received and start it on
38 // the next incoming ack.
39 if (in_slow_start && IsEndOfRound(acked_sequence_number)) {
40 started_ = false;
44 void HybridSlowStart::OnPacketSent(QuicPacketSequenceNumber sequence_number) {
45 last_sent_sequence_number_ = sequence_number;
48 void HybridSlowStart::Restart() {
49 started_ = false;
50 hystart_found_ = NOT_FOUND;
53 void HybridSlowStart::StartReceiveRound(QuicPacketSequenceNumber last_sent) {
54 DVLOG(1) << "Reset hybrid slow start @" << last_sent;
55 end_sequence_number_ = last_sent;
56 current_min_rtt_ = QuicTime::Delta::Zero();
57 rtt_sample_count_ = 0;
58 started_ = true;
61 bool HybridSlowStart::IsEndOfRound(QuicPacketSequenceNumber ack) const {
62 return end_sequence_number_ <= ack;
65 bool HybridSlowStart::ShouldExitSlowStart(QuicTime::Delta latest_rtt,
66 QuicTime::Delta min_rtt,
67 QuicPacketCount congestion_window) {
68 if (!started_) {
69 // Time to start the hybrid slow start.
70 StartReceiveRound(last_sent_sequence_number_);
72 if (hystart_found_ != NOT_FOUND) {
73 return true;
75 // Second detection parameter - delay increase detection.
76 // Compare the minimum delay (current_min_rtt_) of the current
77 // burst of packets relative to the minimum delay during the session.
78 // Note: we only look at the first few(8) packets in each burst, since we
79 // only want to compare the lowest RTT of the burst relative to previous
80 // bursts.
81 rtt_sample_count_++;
82 if (rtt_sample_count_ <= kHybridStartMinSamples) {
83 if (current_min_rtt_.IsZero() || current_min_rtt_ > latest_rtt) {
84 current_min_rtt_ = latest_rtt;
87 // We only need to check this once per round.
88 if (rtt_sample_count_ == kHybridStartMinSamples) {
89 // Divide min_rtt by 8 to get a rtt increase threshold for exiting.
90 int64 min_rtt_increase_threshold_us = min_rtt.ToMicroseconds() >>
91 kHybridStartDelayFactorExp;
92 // Ensure the rtt threshold is never less than 2ms or more than 16ms.
93 min_rtt_increase_threshold_us = min(min_rtt_increase_threshold_us,
94 kHybridStartDelayMaxThresholdUs);
95 QuicTime::Delta min_rtt_increase_threshold =
96 QuicTime::Delta::FromMicroseconds(max(min_rtt_increase_threshold_us,
97 kHybridStartDelayMinThresholdUs));
99 if (current_min_rtt_ > min_rtt.Add(min_rtt_increase_threshold)) {
100 hystart_found_= DELAY;
103 // Exit from slow start if the cwnd is greater than 16 and
104 // increasing delay is found.
105 return congestion_window >= kHybridStartLowWindow &&
106 hystart_found_ != NOT_FOUND;
109 } // namespace net