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

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: Whitelist some socket errors Created 9 years, 1 month 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
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 CapabilityMap::iterator it = known_capability_map_.Get(origin);
46 if (it != known_capability_map_.end()) {
47 return it->second != HttpPipelinedHost::INCAPABLE;
48 }
49 return true;
50 }
51
22 HttpPipelinedStream* HttpPipelinedHostPool::CreateStreamOnNewPipeline( 52 HttpPipelinedStream* HttpPipelinedHostPool::CreateStreamOnNewPipeline(
23 const HostPortPair& origin, 53 const HostPortPair& origin,
24 ClientSocketHandle* connection, 54 ClientSocketHandle* connection,
25 const SSLConfig& used_ssl_config, 55 const SSLConfig& used_ssl_config,
26 const ProxyInfo& used_proxy_info, 56 const ProxyInfo& used_proxy_info,
27 const BoundNetLog& net_log, 57 const BoundNetLog& net_log,
28 bool was_npn_negotiated) { 58 bool was_npn_negotiated) {
29 HttpPipelinedHost* host = GetPipelinedHost(origin, true); 59 HttpPipelinedHost* host = GetPipelinedHost(origin, true);
60 if (!host) {
61 return NULL;
62 }
30 return host->CreateStreamOnNewPipeline(connection, used_ssl_config, 63 return host->CreateStreamOnNewPipeline(connection, used_ssl_config,
31 used_proxy_info, net_log, 64 used_proxy_info, net_log,
32 was_npn_negotiated); 65 was_npn_negotiated);
33 } 66 }
34 67
35 HttpPipelinedStream* HttpPipelinedHostPool::CreateStreamOnExistingPipeline( 68 HttpPipelinedStream* HttpPipelinedHostPool::CreateStreamOnExistingPipeline(
36 const HostPortPair& origin) { 69 const HostPortPair& origin) {
37 HttpPipelinedHost* host = GetPipelinedHost(origin, false); 70 HttpPipelinedHost* host = GetPipelinedHost(origin, false);
38 if (!host) { 71 if (!host) {
39 return NULL; 72 return NULL;
40 } 73 }
41 return host->CreateStreamOnExistingPipeline(); 74 return host->CreateStreamOnExistingPipeline();
42 } 75 }
43 76
44 bool HttpPipelinedHostPool::IsExistingPipelineAvailableForOrigin( 77 bool HttpPipelinedHostPool::IsExistingPipelineAvailableForOrigin(
45 const HostPortPair& origin) { 78 const HostPortPair& origin) {
46 HttpPipelinedHost* host = GetPipelinedHost(origin, false); 79 HttpPipelinedHost* host = GetPipelinedHost(origin, false);
47 if (!host) { 80 if (!host) {
48 return false; 81 return false;
49 } 82 }
50 return host->IsExistingPipelineAvailable(); 83 return host->IsExistingPipelineAvailable();
51 } 84 }
52 85
53 HttpPipelinedHost* HttpPipelinedHostPool::GetPipelinedHost( 86 HttpPipelinedHost* HttpPipelinedHostPool::GetPipelinedHost(
54 const HostPortPair& origin, bool create_if_not_found) { 87 const HostPortPair& origin, bool create_if_not_found) {
55 HostMap::iterator it = host_map_.find(origin); 88 HostMap::iterator host_it = host_map_.find(origin);
56 if (it != host_map_.end()) { 89 if (host_it != host_map_.end()) {
57 CHECK(it->second); 90 CHECK(host_it->second);
58 return it->second; 91 return host_it->second;
59 } else if (!create_if_not_found) { 92 } else if (!create_if_not_found) {
60 return NULL; 93 return NULL;
61 } 94 }
62 HttpPipelinedHost* host = new HttpPipelinedHost(this, origin, NULL); 95
96 HttpPipelinedHost::Capability capability = HttpPipelinedHost::UNKNOWN;
97 CapabilityMap::iterator known_it = known_capability_map_.Get(origin);
mmenke 2011/11/28 23:05:28 Minor suggestion: Create a GetCapability(origin)
James Simonsen 2011/12/01 01:17:10 Done.
98 if (known_it != known_capability_map_.end()) {
99 capability = known_it->second;
100 }
101 if (capability == HttpPipelinedHost::INCAPABLE) {
102 return NULL;
103 }
104
105 HttpPipelinedHost* host = factory_->CreateNewHost(
106 this, origin, NULL, capability);
63 host_map_[origin] = host; 107 host_map_[origin] = host;
64 return host; 108 return host;
65 } 109 }
66 110
67 void HttpPipelinedHostPool::OnHostIdle(HttpPipelinedHost* host) { 111 void HttpPipelinedHostPool::OnHostIdle(HttpPipelinedHost* host) {
68 const HostPortPair& origin = host->origin(); 112 const HostPortPair& origin = host->origin();
69 CHECK(ContainsKey(host_map_, origin)); 113 CHECK(ContainsKey(host_map_, origin));
70 // TODO(simonjam): We should remember the pipeline state for each host.
71 host_map_.erase(origin); 114 host_map_.erase(origin);
72 delete host; 115 delete host;
73 } 116 }
74 117
75 void HttpPipelinedHostPool::OnHostHasAdditionalCapacity( 118 void HttpPipelinedHostPool::OnHostHasAdditionalCapacity(
76 HttpPipelinedHost* host) { 119 HttpPipelinedHost* host) {
77 factory_->OnHttpPipelinedHostHasAdditionalCapacity(host->origin()); 120 delegate_->OnHttpPipelinedHostHasAdditionalCapacity(host->origin());
121 }
122
123 void HttpPipelinedHostPool::OnHostDeterminedCapability(
124 HttpPipelinedHost* host,
125 HttpPipelinedHost::Capability capability) {
126 CapabilityMap::iterator known_it = known_capability_map_.Get(host->origin());
127 if (known_it == known_capability_map_.end() ||
128 known_it->second != HttpPipelinedHost::INCAPABLE) {
129 known_capability_map_.Put(host->origin(), capability);
130 }
78 } 131 }
79 132
80 } // namespace net 133 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698