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

Unified Diff: net/base/client_socket_pool.h

Issue 62181: Add a bound on the total number of active sockets in ClientSocketPool.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: do a gclient sync to update files Created 11 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/base/client_socket_pool.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/client_socket_pool.h
===================================================================
--- net/base/client_socket_pool.h (revision 14127)
+++ net/base/client_socket_pool.h (working copy)
@@ -28,7 +28,19 @@
//
class ClientSocketPool : public base::RefCounted<ClientSocketPool> {
public:
- explicit ClientSocketPool(int max_sockets_per_group);
+ // Construct a socket pool with the given limits.
+ //
+ // |max_sockets_per_group|:
+ // The total number of active sockets allowed per "group".
+ // (A "group" generally corresponds with a single host, so this is
+ // effectively the connections-per-host bound).
+ //
+ // |max_sockets|:
+ // The total number of active sockets across all groups.
+ //
+ // TODO(eroman): would be nice to define these in terms of "open" sockets
+ // instead (active + idle).
+ ClientSocketPool(int max_sockets_per_group, int max_sockets);
// Called to request a socket for the given handle. There are three possible
// results: 1) the handle will be initialized with a socket to reuse, 2) the
@@ -110,6 +122,11 @@
std::deque<IdleSocket> idle_sockets;
RequestQueue pending_requests;
int active_socket_count;
+
+ bool empty() const {
+ return active_socket_count == 0 && idle_sockets.empty() &&
+ pending_requests.empty();
+ }
};
typedef std::map<std::string, Group> GroupMap;
@@ -130,6 +147,30 @@
// Called via PostTask by ReleaseSocket.
void DoReleaseSocket(const std::string& group_name, ClientSocketPtr* ptr);
+ // Dequeue and start the highest priority pending request in |group|.
+ void StartPendingRequestForGroup(Group* group);
+
+ // Finds the group containing the highest priority pending request, and which
+ // has fewer than |max_sockets_per_group_| active sockets. Returns NULL if
+ // there is no such group.
+ Group* FindTopStalledGroup();
+
+ // 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.
+ //
+ // This means when a socket is released, the only pending requests that can
+ // be started next belong to the same group.
+ //
+ // However once the |max_sockets_| limit is reached, this stops being true:
+ // groups can now have pending requests without having first reached the
+ // |max_sockets_per_group_| limit. So choosing the next request involves
+ // selecting the highest priority request across *all* groups.
+ //
+ // Since reaching the maximum number of sockets is an edge case, we make note
+ // of when it happens with the following variable, and thus avoid doing
+ // the slower "scan all groups" in the common case.
+ bool may_have_stalled_group_;
+
// Called when timer_ fires. This method scans the idle sockets removing
// sockets that timed out or can't be reused.
void OnCleanupTimerFired() {
@@ -145,9 +186,15 @@
// The total number of idle sockets in the system.
int idle_socket_count_;
- // The maximum number of sockets kept per group.
+ // The total number of active sockets in the system.
+ int active_socket_count_;
+
+ // The maximum number of active sockets kept per group.
int max_sockets_per_group_;
+ // The maximum number of active sockets kept across all groups.
+ int max_sockets_;
+
DISALLOW_COPY_AND_ASSIGN(ClientSocketPool);
};
« no previous file with comments | « no previous file | net/base/client_socket_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698