Revert "Moved congestion controller to task queue."

This reverts commit 0cbcba7ea0dced1a7f353c64d6cf91d46ccb29f9.

Reason for revert: Major regressions on perf bots.

Original change's description:
> Moved congestion controller to task queue.
> 
> The goal of this work is to make it easier to experiment with the
> bandwidth estimation implementation. For this reason network control
> functionality is moved from SendSideCongestionController(SSCC),
> PacedSender and BitrateController to the newly created
> GoogCcNetworkController which implements the newly created
> NetworkControllerInterface. This allows the implementation to be
> replaced at runtime in the future.
> 
> This is the first part of a split of a larger CL, see:
> https://webrtc-review.googlesource.com/c/src/+/39788/8
> For further explanations.
> 
> Bug: webrtc:8415
> Change-Id: I770189c04cc31b313bd4e57821acff55fbcb1ad3
> Reviewed-on: https://webrtc-review.googlesource.com/43840
> Commit-Queue: Sebastian Jansson <srte@webrtc.org>
> Reviewed-by: Björn Terelius <terelius@webrtc.org>
> Reviewed-by: Stefan Holmer <stefan@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#21868}

TBR=terelius@webrtc.org,stefan@webrtc.org,srte@webrtc.org

Change-Id: Ia8a273eb9e92b7d0d960c49658c228208170962d
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:8415
Reviewed-on: https://webrtc-review.googlesource.com/47560
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21877}
This commit is contained in:
Sebastian Jansson
2018-02-02 16:55:07 +00:00
committed by Commit Bot
parent c5017136c7
commit 5a503b05e1
57 changed files with 837 additions and 2996 deletions

View File

