Commit a1562e2e authored by rajendrant's avatar rajendrant Committed by Commit Bot

LiteVideo: Limit maximum active throttles

This CL implements a finchable limit to max number of active throttles.
Once the limit is hit, responses will not be throttled.

Fixed: 1123634
Change-Id: I6475a9d9bbd0977385a412353a93ed60c49299e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2419000
Commit-Queue: rajendrant <rajendrant@chromium.org>
Reviewed-by: default avatarMichael Crouse <mcrouse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808670}
parent fa3dd0b3
......@@ -38,6 +38,9 @@ base::TimeDelta LiteVideoHintAgent::CalculateLatencyForResourceResponse(
if (!HasLiteVideoHint())
return base::TimeDelta();
if (active_throttles_.size() >= GetMaxActiveThrottles())
return base::TimeDelta();
if (ShouldDisableLiteVideoForCacheControlNoTransform() &&
response_head.headers &&
response_head.headers->HasHeaderValue("cache-control", "no-transform")) {
......
......@@ -305,4 +305,52 @@ TEST_F(LiteVideoHintAgentTest, StopThrottlingResumesResponsesImmediately) {
EXPECT_TRUE(GetActiveThrottledResponses().empty());
}
TEST_F(LiteVideoHintAgentTest, RespectsMaxActiveThrottlesLimit) {
histogram_tester().ExpectUniqueSample("LiteVideo.HintAgent.HasHint", true, 1);
// Initial k media bytes will not be throttled.
auto throttle_info =
CreateThrottleAndSendResponse(net::HTTP_OK, "video/mp4", 11000);
EXPECT_FALSE(throttle_info->is_throttled());
histogram_tester().ExpectTotalCount("LiteVideo.URLLoader.ThrottleLatency", 0);
EXPECT_TRUE(GetActiveThrottledResponses().empty());
// First 50 responses will be throttled.
std::deque<std::unique_ptr<MediaLoaderThrottleInfo>> throttles;
for (int i = 0; i < 50; i++) {
throttle_info =
CreateThrottleAndSendResponse(net::HTTP_OK, "video/mp4", 11000);
histogram_tester().ExpectTotalCount("LiteVideo.URLLoader.ThrottleLatency",
i + 1);
EXPECT_TRUE(throttle_info->is_throttled());
throttles.push_back(std::move(throttle_info));
}
// The next response hits the MaxActiveThrottles limit and won't be throttled.
throttle_info =
CreateThrottleAndSendResponse(net::HTTP_OK, "video/mp4", 11000);
histogram_tester().ExpectTotalCount("LiteVideo.URLLoader.ThrottleLatency",
50);
EXPECT_FALSE(throttle_info->is_throttled());
// Release a response from throttling.
throttles.front().reset();
throttles.pop_front();
base::RunLoop().RunUntilIdle();
// The next response is below the MaxActiveThrottles limit and gets throttled.
throttle_info =
CreateThrottleAndSendResponse(net::HTTP_OK, "video/mp4", 11000);
histogram_tester().ExpectTotalCount("LiteVideo.URLLoader.ThrottleLatency",
51);
EXPECT_TRUE(throttle_info->is_throttled());
task_environment_.FastForwardBy(base::TimeDelta::FromSeconds(50));
base::RunLoop().RunUntilIdle();
for (const auto& throttle : throttles) {
EXPECT_FALSE(throttle->is_throttled());
}
EXPECT_FALSE(throttle_info->is_throttled());
}
} // namespace lite_video
......@@ -24,4 +24,9 @@ bool ShouldThrottleLiteVideoMissingContentLength() {
::features::kLiteVideo, "throttle_missing_content_length", false);
}
size_t GetMaxActiveThrottles() {
return base::GetFieldTrialParamByFeatureAsInt(::features::kLiteVideo,
"max_active_throttles", 50);
}
} // namespace lite_video
......@@ -5,6 +5,8 @@
#ifndef CHROME_RENDERER_LITE_VIDEO_LITE_VIDEO_UTIL_H_
#define CHROME_RENDERER_LITE_VIDEO_LITE_VIDEO_UTIL_H_
#include <stddef.h>
namespace lite_video {
// Returns whether LiteVideo is enabled.
......@@ -17,6 +19,9 @@ bool ShouldDisableLiteVideoForCacheControlNoTransform();
// Returns whether LiteVideo should throttle responses without content-length.
bool ShouldThrottleLiteVideoMissingContentLength();
// Returns the maximum active throttles size.
size_t GetMaxActiveThrottles();
} // namespace lite_video
#endif // CHROME_RENDERER_LITE_VIDEO_LITE_VIDEO_UTIL_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment