diff options
author | samantharitter <samantha.ritter@10gen.com> | 2017-04-06 18:14:58 -0400 |
---|---|---|
committer | samantharitter <samantha.ritter@10gen.com> | 2017-04-07 15:15:10 -0400 |
commit | 8e98c05a75c7ee4e0437daad3d4710790ecca480 (patch) | |
tree | 6d31426c4689a251a594fdc0d09d054adadab75b /src | |
parent | 298bfdb518fd202c59864dec1390ffcc730a626b (diff) | |
download | mongo-8e98c05a75c7ee4e0437daad3d4710790ecca480.tar.gz |
SERVER-28652 Log the size of connection pools when we make new egress connections
(cherry-picked from commit 0727327d247902253342c988fad307ce07b3fb01)
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/executor/connection_pool.cpp | 21 | ||||
-rw-r--r-- | src/mongo/executor/connection_pool.h | 3 | ||||
-rw-r--r-- | src/mongo/executor/network_interface_asio_command.cpp | 6 |
3 files changed, 27 insertions, 3 deletions
diff --git a/src/mongo/executor/connection_pool.cpp b/src/mongo/executor/connection_pool.cpp index 631df12fe5d..7fcc7fe53dc 100644 --- a/src/mongo/executor/connection_pool.cpp +++ b/src/mongo/executor/connection_pool.cpp @@ -98,6 +98,13 @@ public: */ size_t createdConnections(const stdx::unique_lock<stdx::mutex>& lk); + /** + * Returns the total number of connections currently open that belong to + * this pool. This is the sum of refreshingConnections, availableConnections, + * and inUseConnections. + */ + size_t openConnections(const stdx::unique_lock<stdx::mutex>& lk); + private: using OwnedConnection = std::unique_ptr<ConnectionInterface>; using OwnershipPool = std::unordered_map<ConnectionInterface*, OwnedConnection>; @@ -229,6 +236,16 @@ void ConnectionPool::appendConnectionStats(ConnectionPoolStats* stats) const { } } +size_t ConnectionPool::getNumConnectionsPerHost(const HostAndPort& hostAndPort) const { + stdx::unique_lock<stdx::mutex> lk(_mutex); + auto iter = _pools.find(hostAndPort); + if (iter != _pools.end()) { + return iter->second->openConnections(lk); + } + + return 0; +} + void ConnectionPool::returnConnection(ConnectionInterface* conn) { stdx::unique_lock<stdx::mutex> lk(_mutex); @@ -266,6 +283,10 @@ size_t ConnectionPool::SpecificPool::createdConnections(const stdx::unique_lock< return _created; } +size_t ConnectionPool::SpecificPool::openConnections(const stdx::unique_lock<stdx::mutex>& lk) { + return _checkedOutPool.size() + _readyPool.size() + _processingPool.size(); +} + void ConnectionPool::SpecificPool::getConnection(const HostAndPort& hostAndPort, Milliseconds timeout, stdx::unique_lock<stdx::mutex> lk, diff --git a/src/mongo/executor/connection_pool.h b/src/mongo/executor/connection_pool.h index 83dbe54d240..ffa5495602f 100644 --- a/src/mongo/executor/connection_pool.h +++ b/src/mongo/executor/connection_pool.h @@ -121,6 +121,8 @@ public: void appendConnectionStats(ConnectionPoolStats* stats) const; + size_t getNumConnectionsPerHost(const HostAndPort& hostAndPort) const; + private: void returnConnection(ConnectionInterface* connection); @@ -190,7 +192,6 @@ class ConnectionPool::ConnectionInterface : public TimerInterface { public: ConnectionInterface() = default; - virtual ~ConnectionInterface() = default; /** diff --git a/src/mongo/executor/network_interface_asio_command.cpp b/src/mongo/executor/network_interface_asio_command.cpp index 6a4677d4dfa..57b77298b42 100644 --- a/src/mongo/executor/network_interface_asio_command.cpp +++ b/src/mongo/executor/network_interface_asio_command.cpp @@ -235,9 +235,11 @@ void NetworkInterfaceASIO::_beginCommunication(AsyncOp* op) { // codepath. if (op->_inSetup) { + auto host = op->request().target; auto getConnectionDuration = now() - op->start(); - log() << "Successfully connected to " << op->request().target.toString() << ", took " - << getConnectionDuration; + log() << "Successfully connected to " << host << ", took " << getConnectionDuration << " (" + << _connectionPool.getNumConnectionsPerHost(host) << " connections now open to " + << host << ")"; op->_inSetup = false; op->finish(RemoteCommandResponse()); return; |