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

Side by Side Diff: net/http/http_pipelined_host_pool.cc

Issue 8586015: Slow start pipelining. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch for landing Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « net/http/http_pipelined_host_pool.h ('k') | net/http/http_pipelined_host_pool_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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "net/http/http_pipelined_host_pool.h" 5 #include "net/http/http_pipelined_host_pool.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "net/http/http_pipelined_host.h" 9 #include "net/http/http_pipelined_host_impl.h"
10 #include "net/http/http_stream_factory_impl.h"
11 10
12 namespace net { 11 namespace net {
13 12
14 HttpPipelinedHostPool::HttpPipelinedHostPool(HttpStreamFactoryImpl* factory) 13 // TODO(simonjam): Run experiments with different values of this to see what
15 : factory_(factory) { 14 // value is good at avoiding evictions without eating too much memory. Until
15 // then, this is just a bad guess.
16 static const int kNumHostsToRemember = 200;
17
18 class HttpPipelinedHostImplFactory : public HttpPipelinedHost::Factory {
19 public:
20 virtual HttpPipelinedHost* CreateNewHost(
21 HttpPipelinedHost::Delegate* delegate, const HostPortPair& origin,
22 HttpPipelinedConnection::Factory* factory,
23 HttpPipelinedHost::Capability capability) OVERRIDE {
24 return new HttpPipelinedHostImpl(delegate, origin, factory, capability);
25 }
26 };
27
28 HttpPipelinedHostPool::HttpPipelinedHostPool(
29 Delegate* delegate,
30 HttpPipelinedHost::Factory* factory)
31 : delegate_(delegate),
32 factory_(factory),
33 known_capability_map_(kNumHostsToRemember) {
34 if (!factory) {
35 factory_.reset(new HttpPipelinedHostImplFactory);
36 }
16 } 37 }
17 38
18 HttpPipelinedHostPool::~HttpPipelinedHostPool() { 39 HttpPipelinedHostPool::~HttpPipelinedHostPool() {
19 CHECK(host_map_.empty()); 40 CHECK(host_map_.empty());
20 } 41 }
21 42
43 bool HttpPipelinedHostPool::IsHostEligibleForPipelining(
44 const HostPortPair& origin) {
45 HttpPipelinedHost::Capability capability = GetHostCapability(origin);
46 return capability != HttpPipelinedHost::INCAPABLE;
47 }
48
22 HttpPipelinedStream* HttpPipelinedHostPool::CreateStreamOnNewPipeline( 49 HttpPipelinedStream* HttpPipelinedHostPool::CreateStreamOnNewPipeline(
23 const HostPortPair& origin, 50 const HostPortPair& origin,
24 ClientSocketHandle* connection, 51 ClientSocketHandle* connection,
25 const SSLConfig& used_ssl_config, 52 const SSLConfig& used_ssl_config,
26 const ProxyInfo& used_proxy_info, 53 const ProxyInfo& used_proxy_info,
27 const BoundNetLog& net_log, 54 const BoundNetLog& net_log,
28 bool was_npn_negotiated) { 55 bool was_npn_negotiated) {
29 HttpPipelinedHost* host = GetPipelinedHost(origin, true); 56 HttpPipelinedHost* host = GetPipelinedHost(origin, true);
57 if (!host) {
58 return NULL;
59 }
30 return host->CreateStreamOnNewPipeline(connection, used_ssl_config, 60 return host->CreateStreamOnNewPipeline(connection, used_ssl_config,
31 used_proxy_info, net_log, 61 used_proxy_info, net_log,
32 was_npn_negotiated); 62 was_npn_negotiated);
33 } 63 }
34 64
35 HttpPipelinedStream* HttpPipelinedHostPool::CreateStreamOnExistingPipeline( 65 HttpPipelinedStream* HttpPipelinedHostPool::CreateStreamOnExistingPipeline(
36 const HostPortPair& origin) { 66 const HostPortPair& origin) {
37 HttpPipelinedHost* host = GetPipelinedHost(origin, false); 67 HttpPipelinedHost* host = GetPipelinedHost(origin, false);
38 if (!host) { 68 if (!host) {
39 return NULL; 69 return NULL;
40 } 70 }
41 return host->CreateStreamOnExistingPipeline(); 71 return host->CreateStreamOnExistingPipeline();
42 } 72 }
43 73
44 bool HttpPipelinedHostPool::IsExistingPipelineAvailableForOrigin( 74 bool HttpPipelinedHostPool::IsExistingPipelineAvailableForOrigin(
45 const HostPortPair& origin) { 75 const HostPortPair& origin) {
46 HttpPipelinedHost* host = GetPipelinedHost(origin, false); 76 HttpPipelinedHost* host = GetPipelinedHost(origin, false);
47 if (!host) { 77 if (!host) {
48 return false; 78 return false;
49 } 79 }
50 return host->IsExistingPipelineAvailable(); 80 return host->IsExistingPipelineAvailable();
51 } 81 }
52 82
53 HttpPipelinedHost* HttpPipelinedHostPool::GetPipelinedHost( 83 HttpPipelinedHost* HttpPipelinedHostPool::GetPipelinedHost(
54 const HostPortPair& origin, bool create_if_not_found) { 84 const HostPortPair& origin, bool create_if_not_found) {
55 HostMap::iterator it = host_map_.find(origin); 85 HostMap::iterator host_it = host_map_.find(origin);
56 if (it != host_map_.end()) { 86 if (host_it != host_map_.end()) {
57 CHECK(it->second); 87 CHECK(host_it->second);
58 return it->second; 88 return host_it->second;
59 } else if (!create_if_not_found) { 89 } else if (!create_if_not_found) {
60 return NULL; 90 return NULL;
61 } 91 }
62 HttpPipelinedHost* host = new HttpPipelinedHost(this, origin, NULL); 92
93 HttpPipelinedHost::Capability capability = GetHostCapability(origin);
94 if (capability == HttpPipelinedHost::INCAPABLE) {
95 return NULL;
96 }
97
98 HttpPipelinedHost* host = factory_->CreateNewHost(
99 this, origin, NULL, capability);
63 host_map_[origin] = host; 100 host_map_[origin] = host;
64 return host; 101 return host;
65 } 102 }
66 103
67 void HttpPipelinedHostPool::OnHostIdle(HttpPipelinedHost* host) { 104 void HttpPipelinedHostPool::OnHostIdle(HttpPipelinedHost* host) {
68 const HostPortPair& origin = host->origin(); 105 const HostPortPair& origin = host->origin();
69 CHECK(ContainsKey(host_map_, origin)); 106 CHECK(ContainsKey(host_map_, origin));
70 // TODO(simonjam): We should remember the pipeline state for each host.
71 host_map_.erase(origin); 107 host_map_.erase(origin);
72 delete host; 108 delete host;
73 } 109 }
74 110
75 void HttpPipelinedHostPool::OnHostHasAdditionalCapacity( 111 void HttpPipelinedHostPool::OnHostHasAdditionalCapacity(
76 HttpPipelinedHost* host) { 112 HttpPipelinedHost* host) {
77 factory_->OnHttpPipelinedHostHasAdditionalCapacity(host->origin()); 113 delegate_->OnHttpPipelinedHostHasAdditionalCapacity(host->origin());
114 }
115
116 void HttpPipelinedHostPool::OnHostDeterminedCapability(
117 HttpPipelinedHost* host,
118 HttpPipelinedHost::Capability capability) {
119 CapabilityMap::iterator known_it = known_capability_map_.Get(host->origin());
120 if (known_it == known_capability_map_.end() ||
121 known_it->second != HttpPipelinedHost::INCAPABLE) {
122 known_capability_map_.Put(host->origin(), capability);
123 }
124 }
125
126 HttpPipelinedHost::Capability HttpPipelinedHostPool::GetHostCapability(
127 const HostPortPair& origin) {
128 HttpPipelinedHost::Capability capability = HttpPipelinedHost::UNKNOWN;
129 CapabilityMap::const_iterator it = known_capability_map_.Get(origin);
130 if (it != known_capability_map_.end()) {
131 capability = it->second;
132 }
133 return capability;
78 } 134 }
79 135
80 } // namespace net 136 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_pipelined_host_pool.h ('k') | net/http/http_pipelined_host_pool_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698