@ -9,8 +9,8 @@
*/
#include <memory>
#include "modules/congestion_controller/network_control/include/network_types.h"
#include "modules/congestion_controller/probe_controller.h"
#include "modules/pacing/mock/mock_paced_sender.h"
#include "rtc_base/logging.h"
#include "system_wrappers/include/clock.h"
#include "test/gmock.h"
@ -18,13 +18,9 @@
using testing::_;
using testing::AtLeast;
using testing::Field;
using testing::Matcher;
using testing::NiceMock;
using testing::Return;
using webrtc::ProbeClusterConfig;
namespace webrtc {
namespace test {
@ -40,252 +36,234 @@ constexpr int kAlrProbeInterval = 5000;
constexpr int kAlrEndedTimeoutMs = 3000;
constexpr int kBitrateDropTimeoutMs = 5000;
inline Matcher<ProbeClusterConfig> DataRateEqBps(int bps) {
return Field(&ProbeClusterConfig::target_data_rate, DataRate::bps(bps));
}
class MockNetworkControllerObserver : public NetworkControllerObserver {
public:
MOCK_METHOD1(OnCongestionWindow, void(CongestionWindow));
MOCK_METHOD1(OnPacerConfig, void(PacerConfig));
MOCK_METHOD1(OnProbeClusterConfig, void(ProbeClusterConfig));
MOCK_METHOD1(OnTargetTransferRate, void(TargetTransferRate));
};
} // namespace
class ProbeControllerTest : public ::testing::Test {
protected:
ProbeControllerTest() : clock_(100000000L) {
probe_controller_.reset(new ProbeController(&cluster_handler_));
probe_controller_.reset(new ProbeController(&pacer_, &clock_));
}
~ProbeControllerTest() override {}
void SetNetworkAvailable(bool available) {
NetworkAvailability msg;
msg.at_time = Timestamp::ms(clock_.TimeInMicroseconds());
msg.network_available = available;
probe_controller_->OnNetworkAvailability(msg);
}
int64_t NowMs() { return clock_.TimeInMilliseconds(); }
SimulatedClock clock_;
NiceMock<MockNetworkControllerObserver> cluster_handler_;
NiceMock<MockPacedSender> pacer_;
std::unique_ptr<ProbeController> probe_controller_;
};
TEST_F(ProbeControllerTest, InitiatesProbingAtStart) {
EXPECT_CALL(cluster_handler_, OnProbeClusterConfig(_)).Times(AtLeast(2));
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(AtLeast(2));
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
kMaxBitrateBps, NowMs());
kMaxBitrateBps);
}
TEST_F(ProbeControllerTest, ProbeOnlyWhenNetworkIsUp) {
SetNetworkAvailable(false);
EXPECT_CALL(cluster_handler_, OnProbeClusterConfig(_)).Times(0);
probe_controller_->OnNetworkStateChanged(kNetworkDown);
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0);
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
kMaxBitrateBps, NowMs());
kMaxBitrateBps);
testing::Mock::VerifyAndClearExpectations(&cluster_handler_);
EXPECT_CALL(cluster_handler_, OnProbeClusterConfig(_)).Times(AtLeast(2));
SetNetworkAvailable(true);
testing::Mock::VerifyAndClearExpectations(&pacer_);
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(AtLeast(2));
probe_controller_->OnNetworkStateChanged(kNetworkUp);
}
TEST_F(ProbeControllerTest, InitiatesProbingOnMaxBitrateIncrease) {
EXPECT_CALL(cluster_handler_, OnProbeClusterConfig(_)).Times(AtLeast(2));
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(AtLeast(2));
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
kMaxBitrateBps, NowMs());
kMaxBitrateBps);
// Long enough to time out exponential probing.
clock_.AdvanceTimeMilliseconds(kExponentialProbingTimeoutMs);
probe_controller_->SetEstimatedBitrate(kStartBitrateBps, NowMs());
probe_controller_->Process(NowMs());
probe_controller_->SetEstimatedBitrate(kStartBitrateBps);
probe_controller_->Process();
EXPECT_CALL(cluster_handler_,
OnProbeClusterConfig(DataRateEqBps(kMaxBitrateBps + 100)));
EXPECT_CALL(pacer_, CreateProbeCluster(kMaxBitrateBps + 100));
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
kMaxBitrateBps + 100, NowMs());
kMaxBitrateBps + 100);
}
TEST_F(ProbeControllerTest, InitiatesProbingOnMaxBitrateIncreaseAtMaxBitrate) {
EXPECT_CALL(cluster_handler_, OnProbeClusterConfig(_)).Times(AtLeast(2));
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(AtLeast(2));
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
kMaxBitrateBps, NowMs());
kMaxBitrateBps);
// Long enough to time out exponential probing.
clock_.AdvanceTimeMilliseconds(kExponentialProbingTimeoutMs);
probe_controller_->SetEstimatedBitrate(kStartBitrateBps, NowMs());
probe_controller_->Process(NowMs());
probe_controller_->SetEstimatedBitrate(kStartBitrateBps);
probe_controller_->Process();
probe_controller_->SetEstimatedBitrate(kMaxBitrateBps, NowMs());
EXPECT_CALL(cluster_handler_,
OnProbeClusterConfig(DataRateEqBps(kMaxBitrateBps + 100)));
probe_controller_->SetEstimatedBitrate(kMaxBitrateBps);
EXPECT_CALL(pacer_, CreateProbeCluster(kMaxBitrateBps + 100));
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
kMaxBitrateBps + 100, NowMs());
kMaxBitrateBps + 100);
}
TEST_F(ProbeControllerTest, TestExponentialProbing) {
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
kMaxBitrateBps, NowMs());
kMaxBitrateBps);
// Repeated probe should only be sent when estimated bitrate climbs above
// 0.7 * 6 * kStartBitrateBps = 1260.
EXPECT_CALL(cluster_handler_, OnProbeClusterConfig(_)).Times(0);
probe_controller_->SetEstimatedBitrate(1000, NowMs());
testing::Mock::VerifyAndClearExpectations(&cluster_handler_);
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0);
probe_controller_->SetEstimatedBitrate(1000);
testing::Mock::VerifyAndClearExpectations(&pacer_);
EXPECT_CALL(cluster_handler_, OnProbeClusterConfig(DataRateEqBps(2 * 1800)));
probe_controller_->SetEstimatedBitrate(1800, NowMs());
EXPECT_CALL(pacer_, CreateProbeCluster(2 * 1800));
probe_controller_->SetEstimatedBitrate(1800);
}
TEST_F(ProbeControllerTest, TestExponentialProbingTimeout) {
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
kMaxBitrateBps, NowMs());
kMaxBitrateBps);
// Advance far enough to cause a time out in waiting for probing result.
clock_.AdvanceTimeMilliseconds(kExponentialProbingTimeoutMs);
probe_controller_->Process(NowMs());
probe_controller_->Process();
EXPECT_CALL(cluster_handler_, OnProbeClusterConfig(_)).Times(0);
probe_controller_->SetEstimatedBitrate(1800, NowMs());
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0);
probe_controller_->SetEstimatedBitrate(1800);
}
TEST_F(ProbeControllerTest, RequestProbeInAlr) {
EXPECT_CALL(cluster_handler_, OnProbeClusterConfig(_)).Times(2);
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2);
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
kMaxBitrateBps, NowMs());
probe_controller_->SetEstimatedBitrate(500, NowMs());
testing::Mock::VerifyAndClearExpectations(&cluster_handler_);
EXPECT_CALL(cluster_handler_, OnProbeClusterConfig(DataRateEqBps(0.85 * 500)))
.Times(1);
probe_controller_->SetAlrStartTimeMs(clock_.TimeInMilliseconds());
kMaxBitrateBps);
probe_controller_->SetEstimatedBitrate(500);
testing::Mock::VerifyAndClearExpectations(&pacer_);
EXPECT_CALL(pacer_, CreateProbeCluster(0.85 * 500)).Times(1);
EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime())
.WillRepeatedly(Return(clock_.TimeInMilliseconds()));
clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1);
probe_controller_->Process(NowMs());
probe_controller_->SetEstimatedBitrate(250, NowMs());
probe_controller_->RequestProbe(NowMs());
probe_controller_->Process();
probe_controller_->SetEstimatedBitrate(250);
probe_controller_->RequestProbe();
}
TEST_F(ProbeControllerTest, RequestProbeWhenAlrEndedRecently) {
EXPECT_CALL(cluster_handler_, OnProbeClusterConfig(_)).Times(2);
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2);
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
kMaxBitrateBps, NowMs());
probe_controller_->SetEstimatedBitrate(500, NowMs());
testing::Mock::VerifyAndClearExpectations(&cluster_handler_);
EXPECT_CALL(cluster_handler_, OnProbeClusterConfig(DataRateEqBps(0.85 * 500)))
.Times(1);
probe_controller_->SetAlrStartTimeMs(rtc::nullopt);
kMaxBitrateBps);
probe_controller_->SetEstimatedBitrate(500);
testing::Mock::VerifyAndClearExpectations(&pacer_);
EXPECT_CALL(pacer_, CreateProbeCluster(0.85 * 500)).Times(1);
EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime())
.WillRepeatedly(Return(rtc::nullopt));
clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1);
probe_controller_->Process(NowMs());
probe_controller_->SetEstimatedBitrate(250, NowMs());
probe_controller_->Process();
probe_controller_->SetEstimatedBitrate(250);
probe_controller_->SetAlrEndedTimeMs(clock_.TimeInMilliseconds());
clock_.AdvanceTimeMilliseconds(kAlrEndedTimeoutMs - 1);
probe_controller_->RequestProbe(NowMs());
probe_controller_->RequestProbe();
}
TEST_F(ProbeControllerTest, RequestProbeWhenAlrNotEndedRecently) {
EXPECT_CALL(cluster_handler_, OnProbeClusterConfig(_)).Times(2);
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2);
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
kMaxBitrateBps, NowMs());
probe_controller_->SetEstimatedBitrate(500, NowMs());
testing::Mock::VerifyAndClearExpectations(&cluster_handler_);
EXPECT_CALL(cluster_handler_, OnProbeClusterConfig(_)).Times(0);
probe_controller_->SetAlrStartTimeMs(rtc::nullopt);
kMaxBitrateBps);
probe_controller_->SetEstimatedBitrate(500);
testing::Mock::VerifyAndClearExpectations(&pacer_);
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0);
EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime())
.WillRepeatedly(Return(rtc::nullopt));
clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1);
probe_controller_->Process(NowMs());
probe_controller_->SetEstimatedBitrate(250, NowMs());
probe_controller_->Process();
probe_controller_->SetEstimatedBitrate(250);
probe_controller_->SetAlrEndedTimeMs(clock_.TimeInMilliseconds());
clock_.AdvanceTimeMilliseconds(kAlrEndedTimeoutMs + 1);
probe_controller_->RequestProbe(NowMs());
probe_controller_->RequestProbe();
}
TEST_F(ProbeControllerTest, RequestProbeWhenBweDropNotRecent) {
EXPECT_CALL(cluster_handler_, OnProbeClusterConfig(_)).Times(2);
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2);
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
kMaxBitrateBps, NowMs());
probe_controller_->SetEstimatedBitrate(500, NowMs());
testing::Mock::VerifyAndClearExpectations(&cluster_handler_);
EXPECT_CALL(cluster_handler_, OnProbeClusterConfig(_)).Times(0);
probe_controller_->SetAlrStartTimeMs(clock_.TimeInMilliseconds());
kMaxBitrateBps);
probe_controller_->SetEstimatedBitrate(500);
testing::Mock::VerifyAndClearExpectations(&pacer_);
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0);
EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime())
.WillRepeatedly(Return(clock_.TimeInMilliseconds()));
clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1);
probe_controller_->Process(NowMs());
probe_controller_->SetEstimatedBitrate(250, NowMs());
probe_controller_->Process();
probe_controller_->SetEstimatedBitrate(250);
clock_.AdvanceTimeMilliseconds(kBitrateDropTimeoutMs + 1);
probe_controller_->RequestProbe(NowMs());
probe_controller_->RequestProbe();
}
TEST_F(ProbeControllerTest, PeriodicProbing) {
EXPECT_CALL(cluster_handler_, OnProbeClusterConfig(_)).Times(2);
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2);
probe_controller_->EnablePeriodicAlrProbing(true);
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
kMaxBitrateBps, NowMs());
probe_controller_->SetEstimatedBitrate(500, NowMs());
testing::Mock::VerifyAndClearExpectations(&cluster_handler_);
kMaxBitrateBps);
probe_controller_->SetEstimatedBitrate(500);
testing::Mock::VerifyAndClearExpectations(&pacer_);
int64_t start_time = clock_.TimeInMilliseconds();
// Expect the controller to send a new probe after 5s has passed.
EXPECT_CALL(cluster_handler_, OnProbeClusterConfig(DataRateEqBps(1000)))
.Times(1);
probe_controller_->SetAlrStartTimeMs(start_time);
EXPECT_CALL(pacer_, CreateProbeCluster(1000)).Times(1);
EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime())
.WillRepeatedly(Return(start_time));
clock_.AdvanceTimeMilliseconds(5000);
probe_controller_->Process(NowMs());
probe_controller_->SetEstimatedBitrate(500, NowMs());
testing::Mock::VerifyAndClearExpectations(&cluster_handler_);
probe_controller_->Process();
probe_controller_->SetEstimatedBitrate(500);
testing::Mock::VerifyAndClearExpectations(&pacer_);
// The following probe should be sent at 10s into ALR.
EXPECT_CALL(cluster_handler_, OnProbeClusterConfig(_)).Times(0);
probe_controller_->SetAlrStartTimeMs(start_time);
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0);
EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime())
.WillRepeatedly(Return(start_time));
clock_.AdvanceTimeMilliseconds(4000);
probe_controller_->Process(NowMs());
probe_controller_->SetEstimatedBitrate(500, NowMs());
testing::Mock::VerifyAndClearExpectations(&cluster_handler_);
probe_controller_->Process();
probe_controller_->SetEstimatedBitrate(500);
testing::Mock::VerifyAndClearExpectations(&pacer_);
EXPECT_CALL(cluster_handler_, OnProbeClusterConfig(_)).Times(1);
probe_controller_->SetAlrStartTimeMs(start_time);
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(1);
EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime())
.WillRepeatedly(Return(start_time));
clock_.AdvanceTimeMilliseconds(1000);
probe_controller_->Process(NowMs());
probe_controller_->SetEstimatedBitrate(500, NowMs());
testing::Mock::VerifyAndClearExpectations(&cluster_handler_);
probe_controller_->Process();
probe_controller_->SetEstimatedBitrate(500);
testing::Mock::VerifyAndClearExpectations(&pacer_);
}
TEST_F(ProbeControllerTest, PeriodicProbingAfterReset) {
NiceMock<MockNetworkControllerObserver> local_handler;
probe_controller_.reset(new ProbeController(&local_handler));
testing::StrictMock<MockPacedSender> local_pacer;
probe_controller_.reset(new ProbeController(&local_pacer, &clock_));
int64_t alr_start_time = clock_.TimeInMilliseconds();
EXPECT_CALL(local_pacer, GetApplicationLimitedRegionStartTime())
.WillRepeatedly(Return(alr_start_time));
probe_controller_->SetAlrStartTimeMs(alr_start_time);
EXPECT_CALL(local_handler, OnProbeClusterConfig(_)).Times(2);
EXPECT_CALL(local_pacer, CreateProbeCluster(_)).Times(2);
probe_controller_->EnablePeriodicAlrProbing(true);
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
kMaxBitrateBps, NowMs());
probe_controller_->Reset(NowMs());
kMaxBitrateBps);
probe_controller_->Reset();
clock_.AdvanceTimeMilliseconds(10000);
probe_controller_->Process(NowMs());
probe_controller_->Process();
EXPECT_CALL(local_handler, OnProbeClusterConfig(_)).Times(2);
EXPECT_CALL(local_pacer, CreateProbeCluster(_)).Times(2);
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
kMaxBitrateBps, NowMs());
kMaxBitrateBps);
// Make sure we use |kStartBitrateBps| as the estimated bitrate
// until SetEstimatedBitrate is called with an updated estimate.
clock_.AdvanceTimeMilliseconds(10000);
EXPECT_CALL(local_handler,
OnProbeClusterConfig(DataRateEqBps(kStartBitrateBps * 2)));
probe_controller_->Process(NowMs());
EXPECT_CALL(local_pacer, CreateProbeCluster(kStartBitrateBps*2));
probe_controller_->Process();
}
TEST_F(ProbeControllerTest, TestExponentialProbingOverflow) {
const int64_t kMbpsMultiplier = 1000000;
probe_controller_->SetBitrates(kMinBitrateBps, 10 * kMbpsMultiplier,
100 * kMbpsMultiplier, NowMs());
100 * kMbpsMultiplier);
// Verify that probe bitrate is capped at the specified max bitrate.
EXPECT_CALL(cluster_handler_,
OnProbeClusterConfig(DataRateEqBps(100 * kMbpsMultiplier)));
probe_controller_->SetEstimatedBitrate(60 * kMbpsMultiplier, NowMs());
testing::Mock::VerifyAndClearExpectations(&cluster_handler_);
// Verify that probe bitrate is capped at the specified max bitrate
EXPECT_CALL(pacer_, CreateProbeCluster(100 * kMbpsMultiplier));
probe_controller_->SetEstimatedBitrate(60 * kMbpsMultiplier);
testing::Mock::VerifyAndClearExpectations(&pacer_);
// Verify that repeated probes aren't sent.
EXPECT_CALL(cluster_handler_, OnProbeClusterConfig(_)).Times(0);
probe_controller_->SetEstimatedBitrate(100 * kMbpsMultiplier, NowMs());
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0);
probe_controller_->SetEstimatedBitrate(100 * kMbpsMultiplier);
}
} // namespace test