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

Side by Side Diff: webrtc/modules/congestion_controller/probe_controller.cc

Issue 2504023002: Implement periodic bandwidth probing in application-limited region. (Closed)
Patch Set: address feedback Created 4 years, 1 month 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 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 20 matching lines...) Expand all
31 31
32 // Value of |min_bitrate_to_probe_further_bps_| that indicates 32 // Value of |min_bitrate_to_probe_further_bps_| that indicates
33 // further probing is disabled. 33 // further probing is disabled.
34 constexpr int kExponentialProbingDisabled = 0; 34 constexpr int kExponentialProbingDisabled = 0;
35 35
36 // Default probing bitrate limit. Applied only when the application didn't 36 // Default probing bitrate limit. Applied only when the application didn't
37 // specify max bitrate. 37 // specify max bitrate.
38 constexpr int kDefaultMaxProbingBitrateBps = 100000000; 38 constexpr int kDefaultMaxProbingBitrateBps = 100000000;
39 39
40 // This is a limit on how often probing can be done when there is a BW 40 // This is a limit on how often probing can be done when there is a BW
41 // drop detected in ALR region. 41 // drop detected in ALR.
42 constexpr int kAlrProbingIntervalLimitMs = 5000; 42 constexpr int64_t kAlrProbingIntervalMinMs = 5000;
43
44 // Interval between probes when ALR periodic probing is enabled.
45 constexpr int64_t kAlrPeriodicProbingIntervalMs = 5000;
43 46
44 } // namespace 47 } // namespace
45 48
46 ProbeController::ProbeController(PacedSender* pacer, Clock* clock) 49 ProbeController::ProbeController(PacedSender* pacer, Clock* clock)
47 : pacer_(pacer), 50 : pacer_(pacer),
48 clock_(clock), 51 clock_(clock),
49 network_state_(kNetworkUp), 52 network_state_(kNetworkUp),
50 state_(State::kInit), 53 state_(State::kInit),
51 min_bitrate_to_probe_further_bps_(kExponentialProbingDisabled), 54 min_bitrate_to_probe_further_bps_(kExponentialProbingDisabled),
52 time_last_probing_initiated_ms_(0), 55 time_last_probing_initiated_ms_(0),
53 estimated_bitrate_bps_(0), 56 estimated_bitrate_bps_(0),
54 start_bitrate_bps_(0), 57 start_bitrate_bps_(0),
55 max_bitrate_bps_(0), 58 max_bitrate_bps_(0),
56 last_alr_probing_time_(clock_->TimeInMilliseconds()) {} 59 last_alr_probing_time_(clock_->TimeInMilliseconds()),
60 enable_periodic_probing_(false) {}
57 61
58 void ProbeController::SetBitrates(int min_bitrate_bps, 62 void ProbeController::SetBitrates(int min_bitrate_bps,
59 int start_bitrate_bps, 63 int start_bitrate_bps,
60 int max_bitrate_bps) { 64 int max_bitrate_bps) {
61 rtc::CritScope cs(&critsect_); 65 rtc::CritScope cs(&critsect_);
62 66
63 start_bitrate_bps_ = 67 start_bitrate_bps_ =
64 start_bitrate_bps > 0 ? start_bitrate_bps : min_bitrate_bps; 68 start_bitrate_bps > 0 ? start_bitrate_bps : min_bitrate_bps;
65 69
66 int old_max_bitrate_bps = max_bitrate_bps_; 70 int old_max_bitrate_bps = max_bitrate_bps_;
67 max_bitrate_bps_ = max_bitrate_bps; 71 max_bitrate_bps_ = max_bitrate_bps;
68 72
69 switch (state_) { 73 switch (state_) {
70 case State::kInit: 74 case State::kInit:
71 if (network_state_ == kNetworkUp) 75 if (network_state_ == kNetworkUp)
72 InitiateExponentialProbing(); 76 InitiateExponentialProbing();
73 break; 77 break;
74 78
75 case State::kWaitingForProbingResult: 79 case State::kWaitingForProbingResult:
76 break; 80 break;
77 81
78 case State::kProbingComplete: 82 case State::kProbingComplete:
79 // Initiate probing when |max_bitrate_| was increased mid-call. 83 // Initiate probing when |max_bitrate_| was increased mid-call.
80 if (estimated_bitrate_bps_ != 0 && 84 if (estimated_bitrate_bps_ != 0 &&
81 estimated_bitrate_bps_ < old_max_bitrate_bps && 85 estimated_bitrate_bps_ < old_max_bitrate_bps &&
82 max_bitrate_bps_ > old_max_bitrate_bps) { 86 max_bitrate_bps_ > old_max_bitrate_bps) {
83 InitiateProbing({max_bitrate_bps}, kExponentialProbingDisabled); 87 InitiateProbing(clock_->TimeInMilliseconds(), {max_bitrate_bps},
88 kExponentialProbingDisabled);
84 } 89 }
85 break; 90 break;
86 } 91 }
87 } 92 }
88 93
89 void ProbeController::OnNetworkStateChanged(NetworkState network_state) { 94 void ProbeController::OnNetworkStateChanged(NetworkState network_state) {
90 rtc::CritScope cs(&critsect_); 95 rtc::CritScope cs(&critsect_);
91 network_state_ = network_state; 96 network_state_ = network_state;
92 if (network_state_ == kNetworkUp && state_ == State::kInit) 97 if (network_state_ == kNetworkUp && state_ == State::kInit)
93 InitiateExponentialProbing(); 98 InitiateExponentialProbing();
94 } 99 }
95 100
96 void ProbeController::InitiateExponentialProbing() { 101 void ProbeController::InitiateExponentialProbing() {
97 RTC_DCHECK(network_state_ == kNetworkUp); 102 RTC_DCHECK(network_state_ == kNetworkUp);
98 RTC_DCHECK(state_ == State::kInit); 103 RTC_DCHECK(state_ == State::kInit);
99 RTC_DCHECK_GT(start_bitrate_bps_, 0); 104 RTC_DCHECK_GT(start_bitrate_bps_, 0);
100 105
101 // When probing at 1.8 Mbps ( 6x 300), this represents a threshold of 106 // When probing at 1.8 Mbps ( 6x 300), this represents a threshold of
102 // 1.2 Mbps to continue probing. 107 // 1.2 Mbps to continue probing.
103 InitiateProbing({3 * start_bitrate_bps_, 6 * start_bitrate_bps_}, 108 InitiateProbing(clock_->TimeInMilliseconds(),
109 {3 * start_bitrate_bps_, 6 * start_bitrate_bps_},
104 4 * start_bitrate_bps_); 110 4 * start_bitrate_bps_);
105 } 111 }
106 112
107 void ProbeController::SetEstimatedBitrate(int bitrate_bps) { 113 void ProbeController::SetEstimatedBitrate(int bitrate_bps) {
108 rtc::CritScope cs(&critsect_); 114 rtc::CritScope cs(&critsect_);
115 int64_t now_ms = clock_->TimeInMilliseconds();
116
109 if (state_ == State::kWaitingForProbingResult) { 117 if (state_ == State::kWaitingForProbingResult) {
110 if ((clock_->TimeInMilliseconds() - time_last_probing_initiated_ms_) > 118 if ((now_ms - time_last_probing_initiated_ms_) >
111 kMaxWaitingTimeForProbingResultMs) { 119 kMaxWaitingTimeForProbingResultMs) {
112 LOG(LS_INFO) << "kWaitingForProbingResult: timeout"; 120 LOG(LS_INFO) << "kWaitingForProbingResult: timeout";
113 state_ = State::kProbingComplete; 121 state_ = State::kProbingComplete;
114 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled; 122 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled;
115 } else { 123 } else {
116 // Continue probing if probing results indicate channel has greater 124 // Continue probing if probing results indicate channel has greater
117 // capacity. 125 // capacity.
118 LOG(LS_INFO) << "Measured bitrate: " << bitrate_bps 126 LOG(LS_INFO) << "Measured bitrate: " << bitrate_bps
119 << " Minimum to probe further: " 127 << " Minimum to probe further: "
120 << min_bitrate_to_probe_further_bps_; 128 << min_bitrate_to_probe_further_bps_;
121 if (min_bitrate_to_probe_further_bps_ != kExponentialProbingDisabled && 129 if (min_bitrate_to_probe_further_bps_ != kExponentialProbingDisabled &&
122 bitrate_bps > min_bitrate_to_probe_further_bps_) { 130 bitrate_bps > min_bitrate_to_probe_further_bps_) {
123 // Double the probing bitrate and expect a minimum of 25% gain to 131 // Double the probing bitrate and expect a minimum of 25% gain to
124 // continue probing. 132 // continue probing.
125 InitiateProbing({2 * bitrate_bps}, 1.25 * bitrate_bps); 133 InitiateProbing(now_ms, {2 * bitrate_bps}, bitrate_bps * 5 / 4);
134 } else {
135 // Stop exponential probing.
136 state_ = State::kProbingComplete;
137 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled;
126 } 138 }
127 } 139 }
128 } else { 140 }
129 // A drop in estimated BW when operating in ALR and not already probing. 141
130 // The current response is to initiate a single probe session at the 142 // Detect a drop in estimated BW when operating in ALR and not already
131 // previous bitrate and immediately use the reported bitrate as the new 143 // probing. The current response is to initiate a single probe session at the
132 // bitrate. 144 // previous bitrate and immediately use the reported bitrate as the new
133 // 145 // bitrate.
134 // If the probe session fails, the assumption is that this drop was a 146 //
135 // real one from a competing flow or something else on the network and 147 // If the probe session fails, the assumption is that this drop was a
136 // it ramps up from bitrate_bps. 148 // real one from a competing flow or something else on the network and
137 if (pacer_->InApplicationLimitedRegion() && 149 // it ramps up from bitrate_bps.
138 bitrate_bps < 0.5 * estimated_bitrate_bps_) { 150 if (state_ == State::kProbingComplete &&
139 int64_t now_ms = clock_->TimeInMilliseconds(); 151 pacer_->GetApplicationLimitedRegionStartTime() &&
140 if ((now_ms - last_alr_probing_time_) > kAlrProbingIntervalLimitMs) { 152 bitrate_bps < estimated_bitrate_bps_ / 2 &&
141 LOG(LS_INFO) << "Detected big BW drop in ALR, start probe."; 153 (now_ms - last_alr_probing_time_) > kAlrProbingIntervalMinMs) {
142 // Track how often we probe in response to BW drop in ALR. 154 LOG(LS_INFO) << "Detected big BW drop in ALR, start probe.";
143 RTC_HISTOGRAM_COUNTS_10000("WebRTC.BWE.AlrProbingIntervalInS", 155 // Track how often we probe in response to BW drop in ALR.
144 (now_ms - last_alr_probing_time_) / 1000); 156 RTC_HISTOGRAM_COUNTS_10000("WebRTC.BWE.AlrProbingIntervalInS",
145 InitiateProbing({estimated_bitrate_bps_}, kExponentialProbingDisabled); 157 (now_ms - last_alr_probing_time_) / 1000);
146 last_alr_probing_time_ = now_ms; 158 InitiateProbing(now_ms, {estimated_bitrate_bps_},
147 } 159 kExponentialProbingDisabled);
148 } 160 last_alr_probing_time_ = now_ms;
161
149 // TODO(isheriff): May want to track when we did ALR probing in order 162 // TODO(isheriff): May want to track when we did ALR probing in order
150 // to reset |last_alr_probing_time_| if we validate that it was a 163 // to reset |last_alr_probing_time_| if we validate that it was a
151 // drop due to exogenous event. 164 // drop due to exogenous event.
152 } 165 }
166
153 estimated_bitrate_bps_ = bitrate_bps; 167 estimated_bitrate_bps_ = bitrate_bps;
154 } 168 }
155 169
170 void ProbeController::EnablePeriodicProbing(bool enable) {
171 rtc::CritScope cs(&critsect_);
172 enable_periodic_probing_ = enable;
173 }
174
175 void ProbeController::Process() {
176 rtc::CritScope cs(&critsect_);
177
178 if (state_ != State::kProbingComplete || !enable_periodic_probing_)
179 return;
180
181 // Probe bandwidth periodically when in ALR state.
182 int64_t alr_start_time = pacer_->GetApplicationLimitedRegionStartTime();
183 if (alr_start_time > 0) {
184 int64_t now_ms = clock_->TimeInMilliseconds();
185 if (now_ms - alr_start_time >= kAlrPeriodicProbingIntervalMs &&
philipel 2016/11/21 12:05:42 I think something like this is a bit clearer: int6
Sergey Ulanov 2016/11/21 19:28:18 Done.
186 now_ms - time_last_probing_initiated_ms_ >=
187 kAlrPeriodicProbingIntervalMs) {
188 InitiateProbing(now_ms, {estimated_bitrate_bps_ * 2},
189 estimated_bitrate_bps_ * 5 / 4);
190 }
191 }
192 }
193
156 void ProbeController::InitiateProbing( 194 void ProbeController::InitiateProbing(
195 int64_t now_ms,
philipel 2016/11/21 12:05:42 I don't see why this change is necessary or makes
Sergey Ulanov 2016/11/21 19:28:18 TimeInMilliseconds() calls are not free, each of t
157 std::initializer_list<int> bitrates_to_probe, 196 std::initializer_list<int> bitrates_to_probe,
158 int min_bitrate_to_probe_further_bps) { 197 int min_bitrate_to_probe_further_bps) {
159 bool first_cluster = true; 198 bool first_cluster = true;
160 for (int bitrate : bitrates_to_probe) { 199 for (int bitrate : bitrates_to_probe) {
161 int max_probe_bitrate_bps = 200 int max_probe_bitrate_bps =
162 max_bitrate_bps_ > 0 ? max_bitrate_bps_ : kDefaultMaxProbingBitrateBps; 201 max_bitrate_bps_ > 0 ? max_bitrate_bps_ : kDefaultMaxProbingBitrateBps;
163 bitrate = std::min(bitrate, max_probe_bitrate_bps); 202 bitrate = std::min(bitrate, max_probe_bitrate_bps);
164 if (first_cluster) { 203 if (first_cluster) {
165 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster + 1); 204 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster + 1);
166 first_cluster = false; 205 first_cluster = false;
167 } else { 206 } else {
168 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster); 207 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster);
169 } 208 }
170 } 209 }
171 min_bitrate_to_probe_further_bps_ = min_bitrate_to_probe_further_bps; 210 min_bitrate_to_probe_further_bps_ = min_bitrate_to_probe_further_bps;
172 time_last_probing_initiated_ms_ = clock_->TimeInMilliseconds(); 211 time_last_probing_initiated_ms_ = now_ms;
173 if (min_bitrate_to_probe_further_bps == kExponentialProbingDisabled) 212 if (min_bitrate_to_probe_further_bps == kExponentialProbingDisabled)
174 state_ = State::kProbingComplete; 213 state_ = State::kProbingComplete;
175 else 214 else
176 state_ = State::kWaitingForProbingResult; 215 state_ = State::kWaitingForProbingResult;
177 } 216 }
178 217
179 } // namespace webrtc 218 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698