Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(755)

Unified Diff: content/browser/loader/resource_scheduler_unittest.cc

Issue 1230133005: Fix Resource Priorities and Scheduling (Chrome Side) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes from review feedback Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/loader/resource_scheduler_unittest.cc
diff --git a/content/browser/loader/resource_scheduler_unittest.cc b/content/browser/loader/resource_scheduler_unittest.cc
index 3ac956667bfdafb138962616a723766662ad8c10..fd60100167fb645171cfe04bf79236420a4b13d8 100644
--- a/content/browser/loader/resource_scheduler_unittest.cc
+++ b/content/browser/loader/resource_scheduler_unittest.cc
@@ -2360,6 +2360,344 @@ TEST_F(ResourceSchedulerTest, RequestStartedAfterClientDeletedManyDelayable) {
EXPECT_TRUE(lowest->started());
}
+TEST_F(ResourceSchedulerTest, DefaultLayoutBlockingPriority) {
+ const int kDeferLateScripts = 0;
+ const int kIncreaseFontPriority = 0;
+ const int kIncreaseAsyncScriptPriority = 0;
+ const int kEnablePriorityIncrease = 0;
+ const int kEnableLayoutBlockingThreshold = 0;
+ const int kLayoutBlockingThreshold = 0;
+ const int kMaxNumDelayableWhileLayoutBlocking = 1;
+ const int kMaxNumDelayableRequestsPerClient = 10;
+ ASSERT_TRUE(InitializeFieldTrials(base::StringPrintf(
+ "ResourcePriorities/LayoutBlocking_%d%d%d%d%d_%d_%d_%d/",
+ kDeferLateScripts,
+ kIncreaseFontPriority,
+ kIncreaseAsyncScriptPriority,
+ kEnablePriorityIncrease,
+ kEnableLayoutBlockingThreshold,
+ kLayoutBlockingThreshold,
+ kMaxNumDelayableWhileLayoutBlocking,
+ kMaxNumDelayableRequestsPerClient)));
+ InitializeScheduler();
+ scoped_ptr<TestRequest> high(
+ NewRequest("http://hosthigh/high", net::HIGHEST));
+ scoped_ptr<TestRequest> high2(
+ NewRequest("http://hosthigh/high", net::HIGHEST));
+ scoped_ptr<TestRequest> medium(
+ NewRequest("http://hostmedium/medium", net::MEDIUM));
+ scoped_ptr<TestRequest> medium2(
+ NewRequest("http://hostmedium/medium", net::MEDIUM));
+ scoped_ptr<TestRequest> low(NewRequest("http://hostlow/low", net::LOW));
+ scoped_ptr<TestRequest> low2(NewRequest("http://hostlow/low", net::LOW));
+ scoped_ptr<TestRequest> lowest(NewRequest("http://hostlowest/lowest", net::LOWEST));
+ scoped_ptr<TestRequest> lowest2(
+ NewRequest("http://hostlowest/lowest", net::LOWEST));
+ EXPECT_TRUE(high->started());
+ EXPECT_TRUE(high2->started());
+ EXPECT_TRUE(medium->started());
+ EXPECT_TRUE(medium2->started());
+ EXPECT_TRUE(low->started());
+ EXPECT_TRUE(low2->started());
+ EXPECT_TRUE(lowest->started());
+ EXPECT_FALSE(lowest2->started());
+ lowest.reset();
+ EXPECT_TRUE(lowest2->started());
+}
+
+TEST_F(ResourceSchedulerTest, IncreaseLayoutBlockingPriority) {
+ // Changes the level of priorities that are allowed during layout-blocking
+ // from net::LOWEST to net::LOW.
+ const int kDeferLateScripts = 0;
+ const int kIncreaseFontPriority = 0;
+ const int kIncreaseAsyncScriptPriority = 0;
+ const int kEnablePriorityIncrease = 1;
+ const int kEnableLayoutBlockingThreshold = 0;
+ const int kLayoutBlockingThreshold = 0;
+ const int kMaxNumDelayableWhileLayoutBlocking = 1;
+ const int kMaxNumDelayableRequestsPerClient = 10;
+ ASSERT_TRUE(InitializeFieldTrials(base::StringPrintf(
+ "ResourcePriorities/LayoutBlocking_%d%d%d%d%d_%d_%d_%d/",
+ kDeferLateScripts,
+ kIncreaseFontPriority,
+ kIncreaseAsyncScriptPriority,
+ kEnablePriorityIncrease,
+ kEnableLayoutBlockingThreshold,
+ kLayoutBlockingThreshold,
+ kMaxNumDelayableWhileLayoutBlocking,
+ kMaxNumDelayableRequestsPerClient)));
+ InitializeScheduler();
+ scoped_ptr<TestRequest> high(
+ NewRequest("http://hosthigh/high", net::HIGHEST));
+ scoped_ptr<TestRequest> high2(
+ NewRequest("http://hosthigh/high", net::HIGHEST));
+ scoped_ptr<TestRequest> medium(
+ NewRequest("http://hostmedium/medium", net::MEDIUM));
+ scoped_ptr<TestRequest> medium2(
+ NewRequest("http://hostmedium/medium", net::MEDIUM));
+ scoped_ptr<TestRequest> low(NewRequest("http://hostlow/low", net::LOW));
+ scoped_ptr<TestRequest> low2(NewRequest("http://hostlow/low", net::LOW));
+ scoped_ptr<TestRequest> lowest(NewRequest("http://hostlowest/lowest", net::LOWEST));
+ scoped_ptr<TestRequest> lowest2(
+ NewRequest("http://hostlowest/lowest", net::LOWEST));
+ EXPECT_TRUE(high->started());
+ EXPECT_TRUE(high2->started());
+ EXPECT_TRUE(medium->started());
+ EXPECT_TRUE(medium2->started());
+ EXPECT_TRUE(low->started());
+ EXPECT_FALSE(low2->started());
+ EXPECT_FALSE(lowest->started());
+ EXPECT_FALSE(lowest2->started());
+ low.reset();
+ EXPECT_TRUE(low2->started());
+ EXPECT_FALSE(lowest->started());
+ EXPECT_FALSE(lowest2->started());
+ low2.reset();
+ EXPECT_TRUE(lowest->started());
+ EXPECT_FALSE(lowest2->started());
+ lowest.reset();
+ EXPECT_TRUE(lowest2->started());
+}
+
+TEST_F(ResourceSchedulerTest, UseLayoutBlockingThresholdOne) {
+ // Prevents any low priority requests from starting while more than
+ // N high priority requests are pending (before body).
+ const int kDeferLateScripts = 0;
+ const int kIncreaseFontPriority = 0;
+ const int kIncreaseAsyncScriptPriority = 0;
+ const int kEnablePriorityIncrease = 0;
+ const int kEnableLayoutBlockingThreshold = 1;
+ const int kLayoutBlockingThreshold = 1;
+ const int kMaxNumDelayableWhileLayoutBlocking = 1;
+ const int kMaxNumDelayableRequestsPerClient = 10;
+ ASSERT_TRUE(InitializeFieldTrials(base::StringPrintf(
+ "ResourcePriorities/LayoutBlocking_%d%d%d%d%d_%d_%d_%d/",
+ kDeferLateScripts,
+ kIncreaseFontPriority,
+ kIncreaseAsyncScriptPriority,
+ kEnablePriorityIncrease,
+ kEnableLayoutBlockingThreshold,
+ kLayoutBlockingThreshold,
+ kMaxNumDelayableWhileLayoutBlocking,
+ kMaxNumDelayableRequestsPerClient)));
+ InitializeScheduler();
+ scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
+ scoped_ptr<TestRequest> high2(NewRequest("http://host/high", net::HIGHEST));
+ scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
+ scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST));
+ EXPECT_TRUE(high->started());
+ EXPECT_TRUE(high2->started());
+ EXPECT_FALSE(low->started());
+ EXPECT_FALSE(low2->started());
+ high.reset();
+ EXPECT_TRUE(low->started());
+ EXPECT_FALSE(low2->started());
+ high2.reset();
+ EXPECT_FALSE(low2->started());
+ scheduler()->OnWillInsertBody(kChildId, kRouteId);
+ EXPECT_TRUE(low2->started());
+}
+
+TEST_F(ResourceSchedulerTest, UseLayoutBlockingThresholdTwo) {
+ // Prevents any low priority requests from starting while more than
+ // N high priority requests are pending (before body).
+ const int kDeferLateScripts = 0;
+ const int kIncreaseFontPriority = 0;
+ const int kIncreaseAsyncScriptPriority = 0;
+ const int kEnablePriorityIncrease = 0;
+ const int kEnableLayoutBlockingThreshold = 1;
+ const int kLayoutBlockingThreshold = 2;
+ const int kMaxNumDelayableWhileLayoutBlocking = 1;
+ const int kMaxNumDelayableRequestsPerClient = 10;
+ ASSERT_TRUE(InitializeFieldTrials(base::StringPrintf(
+ "ResourcePriorities/LayoutBlocking_%d%d%d%d%d_%d_%d_%d/",
+ kDeferLateScripts,
+ kIncreaseFontPriority,
+ kIncreaseAsyncScriptPriority,
+ kEnablePriorityIncrease,
+ kEnableLayoutBlockingThreshold,
+ kLayoutBlockingThreshold,
+ kMaxNumDelayableWhileLayoutBlocking,
+ kMaxNumDelayableRequestsPerClient)));
+ InitializeScheduler();
+ scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
+ scoped_ptr<TestRequest> high2(NewRequest("http://host/high", net::HIGHEST));
+ scoped_ptr<TestRequest> high3(NewRequest("http://host/high", net::HIGHEST));
+ scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
+ scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST));
+ EXPECT_TRUE(high->started());
+ EXPECT_TRUE(high2->started());
+ EXPECT_TRUE(high3->started());
+ EXPECT_FALSE(low->started());
+ EXPECT_FALSE(low2->started());
+ high.reset();
+ EXPECT_TRUE(low->started());
+ EXPECT_FALSE(low2->started());
+ high2.reset();
+ high3.reset();
+ EXPECT_FALSE(low2->started());
+ scheduler()->OnWillInsertBody(kChildId, kRouteId);
+ EXPECT_TRUE(low2->started());
+}
+
+TEST_F(ResourceSchedulerTest, TwoDelayableLoadsUntilBodyInserted) {
+ // Allow for two low priority requests to be in flight at any point in time
+ // during the layout-blocking phase of loading.
+ const int kDeferLateScripts = 0;
+ const int kIncreaseFontPriority = 0;
+ const int kIncreaseAsyncScriptPriority = 0;
+ const int kEnablePriorityIncrease = 0;
+ const int kEnableLayoutBlockingThreshold = 0;
+ const int kLayoutBlockingThreshold = 0;
+ const int kMaxNumDelayableWhileLayoutBlocking = 2;
+ const int kMaxNumDelayableRequestsPerClient = 10;
+ ASSERT_TRUE(InitializeFieldTrials(base::StringPrintf(
+ "ResourcePriorities/LayoutBlocking_%d%d%d%d%d_%d_%d_%d/",
+ kDeferLateScripts,
+ kIncreaseFontPriority,
+ kIncreaseAsyncScriptPriority,
+ kEnablePriorityIncrease,
+ kEnableLayoutBlockingThreshold,
+ kLayoutBlockingThreshold,
+ kMaxNumDelayableWhileLayoutBlocking,
+ kMaxNumDelayableRequestsPerClient)));
+ InitializeScheduler();
+ scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
+ scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
+ scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST));
+ scoped_ptr<TestRequest> low3(NewRequest("http://host/low", net::LOWEST));
+ EXPECT_TRUE(high->started());
+ EXPECT_TRUE(low->started());
+ EXPECT_TRUE(low2->started());
+ EXPECT_FALSE(low3->started());
+ high.reset();
+ scheduler()->OnWillInsertBody(kChildId, kRouteId);
+ EXPECT_TRUE(low3->started());
+}
+
+TEST_F(ResourceSchedulerTest,
+ UseLayoutBlockingThresholdOneAndTwoDelayableLoadsUntilBodyInserted) {
+ // Allow for two low priority requests to be in flight during the
+ // layout-blocking phase of loading but only when there is not more than one
+ // in-flight high priority request.
+ const int kDeferLateScripts = 0;
+ const int kIncreaseFontPriority = 0;
+ const int kIncreaseAsyncScriptPriority = 0;
+ const int kEnablePriorityIncrease = 0;
+ const int kEnableLayoutBlockingThreshold = 1;
+ const int kLayoutBlockingThreshold = 1;
+ const int kMaxNumDelayableWhileLayoutBlocking = 2;
+ const int kMaxNumDelayableRequestsPerClient = 10;
+ ASSERT_TRUE(InitializeFieldTrials(base::StringPrintf(
+ "ResourcePriorities/LayoutBlocking_%d%d%d%d%d_%d_%d_%d/",
+ kDeferLateScripts,
+ kIncreaseFontPriority,
+ kIncreaseAsyncScriptPriority,
+ kEnablePriorityIncrease,
+ kEnableLayoutBlockingThreshold,
+ kLayoutBlockingThreshold,
+ kMaxNumDelayableWhileLayoutBlocking,
+ kMaxNumDelayableRequestsPerClient)));
+ InitializeScheduler();
+ scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
+ scoped_ptr<TestRequest> high2(NewRequest("http://host/high", net::HIGHEST));
+ scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
+ scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST));
+ scoped_ptr<TestRequest> low3(NewRequest("http://host/low", net::LOWEST));
+ EXPECT_TRUE(high->started());
+ EXPECT_TRUE(high2->started());
+ EXPECT_FALSE(low->started());
+ EXPECT_FALSE(low2->started());
+ EXPECT_FALSE(low3->started());
+ high.reset();
+ EXPECT_TRUE(low->started());
+ EXPECT_TRUE(low2->started());
+ EXPECT_FALSE(low3->started());
+ high2.reset();
+ scheduler()->OnWillInsertBody(kChildId, kRouteId);
+ EXPECT_TRUE(low3->started());
+}
+
+TEST_F(ResourceSchedulerTest, TwentyMaxNumDelayableRequestsPerClient) {
+ // Do not exceed 20 low-priority requests to be in flight across all hosts
+ // at any point in time.
+ const int kDeferLateScripts = 0;
+ const int kIncreaseFontPriority = 0;
+ const int kIncreaseAsyncScriptPriority = 0;
+ const int kEnablePriorityIncrease = 0;
+ const int kEnableLayoutBlockingThreshold = 0;
+ const int kLayoutBlockingThreshold = 0;
+ const int kMaxNumDelayableWhileLayoutBlocking = 1;
+ const int kMaxNumDelayableRequestsPerClient = 20;
+ ASSERT_TRUE(InitializeFieldTrials(base::StringPrintf(
+ "ResourcePriorities/LayoutBlocking_%d%d%d%d%d_%d_%d_%d/",
+ kDeferLateScripts,
+ kIncreaseFontPriority,
+ kIncreaseAsyncScriptPriority,
+ kEnablePriorityIncrease,
+ kEnableLayoutBlockingThreshold,
+ kLayoutBlockingThreshold,
+ kMaxNumDelayableWhileLayoutBlocking,
+ kMaxNumDelayableRequestsPerClient)));
+ InitializeScheduler();
+
+ // Only load low priority resources if there's a body.
+ scheduler()->OnWillInsertBody(kChildId, kRouteId);
+
+ // Queue requests from different hosts until the total limit is reached.
+ ScopedVector<TestRequest> lows_differenthosts;
+ for (int i = 0; i < kMaxNumDelayableRequestsPerClient; ++i) {
+ string url = "http://host" + base::IntToString(i) + "/low";
+ lows_differenthosts.push_back(NewRequest(url.c_str(), net::LOWEST));
+ EXPECT_TRUE(lows_differenthosts[i]->started());
+ }
+
+ scoped_ptr<TestRequest> last_differenthost(NewRequest("http://host_new/last",
+ net::LOWEST));
+ EXPECT_FALSE(last_differenthost->started());
+}
+
+TEST_F(ResourceSchedulerTest,
+ TwentyMaxNumDelayableRequestsPerClientWithEverythingEnabled) {
+ // Do not exceed 20 low-priority requests to be in flight across all hosts
+ // at any point in time and make sure it still works correctly when the other
+ // options are toggled.
+ const int kDeferLateScripts = 1;
+ const int kIncreaseFontPriority = 1;
+ const int kIncreaseAsyncScriptPriority = 1;
+ const int kEnablePriorityIncrease = 1;
+ const int kEnableLayoutBlockingThreshold = 1;
+ const int kLayoutBlockingThreshold = 1;
+ const int kMaxNumDelayableWhileLayoutBlocking = 1;
+ const int kMaxNumDelayableRequestsPerClient = 20;
+ ASSERT_TRUE(InitializeFieldTrials(base::StringPrintf(
+ "ResourcePriorities/LayoutBlocking_%d%d%d%d%d_%d_%d_%d/",
+ kDeferLateScripts,
+ kIncreaseFontPriority,
+ kIncreaseAsyncScriptPriority,
+ kEnablePriorityIncrease,
+ kEnableLayoutBlockingThreshold,
+ kLayoutBlockingThreshold,
+ kMaxNumDelayableWhileLayoutBlocking,
+ kMaxNumDelayableRequestsPerClient)));
+ InitializeScheduler();
+
+ // Only load low priority resources if there's a body.
+ scheduler()->OnWillInsertBody(kChildId, kRouteId);
+
+ // Queue requests from different hosts until the total limit is reached.
+ ScopedVector<TestRequest> lows_differenthosts;
mmenke 2015/08/12 17:30:09 nit: *_different_host. Goes for all of these.
Pat Meenan 2015/08/13 12:11:03 Done.
+ for (int i = 0; i < kMaxNumDelayableRequestsPerClient; ++i) {
+ string url = "http://host" + base::IntToString(i) + "/low";
+ lows_differenthosts.push_back(NewRequest(url.c_str(), net::LOWEST));
+ EXPECT_TRUE(lows_differenthosts[i]->started());
+ }
+
+ scoped_ptr<TestRequest> last_differenthost(NewRequest("http://host_new/last",
+ net::LOWEST));
+ EXPECT_FALSE(last_differenthost->started());
+}
+
} // unnamed namespace
} // namespace content
« content/browser/loader/resource_scheduler.cc ('K') | « content/browser/loader/resource_scheduler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698