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

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

Issue 2949203002: Only use 95% of the link capacity if the true link capacity is found by probing. (Closed)
Patch Set: Nit Created 3 years, 6 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 /* 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
11 #include "webrtc/modules/congestion_controller/probe_bitrate_estimator.h" 11 #include "webrtc/modules/congestion_controller/probe_bitrate_estimator.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 14
15 #include "webrtc/base/checks.h" 15 #include "webrtc/base/checks.h"
16 #include "webrtc/base/logging.h" 16 #include "webrtc/base/logging.h"
17 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" 17 #include "webrtc/logging/rtc_event_log/rtc_event_log.h"
18 18
19 namespace { 19 namespace {
20 // The minumum number of probes we need to receive feedback about in percent 20 // The minumum number of probes we need to receive feedback about in percent
21 // in order to have a valid estimate. 21 // in order to have a valid estimate.
22 constexpr int kMinReceivedProbesPercent = 80; 22 constexpr int kMinReceivedProbesPercent = 80;
23 23
24 // The minumum number of bytes we need to receive feedback about in percent 24 // The minumum number of bytes we need to receive feedback about in percent
25 // in order to have a valid estimate. 25 // in order to have a valid estimate.
26 constexpr int kMinReceivedBytesPercent = 80; 26 constexpr int kMinReceivedBytesPercent = 80;
27 27
28 // The maximum (receive rate)/(send rate) ratio for a valid estimate. 28 // The maximum |receive rate| / |send rate| ratio for a valid estimate.
29 constexpr float kValidRatio = 2.0f; 29 constexpr float kMaxValidRatio = 2.0f;
30
31 // The minimum |receive rate| / |send rate| ratio assuming that the link is
32 // not saturated, i.e. we assume that we will receive at least
33 // kMinRatioForUnsaturatedLink * |send rate| if |send rate| is less than the
34 // link capacity.
35 constexpr float kMinRatioForUnsaturatedLink = 0.9f;
36
37 // The target utilization of the link. If we know true link capacity
38 // we'd like to send at 95% of that rate.
39 constexpr float kTargetUtilizationFraction = 0.95f;
30 40
31 // The maximum time period over which the cluster history is retained. 41 // The maximum time period over which the cluster history is retained.
32 // This is also the maximum time period beyond which a probing burst is not 42 // This is also the maximum time period beyond which a probing burst is not
33 // expected to last. 43 // expected to last.
34 constexpr int kMaxClusterHistoryMs = 1000; 44 constexpr int kMaxClusterHistoryMs = 1000;
35 45
36 // The maximum time interval between first and the last probe on a cluster 46 // The maximum time interval between first and the last probe on a cluster
37 // on the sender side as well as the receive side. 47 // on the sender side as well as the receive side.
38 constexpr int kMaxProbeIntervalMs = 1000; 48 constexpr int kMaxProbeIntervalMs = 1000;
39 } // namespace 49 } // namespace
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 float send_bps = send_size / send_interval_ms * 1000; 116 float send_bps = send_size / send_interval_ms * 1000;
107 117
108 // Since the |receive_interval_ms| does not include the time it takes to 118 // Since the |receive_interval_ms| does not include the time it takes to
109 // actually receive the first packet the size of the first received packet 119 // actually receive the first packet the size of the first received packet
110 // should not be included when calculating the receive bitrate. 120 // should not be included when calculating the receive bitrate.
111 RTC_DCHECK_GT(cluster->size_total, cluster->size_first_receive); 121 RTC_DCHECK_GT(cluster->size_total, cluster->size_first_receive);
112 float receive_size = cluster->size_total - cluster->size_first_receive; 122 float receive_size = cluster->size_total - cluster->size_first_receive;
113 float receive_bps = receive_size / receive_interval_ms * 1000; 123 float receive_bps = receive_size / receive_interval_ms * 1000;
114 124
115 float ratio = receive_bps / send_bps; 125 float ratio = receive_bps / send_bps;
116 if (ratio > kValidRatio) { 126 if (ratio > kMaxValidRatio) {
117 LOG(LS_INFO) << "Probing unsuccessful, receive/send ratio too high" 127 LOG(LS_INFO) << "Probing unsuccessful, receive/send ratio too high"
118 << " [cluster id: " << cluster_id << "] [send: " << send_size 128 << " [cluster id: " << cluster_id << "] [send: " << send_size
119 << " bytes / " << send_interval_ms 129 << " bytes / " << send_interval_ms
120 << " ms = " << send_bps / 1000 << " kb/s]" 130 << " ms = " << send_bps / 1000 << " kb/s]"
121 << " [receive: " << receive_size << " bytes / " 131 << " [receive: " << receive_size << " bytes / "
122 << receive_interval_ms << " ms = " << receive_bps / 1000 132 << receive_interval_ms << " ms = " << receive_bps / 1000
123 << " kb/s]" 133 << " kb/s]"
124 << " [ratio: " << receive_bps / 1000 << " / " 134 << " [ratio: " << receive_bps / 1000 << " / "
125 << send_bps / 1000 << " = " << ratio << " > kValidRatio (" 135 << send_bps / 1000 << " = " << ratio << " > kMaxValidRatio ("
126 << kValidRatio << ")]"; 136 << kMaxValidRatio << ")]";
127 if (event_log_) 137 if (event_log_)
128 event_log_->LogProbeResultFailure(cluster_id, kInvalidSendReceiveRatio); 138 event_log_->LogProbeResultFailure(cluster_id, kInvalidSendReceiveRatio);
129 return -1; 139 return -1;
130 } 140 }
131 LOG(LS_INFO) << "Probing successful" 141 LOG(LS_INFO) << "Probing successful"
132 << " [cluster id: " << cluster_id << "] [send: " << send_size 142 << " [cluster id: " << cluster_id << "] [send: " << send_size
133 << " bytes / " << send_interval_ms << " ms = " << send_bps / 1000 143 << " bytes / " << send_interval_ms << " ms = " << send_bps / 1000
134 << " kb/s]" 144 << " kb/s]"
135 << " [receive: " << receive_size << " bytes / " 145 << " [receive: " << receive_size << " bytes / "
136 << receive_interval_ms << " ms = " << receive_bps / 1000 146 << receive_interval_ms << " ms = " << receive_bps / 1000
137 << " kb/s]"; 147 << " kb/s]";
138 148
139 float res = std::min(send_bps, receive_bps); 149 float res = std::min(send_bps, receive_bps);
150 // If we're receiving at significantly lower bitrate than we were sending at,
151 // it suggests that we've found the true capacity of the link. In this case,
152 // set the target bitrate slightly lower to not immediately overuse.
153 if (receive_bps < kMinRatioForUnsaturatedLink * send_bps) {
154 RTC_DCHECK_GT(send_bps, receive_bps);
155 res = kTargetUtilizationFraction * receive_bps;
156 }
140 if (event_log_) 157 if (event_log_)
141 event_log_->LogProbeResultSuccess(cluster_id, res); 158 event_log_->LogProbeResultSuccess(cluster_id, res);
142 estimated_bitrate_bps_ = rtc::Optional<int>(res); 159 estimated_bitrate_bps_ = rtc::Optional<int>(res);
143 return *estimated_bitrate_bps_; 160 return *estimated_bitrate_bps_;
144 } 161 }
145 162
146 rtc::Optional<int> 163 rtc::Optional<int>
147 ProbeBitrateEstimator::FetchAndResetLastEstimatedBitrateBps() { 164 ProbeBitrateEstimator::FetchAndResetLastEstimatedBitrateBps() {
148 rtc::Optional<int> estimated_bitrate_bps = estimated_bitrate_bps_; 165 rtc::Optional<int> estimated_bitrate_bps = estimated_bitrate_bps_;
149 estimated_bitrate_bps_.reset(); 166 estimated_bitrate_bps_.reset();
150 return estimated_bitrate_bps; 167 return estimated_bitrate_bps;
151 } 168 }
152 169
153 void ProbeBitrateEstimator::EraseOldClusters(int64_t timestamp_ms) { 170 void ProbeBitrateEstimator::EraseOldClusters(int64_t timestamp_ms) {
154 for (auto it = clusters_.begin(); it != clusters_.end();) { 171 for (auto it = clusters_.begin(); it != clusters_.end();) {
155 if (it->second.last_receive_ms < timestamp_ms) { 172 if (it->second.last_receive_ms < timestamp_ms) {
156 it = clusters_.erase(it); 173 it = clusters_.erase(it);
157 } else { 174 } else {
158 ++it; 175 ++it;
159 } 176 }
160 } 177 }
161 } 178 }
162 } // namespace webrtc 179 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698