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

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

Issue 8586015: Slow start pipelining. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add missing files 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "net/http/http_pipelined_host_impl.h"
6
7 #include "base/stl_util.h"
8 #include "net/http/http_pipelined_connection_impl.h"
9 #include "net/http/http_pipelined_stream.h"
10
11 namespace net {
12
13 // TODO(simonjam): Run experiments to see what value minimizes evictions without
14 // costing too much performance. Until then, this is just a bad guess.
15 static const int kNumKnownSuccessesThreshold = 3;
16
17 class HttpPipelinedConnectionImplFactory :
18 public HttpPipelinedConnection::Factory {
19 public:
20 HttpPipelinedConnection* CreateNewPipeline(
21 ClientSocketHandle* connection,
22 HttpPipelinedConnection::Delegate* delegate,
23 const SSLConfig& used_ssl_config,
24 const ProxyInfo& used_proxy_info,
25 const BoundNetLog& net_log,
26 bool was_npn_negotiated) OVERRIDE {
27 return new HttpPipelinedConnectionImpl(connection, delegate,
28 used_ssl_config, used_proxy_info,
29 net_log, was_npn_negotiated);
30 }
31 };
32
33 HttpPipelinedHostImpl::HttpPipelinedHostImpl(
34 HttpPipelinedHost::Delegate* delegate,
35 const HostPortPair& origin,
36 HttpPipelinedConnection::Factory* factory,
37 Capability capability)
38 : delegate_(delegate),
39 origin_(origin),
40 factory_(factory),
41 capability_(capability) {
42 if (!factory) {
43 factory_.reset(new HttpPipelinedConnectionImplFactory());
44 }
45 }
46
47 HttpPipelinedHostImpl::~HttpPipelinedHostImpl() {
48 CHECK(pipelines_.empty());
49 }
50
51 HttpPipelinedStream* HttpPipelinedHostImpl::CreateStreamOnNewPipeline(
52 ClientSocketHandle* connection,
53 const SSLConfig& used_ssl_config,
54 const ProxyInfo& used_proxy_info,
55 const BoundNetLog& net_log,
56 bool was_npn_negotiated) {
57 HttpPipelinedConnection* pipeline = factory_->CreateNewPipeline(
58 connection, this, used_ssl_config, used_proxy_info, net_log,
59 was_npn_negotiated);
60 PipelineInfo info;
61 switch (capability_) {
62 case CAPABLE:
63 info.capacity = max_pipeline_depth();
64 break;
65
66 case INCAPABLE:
67 CHECK(false);
68
69 case UNKNOWN:
70 info.capacity = 1;
71 break;
72 }
73 pipelines_.insert(std::make_pair(pipeline, info));
74 return pipeline->CreateNewStream();
75 }
76
77 HttpPipelinedStream* HttpPipelinedHostImpl::CreateStreamOnExistingPipeline() {
78 HttpPipelinedConnection* available_pipeline = NULL;
79 for (PipelineInfoMap::iterator it = pipelines_.begin();
80 it != pipelines_.end(); ++it) {
81 if (it->first->usable() &&
82 it->first->active() &&
83 it->first->depth() < it->second.capacity &&
84 (!available_pipeline ||
85 it->first->depth() < available_pipeline->depth())) {
86 available_pipeline = it->first;
87 }
88 }
89 if (!available_pipeline) {
90 return NULL;
91 }
92 return available_pipeline->CreateNewStream();
93 }
94
95 bool HttpPipelinedHostImpl::IsExistingPipelineAvailable() {
96 for (PipelineInfoMap::iterator it = pipelines_.begin();
97 it != pipelines_.end(); ++it) {
98 if (it->first->usable() &&
99 it->first->active() &&
100 it->first->depth() < it->second.capacity) {
101 return true;
102 }
103 }
104 return false;
105 }
106
107 const HostPortPair& HttpPipelinedHostImpl::origin() const {
108 return origin_;
109 }
110
111 void HttpPipelinedHostImpl::OnPipelineEmpty(HttpPipelinedConnection* pipeline) {
112 CHECK(ContainsKey(pipelines_, pipeline));
113 if (capability_ == UNKNOWN &&
114 pipelines_[pipeline].num_successes >= kNumKnownSuccessesThreshold) {
115 capability_ = CAPABLE;
116 delegate_->OnHostDeterminedCapability(this, CAPABLE);
117 }
118 pipelines_.erase(pipeline);
119 delete pipeline;
120 if (pipelines_.empty()) {
121 delegate_->OnHostIdle(this);
122 // WARNING: We'll probably be deleted here.
123 }
124 }
125
126 void HttpPipelinedHostImpl::OnPipelineHasCapacity(
127 HttpPipelinedConnection* pipeline) {
128 CHECK(ContainsKey(pipelines_, pipeline));
129 if (pipeline->usable() &&
130 capability_ != INCAPABLE &&
131 pipeline->depth() < pipelines_[pipeline].capacity) {
132 delegate_->OnHostHasAdditionalCapacity(this);
133 }
134 if (!pipeline->depth()) {
135 OnPipelineEmpty(pipeline);
136 // WARNING: We might be deleted here.
137 }
138 }
139
140 void HttpPipelinedHostImpl::OnPipelineFeedback(
141 HttpPipelinedConnection* pipeline,
142 HttpPipelinedConnection::Feedback feedback) {
143 CHECK(ContainsKey(pipelines_, pipeline));
144 switch (feedback) {
145 case HttpPipelinedConnection::OK:
146 ++pipelines_[pipeline].num_successes;
147 if (pipelines_[pipeline].capacity != max_pipeline_depth()) {
148 pipelines_[pipeline].capacity = max_pipeline_depth();
149 OnPipelineHasCapacity(pipeline);
150 }
151 break;
152
153 case HttpPipelinedConnection::SOCKET_ERROR:
154 // TODO(simonjam): How often do we get spurious errors? Maybe we should
155 // just ignore these unless they're common. Until then, fall through...
mmenke 2011/11/17 22:25:37 Just think of the case of losing a network connect
James Simonsen 2011/11/18 00:03:56 Okay, I think a whitelist is the safest thing to d
mmenke 2011/11/21 14:51:39 Consider what servers that don't support pipelinin
156 case HttpPipelinedConnection::OLD_HTTP_VERSION:
157 // TODO(simonjam): I'd like to know if this ever happens after a HTTP/1.1.
158 // What's the best way to track that? If it does happen, I'd like to know
159 // which site, so I can debug it.
mmenke 2011/11/17 22:25:37 I'm no expert, but wouldn't surprise me if it did.
James Simonsen 2011/11/18 00:03:56 That's a good example. I guess I'll just take out
160 capability_ = INCAPABLE;
161 delegate_->OnHostDeterminedCapability(this, INCAPABLE);
162 break;
163
164 case HttpPipelinedConnection::MUST_CLOSE_CONNECTION:
165 break;
166 }
167 }
168
169 HttpPipelinedHostImpl::PipelineInfo::PipelineInfo()
170 : capacity(1),
mmenke 2011/11/17 22:25:37 nit: 4 space indent.
James Simonsen 2011/11/18 00:03:56 Done. I really need to figure out how to get vim t
171 num_successes(0) {
172 }
173
174 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698