Commit 48475f48 authored by dougarnett's avatar dougarnett Committed by Commit bot

[Offline Pages] Defines longer processing budget for immediate bg loads.

BUG=655341

Review-Url: https://codereview.chromium.org/2431193003
Cr-Commit-Position: refs/heads/master@{#427098}
parent 8e100e89
......@@ -8,10 +8,23 @@
namespace {
const int kMaxStartedTries = 4;
const int kMaxCompletedTries = 1;
const int kDefaultBackgroundProcessingTimeBudgetSeconds = 170;
const int kSinglePageTimeLimitWhenBackgroundScheduledSeconds = 120;
const int kSinglePageTimeLimitForImmediateLoadSeconds = 300;
const int kRequestExpirationTimeInSeconds = 60 * 60 * 24 * 7;
// Scheduled background processing time limits.
const int kDozeModeBackgroundServiceWindowSeconds = 60 * 3;
const int kDefaultBackgroundProcessingTimeBudgetSeconds =
kDozeModeBackgroundServiceWindowSeconds - 10;
const int kSinglePageTimeLimitWhenBackgroundScheduledSeconds =
kDozeModeBackgroundServiceWindowSeconds - 10;
// Immediate processing time limits.
// Note: experiments on GIN-2g-poor show many page requests took 3 or 4
// attempts in background scheduled mode with timeout of 2 minutes. So for
// immediate processing mode, give page requests 4 times that limit (8 min).
// Then budget up to 5 of those requests in processing window.
const int kSinglePageTimeLimitForImmediateLoadSeconds = 60 * 8;
const int kImmediateLoadProcessingTimeBudgetSeconds =
kSinglePageTimeLimitForImmediateLoadSeconds * 5;
} // namespace
namespace offline_pages {
......@@ -26,7 +39,7 @@ class OfflinerPolicy {
retry_count_is_more_important_than_recency_(false),
max_started_tries_(kMaxStartedTries),
max_completed_tries_(kMaxCompletedTries),
background_processing_time_budget_(
background_scheduled_processing_time_budget_(
kDefaultBackgroundProcessingTimeBudgetSeconds) {}
// Constructor for unit tests.
......@@ -41,7 +54,8 @@ class OfflinerPolicy {
retry_count_is_more_important_than_recency_(prefer_retry_count),
max_started_tries_(max_started_tries),
max_completed_tries_(max_completed_tries),
background_processing_time_budget_(background_processing_time_budget) {}
background_scheduled_processing_time_budget_(
background_processing_time_budget) {}
// TODO(petewil): Numbers here are chosen arbitrarily, do the proper studies
// to get good policy numbers. Eventually this should get data from a finch
......@@ -85,10 +99,18 @@ class OfflinerPolicy {
return 25;
}
// How many seconds to keep trying new pages for, before we give up, and
// How many seconds to keep trying new pages for, before we give up, and
// return to the scheduler.
int GetBackgroundProcessingTimeBudgetSeconds() const {
return background_processing_time_budget_;
// TODO(dougarnett): Consider parameterizing these time limit/budget
// calls with processing mode.
int GetProcessingTimeBudgetWhenBackgroundScheduledInSeconds() const {
return background_scheduled_processing_time_budget_;
}
// How many seconds to keep trying new pages for, before we give up, when
// processing started immediately (without scheduler).
int GetProcessingTimeBudgetForImmediateLoadInSeconds() const {
return kImmediateLoadProcessingTimeBudgetSeconds;
}
// How long do we allow a page to load before giving up on it when
......@@ -114,7 +136,7 @@ class OfflinerPolicy {
bool retry_count_is_more_important_than_recency_;
int max_started_tries_;
int max_completed_tries_;
int background_processing_time_budget_;
int background_scheduled_processing_time_budget_;
};
} // namespace offline_pages
......
......@@ -122,7 +122,8 @@ RequestCoordinator::RequestCoordinator(
std::unique_ptr<Scheduler> scheduler,
net::NetworkQualityEstimator::NetworkQualityProvider*
network_quality_estimator)
: is_busy_(false),
: is_low_end_device_(base::SysInfo::IsLowEndDevice()),
is_busy_(false),
is_starting_(false),
processing_state_(ProcessingWindowState::STOPPED),
use_test_connection_type_(false),
......@@ -468,8 +469,8 @@ RequestCoordinator::TryImmediateStart() {
return OfflinerImmediateStartStatus::BUSY;
// Make sure we are not on svelte device to start immediately.
// Let the scheduler know we are done processing and failed due to svelte.
if (base::SysInfo::IsLowEndDevice()) {
if (is_low_end_device_) {
// Let the scheduler know we are done processing and failed due to svelte.
immediate_schedule_callback_.Run(false);
return OfflinerImmediateStartStatus::NOT_STARTED_ON_SVELTE;
}
......@@ -499,13 +500,21 @@ RequestCoordinator::TryImmediateStart() {
}
void RequestCoordinator::TryNextRequest() {
base::TimeDelta processing_time_budget;
if (processing_state_ == ProcessingWindowState::SCHEDULED_WINDOW) {
processing_time_budget = base::TimeDelta::FromSeconds(
policy_->GetProcessingTimeBudgetWhenBackgroundScheduledInSeconds());
} else {
DCHECK(processing_state_ == ProcessingWindowState::IMMEDIATE_WINDOW);
processing_time_budget = base::TimeDelta::FromSeconds(
policy_->GetProcessingTimeBudgetForImmediateLoadInSeconds());
}
// If there is no time left in the budget, return to the scheduler.
// We do not remove the pending task that was set up earlier in case
// we run out of time, so the background scheduler will return to us
// at the next opportunity to run background tasks.
if (base::Time::Now() - operation_start_time_ >
base::TimeDelta::FromSeconds(
policy_->GetBackgroundProcessingTimeBudgetSeconds())) {
if ((base::Time::Now() - operation_start_time_) > processing_time_budget) {
is_starting_ = false;
// Let the scheduler know we are done processing.
......
......@@ -145,6 +145,8 @@ class RequestCoordinator : public KeyedService,
immediate_schedule_callback_ = callback;
}
void StartImmediatelyForTest() { StartImmediatelyIfConnected(); }
// Observers implementing the RequestCoordinator::Observer interface can
// register here to get notifications of changes to request state. This
// pointer is not owned, and it is the callers responsibility to remove the
......@@ -339,6 +341,9 @@ class RequestCoordinator : public KeyedService,
friend class RequestCoordinatorTest;
// Cached value of whether low end device. Overwritable for testing.
bool is_low_end_device_;
// The offliner can only handle one request at a time - if the offliner is
// busy, prevent other requests. This flag marks whether the offliner is in
// use.
......
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