Commit 5e728e25 authored by Yutaka Hirano's avatar Yutaka Hirano Committed by Commit Bot

ResourceLoadScheduler should work with multiple experiments

We have two experiments, and currently enabling both would confuse
ResourceLoadScheduler. This CL fixes that.

Bug: 785770
Change-Id: Iedcd31b85b83dae8397c992e3c769addd9dba956
Reviewed-on: https://chromium-review.googlesource.com/816775
Commit-Queue: Yutaka Hirano <yhirano@chromium.org>
Reviewed-by: default avatarTakashi Toyoshima <toyoshim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523390}
parent ee522f0c
...@@ -86,9 +86,12 @@ uint32_t GetFieldTrialUint32Param(const char* trial_name, ...@@ -86,9 +86,12 @@ uint32_t GetFieldTrialUint32Param(const char* trial_name,
return param; return param;
} }
uint32_t GetOutstandingThrottledLimit(FetchContext* context) { size_t GetOutstandingThrottledLimit(FetchContext* context) {
DCHECK(context); DCHECK(context);
if (!RuntimeEnabledFeatures::ResourceLoadSchedulerEnabled())
return ResourceLoadScheduler::kOutstandingUnlimited;
uint32_t main_frame_limit = GetFieldTrialUint32Param( uint32_t main_frame_limit = GetFieldTrialUint32Param(
kResourceLoadSchedulerTrial, kOutstandingLimitForBackgroundMainFrameName, kResourceLoadSchedulerTrial, kOutstandingLimitForBackgroundMainFrameName,
kOutstandingLimitForBackgroundFrameDefault); kOutstandingLimitForBackgroundFrameDefault);
...@@ -335,7 +338,8 @@ constexpr ResourceLoadScheduler::ClientId ...@@ -335,7 +338,8 @@ constexpr ResourceLoadScheduler::ClientId
ResourceLoadScheduler::kInvalidClientId; ResourceLoadScheduler::kInvalidClientId;
ResourceLoadScheduler::ResourceLoadScheduler(FetchContext* context) ResourceLoadScheduler::ResourceLoadScheduler(FetchContext* context)
: outstanding_throttled_limit_(GetOutstandingThrottledLimit(context)), : outstanding_limit_for_throttled_frame_scheduler_(
GetOutstandingThrottledLimit(context)),
context_(context) { context_(context) {
traffic_monitor_ = std::make_unique<ResourceLoadScheduler::TrafficMonitor>( traffic_monitor_ = std::make_unique<ResourceLoadScheduler::TrafficMonitor>(
context_->IsMainFrame()); context_->IsMainFrame());
...@@ -351,7 +355,7 @@ ResourceLoadScheduler::ResourceLoadScheduler(FetchContext* context) ...@@ -351,7 +355,7 @@ ResourceLoadScheduler::ResourceLoadScheduler(FetchContext* context)
if (Platform::Current()->IsRendererSideResourceSchedulerEnabled()) { if (Platform::Current()->IsRendererSideResourceSchedulerEnabled()) {
policy_ = context->InitialLoadThrottlingPolicy(); policy_ = context->InitialLoadThrottlingPolicy();
outstanding_limit_ = normal_outstanding_limit_ =
GetFieldTrialUint32Param(kRendererSideResourceScheduler, GetFieldTrialUint32Param(kRendererSideResourceScheduler,
kLimitForRendererSideResourceSchedulerName, kLimitForRendererSideResourceSchedulerName,
kLimitForRendererSideResourceScheduler); kLimitForRendererSideResourceScheduler);
...@@ -489,9 +493,9 @@ bool ResourceLoadScheduler::Release( ...@@ -489,9 +493,9 @@ bool ResourceLoadScheduler::Release(
} }
void ResourceLoadScheduler::SetOutstandingLimitForTesting(size_t tight_limit, void ResourceLoadScheduler::SetOutstandingLimitForTesting(size_t tight_limit,
size_t limit) { size_t normal_limit) {
tight_outstanding_limit_ = tight_limit; tight_outstanding_limit_ = tight_limit;
outstanding_limit_ = limit; normal_outstanding_limit_ = normal_limit;
MaybeRun(); MaybeRun();
} }
...@@ -592,20 +596,18 @@ void ResourceLoadScheduler::OnThrottlingStateChanged( ...@@ -592,20 +596,18 @@ void ResourceLoadScheduler::OnThrottlingStateChanged(
throttling_history_ = ThrottlingHistory::kThrottled; throttling_history_ = ThrottlingHistory::kThrottled;
else if (throttling_history_ == ThrottlingHistory::kNotThrottled) else if (throttling_history_ == ThrottlingHistory::kNotThrottled)
throttling_history_ = ThrottlingHistory::kPartiallyThrottled; throttling_history_ = ThrottlingHistory::kPartiallyThrottled;
SetOutstandingLimitAndMaybeRun(outstanding_throttled_limit_);
break; break;
case WebFrameScheduler::ThrottlingState::kNotThrottled: case WebFrameScheduler::ThrottlingState::kNotThrottled:
if (throttling_history_ == ThrottlingHistory::kInitial) if (throttling_history_ == ThrottlingHistory::kInitial)
throttling_history_ = ThrottlingHistory::kNotThrottled; throttling_history_ = ThrottlingHistory::kNotThrottled;
else if (throttling_history_ == ThrottlingHistory::kThrottled) else if (throttling_history_ == ThrottlingHistory::kThrottled)
throttling_history_ = ThrottlingHistory::kPartiallyThrottled; throttling_history_ = ThrottlingHistory::kPartiallyThrottled;
SetOutstandingLimitAndMaybeRun(kOutstandingUnlimited);
break; break;
case WebFrameScheduler::ThrottlingState::kStopped: case WebFrameScheduler::ThrottlingState::kStopped:
throttling_history_ = ThrottlingHistory::kStopped; throttling_history_ = ThrottlingHistory::kStopped;
SetOutstandingLimitAndMaybeRun(0u);
break; break;
} }
MaybeRun();
} }
ResourceLoadScheduler::ClientId ResourceLoadScheduler::GenerateClientId() { ResourceLoadScheduler::ClientId ResourceLoadScheduler::GenerateClientId() {
...@@ -621,18 +623,9 @@ void ResourceLoadScheduler::MaybeRun() { ...@@ -621,18 +623,9 @@ void ResourceLoadScheduler::MaybeRun() {
return; return;
while (!pending_requests_.empty()) { while (!pending_requests_.empty()) {
bool has_enough_running_requets = false; const bool has_enough_running_requets =
running_requests_.size() >= GetOutstandingLimit();
switch (policy_) {
case ThrottlingPolicy::kTight:
if (running_requests_.size() >= tight_outstanding_limit_)
has_enough_running_requets = true;
break;
case ThrottlingPolicy::kNormal:
if (running_requests_.size() >= outstanding_limit_)
has_enough_running_requets = true;
break;
}
if (IsThrottablePriority(pending_requests_.begin()->priority) && if (IsThrottablePriority(pending_requests_.begin()->priority) &&
has_enough_running_requets) { has_enough_running_requets) {
break; break;
...@@ -662,9 +655,30 @@ void ResourceLoadScheduler::Run(ResourceLoadScheduler::ClientId id, ...@@ -662,9 +655,30 @@ void ResourceLoadScheduler::Run(ResourceLoadScheduler::ClientId id,
client->Run(); client->Run();
} }
void ResourceLoadScheduler::SetOutstandingLimitAndMaybeRun(size_t limit) { size_t ResourceLoadScheduler::GetOutstandingLimit() const {
outstanding_limit_ = limit; size_t limit = kOutstandingUnlimited;
MaybeRun();
switch (frame_scheduler_throttling_state_) {
case WebFrameScheduler::ThrottlingState::kThrottled:
limit = std::min(limit, outstanding_limit_for_throttled_frame_scheduler_);
break;
case WebFrameScheduler::ThrottlingState::kNotThrottled:
break;
case WebFrameScheduler::ThrottlingState::kStopped:
if (RuntimeEnabledFeatures::ResourceLoadSchedulerEnabled())
limit = 0;
break;
}
switch (policy_) {
case ThrottlingPolicy::kTight:
limit = std::min(limit, tight_outstanding_limit_);
break;
case ThrottlingPolicy::kNormal:
limit = std::min(limit, normal_outstanding_limit_);
break;
}
return limit;
} }
} // namespace blink } // namespace blink
...@@ -53,7 +53,7 @@ class PLATFORM_EXPORT ResourceLoadSchedulerClient ...@@ -53,7 +53,7 @@ class PLATFORM_EXPORT ResourceLoadSchedulerClient
// SetPriority(). // SetPriority().
// - A ResourceLoadScheulder won't initiate a new resource loading which can // - A ResourceLoadScheulder won't initiate a new resource loading which can
// be throttable when there are active resource loading activities more than // be throttable when there are active resource loading activities more than
// its internal threshold. // its internal threshold (i.e., what GetOutstandingLimit() returns)".
// //
// By default, ResourceLoadScheduler is disabled, which means it doesn't // By default, ResourceLoadScheduler is disabled, which means it doesn't
// throttle any resource loading requests. // throttle any resource loading requests.
...@@ -182,7 +182,7 @@ class PLATFORM_EXPORT ResourceLoadScheduler final ...@@ -182,7 +182,7 @@ class PLATFORM_EXPORT ResourceLoadScheduler final
void SetOutstandingLimitForTesting(size_t limit) { void SetOutstandingLimitForTesting(size_t limit) {
SetOutstandingLimitForTesting(limit, limit); SetOutstandingLimitForTesting(limit, limit);
} }
void SetOutstandingLimitForTesting(size_t tight_limit, size_t limit); void SetOutstandingLimitForTesting(size_t tight_limit, size_t normal_limit);
void OnNetworkQuiet(); void OnNetworkQuiet();
...@@ -245,7 +245,7 @@ class PLATFORM_EXPORT ResourceLoadScheduler final ...@@ -245,7 +245,7 @@ class PLATFORM_EXPORT ResourceLoadScheduler final
// Grants a client to run, // Grants a client to run,
void Run(ClientId, ResourceLoadSchedulerClient*); void Run(ClientId, ResourceLoadSchedulerClient*);
void SetOutstandingLimitAndMaybeRun(size_t limit); size_t GetOutstandingLimit() const;
// A flag to indicate an internal running state. // A flag to indicate an internal running state.
// TODO(toyoshim): We may want to use enum once we start to have more states. // TODO(toyoshim): We may want to use enum once we start to have more states.
...@@ -257,16 +257,18 @@ class PLATFORM_EXPORT ResourceLoadScheduler final ...@@ -257,16 +257,18 @@ class PLATFORM_EXPORT ResourceLoadScheduler final
ThrottlingPolicy policy_ = ThrottlingPolicy::kNormal; ThrottlingPolicy policy_ = ThrottlingPolicy::kNormal;
// Used to limit outstanding requests when |policy_| is kTight. // ResourceLoadScheduler threshold values for various circumstances. Some
// conditions can overlap, and ResourceLoadScheduler chooses the smallest
// value in such cases.
// Used when |policy_| is |kTight|.
size_t tight_outstanding_limit_ = kOutstandingUnlimited; size_t tight_outstanding_limit_ = kOutstandingUnlimited;
// TODO(crbug.com/735410): If this throttling is enabled always, it makes some // Used when |policy_| is |kNormal|.
// tests fail. size_t normal_outstanding_limit_ = kOutstandingUnlimited;
// Used to limit outstanding requests when |policy_| is kNormal.
size_t outstanding_limit_ = kOutstandingUnlimited;
// Outstanding limit for throttled frames. Managed via the field trial. // Used when |frame_scheduler_throttling_state_| is |kThrottled|.
const size_t outstanding_throttled_limit_; const size_t outstanding_limit_for_throttled_frame_scheduler_;
// The last used ClientId to calculate the next. // The last used ClientId to calculate the next.
ClientId current_id_ = kInvalidClientId; ClientId current_id_ = kInvalidClientId;
......
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