summaryrefslogtreecommitdiffstats
path: root/net/socket/client_socket_pool_base.h
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-29 01:35:16 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-29 01:35:16 +0000
commit9bf28dba03b1caaec0f64f54232e7f1acf4eaddf (patch)
treee9ed3ba489214d2c88884b5a059819e72df54413 /net/socket/client_socket_pool_base.h
parent6d60703bcc863062952c5907cddc649cd130c20b (diff)
downloadchromium_src-9bf28dba03b1caaec0f64f54232e7f1acf4eaddf.zip
chromium_src-9bf28dba03b1caaec0f64f54232e7f1acf4eaddf.tar.gz
chromium_src-9bf28dba03b1caaec0f64f54232e7f1acf4eaddf.tar.bz2
Control the amount of time to leave an unused socket idle before closing it.
This adds constructor arguments for socket idle timeouts. This allows me to control it for testing, and also makes it possible to run experiments on how long to enable it for. Currently I've set the timeout for unused sockets to 10 seconds, since that will cover 90% of the TCP RSTs we're seeing. We can probably increase this, but I'm waiting on histogram data to decide what to change it to. BUG=http://crbug.com/18192 Review URL: http://codereview.chromium.org/176021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24847 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket/client_socket_pool_base.h')
-rw-r--r--net/socket/client_socket_pool_base.h38
1 files changed, 33 insertions, 5 deletions
diff --git a/net/socket/client_socket_pool_base.h b/net/socket/client_socket_pool_base.h
index e6368ca..4b5a3b1 100644
--- a/net/socket/client_socket_pool_base.h
+++ b/net/socket/client_socket_pool_base.h
@@ -166,6 +166,8 @@ class ClientSocketPoolBaseHelper
ClientSocketPoolBaseHelper(int max_sockets,
int max_sockets_per_group,
+ base::TimeDelta unused_idle_socket_timeout,
+ base::TimeDelta used_idle_socket_timeout,
ConnectJobFactory* connect_job_factory);
~ClientSocketPoolBaseHelper();
@@ -217,6 +219,10 @@ class ClientSocketPoolBaseHelper
return group_map_.find(group_name)->second.jobs.size();
}
+ // Closes all idle sockets if |force| is true. Else, only closes idle
+ // sockets that timed out or can't be reused. Made public for testing.
+ void CleanupIdleSockets(bool force);
+
private:
// Entry for a persistent socket which became idle at time |start_time|.
struct IdleSocket {
@@ -227,12 +233,13 @@ class ClientSocketPoolBaseHelper
// An idle socket should be removed if it can't be reused, or has been idle
// for too long. |now| is the current time value (TimeTicks::Now()).
+ // |timeout| is the length of time to wait before timing out an idle socket.
//
// An idle socket can't be reused if it is disconnected or has received
// data unexpectedly (hence no longer idle). The unread data would be
// mistaken for the beginning of the next response if we were to reuse the
// socket for a new request.
- bool ShouldCleanup(base::TimeTicks now) const;
+ bool ShouldCleanup(base::TimeTicks now, base::TimeDelta timeout) const;
};
typedef std::deque<const Request*> RequestQueue;
@@ -274,10 +281,6 @@ class ClientSocketPoolBaseHelper
static const Request* RemoveRequestFromQueue(RequestQueue::iterator it,
RequestQueue* pending_requests);
- // Closes all idle sockets if |force| is true. Else, only closes idle
- // sockets that timed out or can't be reused.
- void CleanupIdleSockets(bool force);
-
// Called when the number of idle sockets changes.
void IncrementIdleCount();
void DecrementIdleCount();
@@ -359,6 +362,10 @@ class ClientSocketPoolBaseHelper
// The maximum number of sockets kept per group.
const int max_sockets_per_group_;
+ // The time to wait until closing idle sockets.
+ const base::TimeDelta unused_idle_socket_timeout_;
+ const base::TimeDelta used_idle_socket_timeout_;
+
// Until the maximum number of sockets limit is reached, a group can only
// have pending requests if it exceeds the "max sockets per group" limit.
//
@@ -384,6 +391,14 @@ class ClientSocketPoolBaseHelper
} // namespace internal
+// The maximum duration, in seconds, to keep unused idle persistent sockets
+// alive.
+// TODO(willchan): Change this timeout after getting histogram data on how
+// long it should be.
+static const int kUnusedIdleSocketTimeout = 10;
+// The maximum duration, in seconds, to keep used idle persistent sockets alive.
+static const int kUsedIdleSocketTimeout = 300; // 5 minutes
+
template <typename SocketParams>
class ClientSocketPoolBase {
public:
@@ -419,11 +434,20 @@ class ClientSocketPoolBase {
DISALLOW_COPY_AND_ASSIGN(ConnectJobFactory);
};
+ // |max_sockets| is the maximum number of sockets to be maintained by this
+ // ClientSocketPool. |max_sockets_per_group| specifies the maximum number of
+ // sockets a "group" can have. |unused_idle_socket_timeout| specifies how
+ // long to leave an unused idle socket open before closing it.
+ // |used_idle_socket_timeout| specifies how long to leave a previously used
+ // idle socket open before closing it.
ClientSocketPoolBase(int max_sockets,
int max_sockets_per_group,
+ base::TimeDelta unused_idle_socket_timeout,
+ base::TimeDelta used_idle_socket_timeout,
ConnectJobFactory* connect_job_factory)
: helper_(new internal::ClientSocketPoolBaseHelper(
max_sockets, max_sockets_per_group,
+ unused_idle_socket_timeout, used_idle_socket_timeout,
new ConnectJobFactoryAdaptor(connect_job_factory))) {}
~ClientSocketPoolBase() {}
@@ -485,6 +509,10 @@ class ClientSocketPoolBase {
return helper_->NumConnectJobsInGroup(group_name);
}
+ void CleanupIdleSockets(bool force) {
+ return helper_->CleanupIdleSockets(force);
+ }
+
private:
// This adaptor class exists to bridge the
// internal::ClientSocketPoolBaseHelper::ConnectJobFactory and