webrtc_m130/webrtc/modules/pacing/alr_detector.cc
isheriff 3168781d2f Add AlrDetector
This is a simple application limited region detector that is quite conservative
at the moment. We detect as being application-limited if we see sending rate
as less than 30% of the estimated bandwidth over 500 ms. The moment we detect
a single burst above 30% over a 100 ms period, we consider ourselves network
limited.

This class is currently not used. A follow up CL will leverage this to enable probing.

BUG=webrtc:6332

Review-Url: https://codereview.webrtc.org/2340763004
Cr-Commit-Position: refs/heads/master@{#14505}
2016-10-04 15:43:15 +00:00

81 lines
2.7 KiB
C++

/*
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/modules/pacing/alr_detector.h"
#include "webrtc/base/checks.h"
#include "webrtc/base/logging.h"
namespace {
// Time period over which outgoing traffic is measured and considered a single
// data point.
constexpr int kMeasurementPeriodMs = 100;
// Minimum number of consecutive measurements over |kMeasurementPeriodMs| time
// that indicate sending rate is below |kUsagePercent| to consider being
// application limited.
constexpr int kApplicationLimitedThreshold = 5;
// Sent traffic percentage as a function of network capaicty to consider traffic
// as application limited.
// NOTE: This is intentionally conservative at the moment until BW adjustments
// of application limited region is fine tuned.
constexpr int kUsagePercent = 30;
} // namespace
namespace webrtc {
AlrDetector::AlrDetector()
: measurement_interval_bytes_sent_(0),
measurement_interval_elapsed_time_ms_(0),
estimated_bitrate_bps_(0),
application_limited_count_(0) {}
AlrDetector::~AlrDetector() {}
void AlrDetector::OnBytesSent(size_t bytes_sent, int64_t elapsed_time_ms) {
if (measurement_interval_elapsed_time_ms_ > kMeasurementPeriodMs) {
RTC_DCHECK(estimated_bitrate_bps_);
int max_bytes =
(measurement_interval_elapsed_time_ms_ * estimated_bitrate_bps_) /
(8 * 1000);
RTC_DCHECK_GT(max_bytes, 0);
int utilization =
static_cast<int>((measurement_interval_bytes_sent_ * 100) / max_bytes);
if (utilization < kUsagePercent) {
application_limited_count_++;
if (application_limited_count_ == kApplicationLimitedThreshold)
LOG(LS_INFO) << "ALR start";
} else {
if (application_limited_count_ >= kApplicationLimitedThreshold)
LOG(LS_INFO) << "ALR stop";
application_limited_count_ = 0;
}
measurement_interval_elapsed_time_ms_ = elapsed_time_ms;
measurement_interval_bytes_sent_ = bytes_sent;
} else {
measurement_interval_elapsed_time_ms_ += elapsed_time_ms;
measurement_interval_bytes_sent_ += bytes_sent;
}
}
void AlrDetector::SetEstimatedBitrate(int bitrate_bps) {
RTC_DCHECK(bitrate_bps);
estimated_bitrate_bps_ = bitrate_bps;
}
bool AlrDetector::InApplicationLimitedRegion() {
return application_limited_count_ >= kApplicationLimitedThreshold;
}
} // namespace webrtc