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

Side by Side Diff: content/browser/loader/resource_scheduler.cc

Issue 2435743002: [ResourceScheduler] Throttle H2/QUIC requests just like we do for 1.1 (Closed)
Patch Set: Nits Created 4 years, 2 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 unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/loader/resource_scheduler_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/loader/resource_scheduler.h" 5 #include "content/browser/loader/resource_scheduler.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/feature_list.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/metrics/field_trial.h" 15 #include "base/metrics/field_trial.h"
15 #include "base/metrics/histogram_macros.h" 16 #include "base/metrics/histogram_macros.h"
16 #include "base/stl_util.h" 17 #include "base/stl_util.h"
17 #include "base/supports_user_data.h" 18 #include "base/supports_user_data.h"
18 #include "content/common/resource_messages.h" 19 #include "content/common/resource_messages.h"
19 #include "content/public/browser/resource_controller.h" 20 #include "content/public/browser/resource_controller.h"
20 #include "content/public/browser/resource_request_info.h" 21 #include "content/public/browser/resource_request_info.h"
21 #include "content/public/browser/resource_throttle.h" 22 #include "content/public/browser/resource_throttle.h"
22 #include "net/base/host_port_pair.h" 23 #include "net/base/host_port_pair.h"
23 #include "net/base/load_flags.h" 24 #include "net/base/load_flags.h"
24 #include "net/base/request_priority.h" 25 #include "net/base/request_priority.h"
25 #include "net/http/http_server_properties.h" 26 #include "net/http/http_server_properties.h"
26 #include "net/url_request/url_request.h" 27 #include "net/url_request/url_request.h"
27 #include "net/url_request/url_request_context.h" 28 #include "net/url_request/url_request_context.h"
28 #include "url/scheme_host_port.h" 29 #include "url/scheme_host_port.h"
29 30
30 namespace content { 31 namespace content {
31 32
32 namespace { 33 namespace {
33 34
35 const base::Feature kPrioritySupportedRequestsDelayable{
Charlie Harrison 2016/10/19 15:40:43 Can you add a comment about what this feature does
jkarlin 2016/10/19 15:53:48 Done.
36 "PrioritySupportedRequestsDelayable", base::FEATURE_ENABLED_BY_DEFAULT};
37
34 enum StartMode { 38 enum StartMode {
35 START_SYNC, 39 START_SYNC,
36 START_ASYNC 40 START_ASYNC
37 }; 41 };
38 42
39 // Flags identifying various attributes of the request that are used 43 // Flags identifying various attributes of the request that are used
40 // when making scheduling decisions. 44 // when making scheduling decisions.
41 using RequestAttributes = uint8_t; 45 using RequestAttributes = uint8_t;
42 const RequestAttributes kAttributeNone = 0x00; 46 const RequestAttributes kAttributeNone = 0x00;
43 const RequestAttributes kAttributeInFlight = 0x01; 47 const RequestAttributes kAttributeInFlight = 0x01;
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 // attribute across redirects. 510 // attribute across redirects.
507 attributes |= kAttributeLayoutBlocking; 511 attributes |= kAttributeLayoutBlocking;
508 } else if (!has_html_body_ && 512 } else if (!has_html_body_ &&
509 request->url_request()->priority() > 513 request->url_request()->priority() >
510 kLayoutBlockingPriorityThreshold) { 514 kLayoutBlockingPriorityThreshold) {
511 // Requests that are above the non_delayable threshold before the HTML 515 // Requests that are above the non_delayable threshold before the HTML
512 // body has been parsed are inferred to be layout-blocking. 516 // body has been parsed are inferred to be layout-blocking.
513 attributes |= kAttributeLayoutBlocking; 517 attributes |= kAttributeLayoutBlocking;
514 } else if (request->url_request()->priority() < 518 } else if (request->url_request()->priority() <
515 kDelayablePriorityThreshold) { 519 kDelayablePriorityThreshold) {
516 // Resources below the delayable priority threshold that are being 520 if (base::FeatureList::IsEnabled(kPrioritySupportedRequestsDelayable)) {
517 // requested from a server that does not support native prioritization are 521 // Resources below the delayable priority threshold that are considered
518 // considered delayable. 522 // delayable.
519 url::SchemeHostPort scheme_host_port(request->url_request()->url());
520 net::HttpServerProperties& http_server_properties =
521 *request->url_request()->context()->http_server_properties();
522 if (!http_server_properties.SupportsRequestPriority(scheme_host_port))
523 attributes |= kAttributeDelayable; 523 attributes |= kAttributeDelayable;
524 } else {
525 // Resources below the delayable priority threshold that are being
526 // requested from a server that does not support native prioritization
527 // are considered delayable.
528 url::SchemeHostPort scheme_host_port(request->url_request()->url());
529 net::HttpServerProperties& http_server_properties =
530 *request->url_request()->context()->http_server_properties();
531 if (!http_server_properties.SupportsRequestPriority(scheme_host_port))
532 attributes |= kAttributeDelayable;
533 }
524 } 534 }
525 535
526 return attributes; 536 return attributes;
527 } 537 }
528 538
529 bool ShouldKeepSearching( 539 bool ShouldKeepSearching(
530 const net::HostPortPair& active_request_host) const { 540 const net::HostPortPair& active_request_host) const {
531 size_t same_host_count = 0; 541 size_t same_host_count = 0;
532 for (RequestSet::const_iterator it = in_flight_requests_.begin(); 542 for (RequestSet::const_iterator it = in_flight_requests_.begin();
533 it != in_flight_requests_.end(); ++it) { 543 it != in_flight_requests_.end(); ++it) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 // Syncronous requests could block the entire render, which could impact 598 // Syncronous requests could block the entire render, which could impact
589 // user-observable Clients. 599 // user-observable Clients.
590 if (!request->is_async()) 600 if (!request->is_async())
591 return START_REQUEST; 601 return START_REQUEST;
592 602
593 // TODO(simonjam): This may end up causing disk contention. We should 603 // TODO(simonjam): This may end up causing disk contention. We should
594 // experiment with throttling if that happens. 604 // experiment with throttling if that happens.
595 if (!url_request.url().SchemeIsHTTPOrHTTPS()) 605 if (!url_request.url().SchemeIsHTTPOrHTTPS())
596 return START_REQUEST; 606 return START_REQUEST;
597 607
598 if (using_spdy_proxy_ && url_request.url().SchemeIs(url::kHttpScheme))
599 return START_REQUEST;
600
601 net::HostPortPair host_port_pair = 608 net::HostPortPair host_port_pair =
602 net::HostPortPair::FromURL(url_request.url()); 609 net::HostPortPair::FromURL(url_request.url());
603 url::SchemeHostPort scheme_host_port(url_request.url());
604 net::HttpServerProperties& http_server_properties =
605 *url_request.context()->http_server_properties();
606 610
607 // TODO(willchan): We should really improve this algorithm as described in 611 if (!base::FeatureList::IsEnabled(kPrioritySupportedRequestsDelayable)) {
608 // crbug.com/164101. Also, theoretically we should not count a 612 if (using_spdy_proxy_ && url_request.url().SchemeIs(url::kHttpScheme))
609 // request-priority capable request against the delayable requests limit. 613 return START_REQUEST;
610 if (http_server_properties.SupportsRequestPriority(scheme_host_port)) 614
611 return START_REQUEST; 615 url::SchemeHostPort scheme_host_port(url_request.url());
616
617 net::HttpServerProperties& http_server_properties =
618 *url_request.context()->http_server_properties();
619
620 // TODO(willchan): We should really improve this algorithm as described in
621 // crbug.com/164101. Also, theoretically we should not count a
622 // request-priority capable request against the delayable requests limit.
623 if (http_server_properties.SupportsRequestPriority(scheme_host_port))
624 return START_REQUEST;
625 }
612 626
613 // Non-delayable requests. 627 // Non-delayable requests.
614 if (!RequestAttributesAreSet(request->attributes(), kAttributeDelayable)) 628 if (!RequestAttributesAreSet(request->attributes(), kAttributeDelayable))
615 return START_REQUEST; 629 return START_REQUEST;
616 630
617 if (in_flight_delayable_count_ >= kMaxNumDelayableRequestsPerClient) 631 if (in_flight_delayable_count_ >= kMaxNumDelayableRequestsPerClient)
618 return DO_NOT_START_REQUEST_AND_STOP_SEARCHING; 632 return DO_NOT_START_REQUEST_AND_STOP_SEARCHING;
619 633
620 if (ShouldKeepSearching(host_port_pair)) { 634 if (ShouldKeepSearching(host_port_pair)) {
621 // There may be other requests for other hosts that may be allowed, 635 // There may be other requests for other hosts that may be allowed,
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 client->ReprioritizeRequest(scheduled_resource_request, old_priority_params, 903 client->ReprioritizeRequest(scheduled_resource_request, old_priority_params,
890 new_priority_params); 904 new_priority_params);
891 } 905 }
892 906
893 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( 907 ResourceScheduler::ClientId ResourceScheduler::MakeClientId(
894 int child_id, int route_id) { 908 int child_id, int route_id) {
895 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; 909 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id;
896 } 910 }
897 911
898 } // namespace content 912 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/loader/resource_scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698