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

Side by Side Diff: net/socket/client_socket_pool_manager.cc

Issue 9764003: Increase number of max sockets per group for WebSocket connections. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
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 "net/socket/client_socket_pool_manager.h" 5 #include "net/socket/client_socket_pool_manager.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
11 #include "net/base/load_flags.h" 11 #include "net/base/load_flags.h"
12 #include "net/http/http_network_session.h"
13 #include "net/http/http_proxy_client_socket_pool.h" 12 #include "net/http/http_proxy_client_socket_pool.h"
14 #include "net/http/http_request_info.h" 13 #include "net/http/http_request_info.h"
15 #include "net/http/http_stream_factory.h" 14 #include "net/http/http_stream_factory.h"
16 #include "net/proxy/proxy_info.h" 15 #include "net/proxy/proxy_info.h"
17 #include "net/socket/client_socket_handle.h" 16 #include "net/socket/client_socket_handle.h"
18 #include "net/socket/socks_client_socket_pool.h" 17 #include "net/socket/socks_client_socket_pool.h"
19 #include "net/socket/ssl_client_socket_pool.h" 18 #include "net/socket/ssl_client_socket_pool.h"
20 #include "net/socket/transport_client_socket_pool.h" 19 #include "net/socket/transport_client_socket_pool.h"
21 20
22 namespace net { 21 namespace net {
23 22
24 namespace { 23 namespace {
25 24
26 // Limit of sockets of each socket pool. 25 // Limit of sockets of each socket pool.
27 int g_max_sockets_per_pool = 256; 26 int g_max_sockets_per_pool[HttpNetworkSession::kNumSocketPoolTypes] = {
27 256, // NORMAL_SOCKET_POOL
28 256 // WEBSOCKET_SOCKET_POOL
29 };
28 30
29 // Default to allow up to 6 connections per host. Experiment and tuning may 31 // Default to allow up to 6 connections per host. Experiment and tuning may
30 // try other values (greater than 0). Too large may cause many problems, such 32 // try other values (greater than 0). Too large may cause many problems, such
31 // as home routers blocking the connections!?!? See http://crbug.com/12066. 33 // as home routers blocking the connections!?!? See http://crbug.com/12066.
32 int g_max_sockets_per_group = 6; 34 //
35 // WebSocket connections are long-lived, and should be treated differently
36 // than normal other connections. 6 connections per group sounded too small
37 // for such use, thus we use a larger limit which was determined somewhat
38 // arbitrarily.
39 // TODO(yutak): Look at the usage and determine the right value after
40 // WebSocket protocol stack starts to work.
41 int g_max_sockets_per_group[HttpNetworkSession::kNumSocketPoolTypes] = {
42 6, // NORMAL_SOCKET_POOL
43 30 // WEBSOCKET_SOCKET_POOL
44 };
33 45
34 // The max number of sockets to allow per proxy server. This applies both to 46 // The max number of sockets to allow per proxy server. This applies both to
35 // http and SOCKS proxies. See http://crbug.com/12066 and 47 // http and SOCKS proxies. See http://crbug.com/12066 and
36 // http://crbug.com/44501 for details about proxy server connection limits. 48 // http://crbug.com/44501 for details about proxy server connection limits.
37 int g_max_sockets_per_proxy_server = kDefaultMaxSocketsPerProxyServer; 49 int g_max_sockets_per_proxy_server[HttpNetworkSession::kNumSocketPoolTypes] = {
50 kDefaultMaxSocketsPerProxyServer, // NORMAL_SOCKET_POOL
51 kDefaultMaxSocketsPerProxyServer // WEBSOCKET_SOCKET_POOL
52 };
38 53
39 // The meat of the implementation for the InitSocketHandleForHttpRequest, 54 // The meat of the implementation for the InitSocketHandleForHttpRequest,
40 // InitSocketHandleForRawConnect and PreconnectSocketsForHttpRequest methods. 55 // InitSocketHandleForRawConnect and PreconnectSocketsForHttpRequest methods.
41 int InitSocketPoolHelper(const GURL& request_url, 56 int InitSocketPoolHelper(const GURL& request_url,
42 const HttpRequestHeaders& request_extra_headers, 57 const HttpRequestHeaders& request_extra_headers,
43 int request_load_flags, 58 int request_load_flags,
44 RequestPriority request_priority, 59 RequestPriority request_priority,
45 HttpNetworkSession* session, 60 HttpNetworkSession* session,
46 const ProxyInfo& proxy_info, 61 const ProxyInfo& proxy_info,
47 bool force_spdy_over_ssl, 62 bool force_spdy_over_ssl,
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 num_preconnect_streams, net_log); 196 num_preconnect_streams, net_log);
182 return OK; 197 return OK;
183 } 198 }
184 199
185 return socket_handle->Init(connection_group, ssl_params, 200 return socket_handle->Init(connection_group, ssl_params,
186 request_priority, callback, ssl_pool, 201 request_priority, callback, ssl_pool,
187 net_log); 202 net_log);
188 } 203 }
189 204
190 // Finally, get the connection started. 205 // Finally, get the connection started.
206
191 if (proxy_info.is_http() || proxy_info.is_https()) { 207 if (proxy_info.is_http() || proxy_info.is_https()) {
192 HttpProxyClientSocketPool* pool = 208 HttpProxyClientSocketPool* pool =
193 session->GetSocketPoolForHTTPProxy( 209 session->GetSocketPoolForHTTPProxy(
194 HttpNetworkSession::NORMAL_SOCKET_POOL, 210 HttpNetworkSession::NORMAL_SOCKET_POOL,
195 *proxy_host_port); 211 *proxy_host_port);
196 if (num_preconnect_streams) { 212 if (num_preconnect_streams) {
197 RequestSocketsForPool(pool, connection_group, http_proxy_params, 213 RequestSocketsForPool(pool, connection_group, http_proxy_params,
198 num_preconnect_streams, net_log); 214 num_preconnect_streams, net_log);
199 return OK; 215 return OK;
200 } 216 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 request_priority, callback, 250 request_priority, callback,
235 pool, net_log); 251 pool, net_log);
236 } 252 }
237 253
238 } // namespace 254 } // namespace
239 255
240 ClientSocketPoolManager::ClientSocketPoolManager() {} 256 ClientSocketPoolManager::ClientSocketPoolManager() {}
241 ClientSocketPoolManager::~ClientSocketPoolManager() {} 257 ClientSocketPoolManager::~ClientSocketPoolManager() {}
242 258
243 // static 259 // static
244 int ClientSocketPoolManager::max_sockets_per_pool() { 260 int ClientSocketPoolManager::max_sockets_per_pool(
245 return g_max_sockets_per_pool; 261 HttpNetworkSession::SocketPoolType pool_type) {
262 DCHECK_LT(pool_type, HttpNetworkSession::kNumSocketPoolTypes);
263 return g_max_sockets_per_pool[pool_type];
246 } 264 }
247 265
248 // static 266 // static
249 void ClientSocketPoolManager::set_max_sockets_per_pool(int socket_count) { 267 void ClientSocketPoolManager::set_max_sockets_per_pool(
268 HttpNetworkSession::SocketPoolType pool_type,
269 int socket_count) {
250 DCHECK_LT(0, socket_count); 270 DCHECK_LT(0, socket_count);
251 DCHECK_GT(1000, socket_count); // Sanity check. 271 DCHECK_GT(1000, socket_count); // Sanity check.
252 g_max_sockets_per_pool = socket_count; 272 DCHECK_LT(pool_type, HttpNetworkSession::kNumSocketPoolTypes);
253 DCHECK_GE(g_max_sockets_per_pool, g_max_sockets_per_group); 273 g_max_sockets_per_pool[pool_type] = socket_count;
274 DCHECK_GE(g_max_sockets_per_pool[pool_type],
275 g_max_sockets_per_group[pool_type]);
254 } 276 }
255 277
256 // static 278 // static
257 int ClientSocketPoolManager::max_sockets_per_group() { 279 int ClientSocketPoolManager::max_sockets_per_group(
258 return g_max_sockets_per_group; 280 HttpNetworkSession::SocketPoolType pool_type) {
281 DCHECK_LT(pool_type, HttpNetworkSession::kNumSocketPoolTypes);
282 return g_max_sockets_per_group[pool_type];
259 } 283 }
260 284
261 // static 285 // static
262 void ClientSocketPoolManager::set_max_sockets_per_group(int socket_count) { 286 void ClientSocketPoolManager::set_max_sockets_per_group(
287 HttpNetworkSession::SocketPoolType pool_type,
288 int socket_count) {
263 DCHECK_LT(0, socket_count); 289 DCHECK_LT(0, socket_count);
264 // The following is a sanity check... but we should NEVER be near this value. 290 // The following is a sanity check... but we should NEVER be near this value.
265 DCHECK_GT(100, socket_count); 291 DCHECK_GT(100, socket_count);
266 g_max_sockets_per_group = socket_count; 292 DCHECK_LT(pool_type, HttpNetworkSession::kNumSocketPoolTypes);
293 g_max_sockets_per_group[pool_type] = socket_count;
267 294
268 DCHECK_GE(g_max_sockets_per_pool, g_max_sockets_per_group); 295 DCHECK_GE(g_max_sockets_per_pool[pool_type],
269 DCHECK_GE(g_max_sockets_per_proxy_server, g_max_sockets_per_group); 296 g_max_sockets_per_group[pool_type]);
297 DCHECK_GE(g_max_sockets_per_proxy_server[pool_type],
298 g_max_sockets_per_group[pool_type]);
270 } 299 }
271 300
272 // static 301 // static
273 int ClientSocketPoolManager::max_sockets_per_proxy_server() { 302 int ClientSocketPoolManager::max_sockets_per_proxy_server(
274 return g_max_sockets_per_proxy_server; 303 HttpNetworkSession::SocketPoolType pool_type) {
304 DCHECK_LT(pool_type, HttpNetworkSession::kNumSocketPoolTypes);
305 return g_max_sockets_per_proxy_server[pool_type];
275 } 306 }
276 307
277 // static 308 // static
278 void ClientSocketPoolManager::set_max_sockets_per_proxy_server( 309 void ClientSocketPoolManager::set_max_sockets_per_proxy_server(
310 HttpNetworkSession::SocketPoolType pool_type,
279 int socket_count) { 311 int socket_count) {
280 DCHECK_LT(0, socket_count); 312 DCHECK_LT(0, socket_count);
281 DCHECK_GT(100, socket_count); // Sanity check. 313 DCHECK_GT(100, socket_count); // Sanity check.
314 DCHECK_LT(pool_type, HttpNetworkSession::kNumSocketPoolTypes);
282 // Assert this case early on. The max number of sockets per group cannot 315 // Assert this case early on. The max number of sockets per group cannot
283 // exceed the max number of sockets per proxy server. 316 // exceed the max number of sockets per proxy server.
284 DCHECK_LE(g_max_sockets_per_group, socket_count); 317 DCHECK_LE(g_max_sockets_per_group[pool_type], socket_count);
285 g_max_sockets_per_proxy_server = socket_count; 318 g_max_sockets_per_proxy_server[pool_type] = socket_count;
286 } 319 }
287 320
288 int InitSocketHandleForHttpRequest( 321 int InitSocketHandleForHttpRequest(
289 const GURL& request_url, 322 const GURL& request_url,
290 const HttpRequestHeaders& request_extra_headers, 323 const HttpRequestHeaders& request_extra_headers,
291 int request_load_flags, 324 int request_load_flags,
292 RequestPriority request_priority, 325 RequestPriority request_priority,
293 HttpNetworkSession* session, 326 HttpNetworkSession* session,
294 const ProxyInfo& proxy_info, 327 const ProxyInfo& proxy_info,
295 bool force_spdy_over_ssl, 328 bool force_spdy_over_ssl,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 const BoundNetLog& net_log, 376 const BoundNetLog& net_log,
344 int num_preconnect_streams) { 377 int num_preconnect_streams) {
345 return InitSocketPoolHelper( 378 return InitSocketPoolHelper(
346 request_url, request_extra_headers, request_load_flags, request_priority, 379 request_url, request_extra_headers, request_load_flags, request_priority,
347 session, proxy_info, force_spdy_over_ssl, want_spdy_over_npn, 380 session, proxy_info, force_spdy_over_ssl, want_spdy_over_npn,
348 ssl_config_for_origin, ssl_config_for_proxy, false, net_log, 381 ssl_config_for_origin, ssl_config_for_proxy, false, net_log,
349 num_preconnect_streams, NULL, CompletionCallback()); 382 num_preconnect_streams, NULL, CompletionCallback());
350 } 383 }
351 384
352 } // namespace net 385 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698