summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsamantharitter <samantha.ritter@10gen.com>2017-04-06 18:14:58 -0400
committersamantharitter <samantha.ritter@10gen.com>2017-04-07 15:11:39 -0400
commit208bcdd027b17551631535614ec003a45740a7ab (patch)
treea15041c5515bd8612b633338593acf8e9d63fd3e
parent2d22e8bf64e97a2b1ef6f755fe3aebaee474e677 (diff)
downloadmongo-208bcdd027b17551631535614ec003a45740a7ab.tar.gz
SERVER-28652 Log the size of connection pools when we make new egress connections
-rw-r--r--src/mongo/executor/connection_pool.cpp21
-rw-r--r--src/mongo/executor/connection_pool.h3
-rw-r--r--src/mongo/executor/network_interface_asio_command.cpp6
3 files changed, 27 insertions, 3 deletions
diff --git a/src/mongo/executor/connection_pool.cpp b/src/mongo/executor/connection_pool.cpp
index 188772d8aee..80b993e4b38 100644
--- a/src/mongo/executor/connection_pool.cpp
+++ b/src/mongo/executor/connection_pool.cpp
@@ -104,6 +104,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 = stdx::unordered_map<ConnectionInterface*, OwnedConnection>;
@@ -238,6 +245,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);
@@ -280,6 +297,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 492ba6fe7da..b644c0ae148 100644
--- a/src/mongo/executor/connection_pool.h
+++ b/src/mongo/executor/connection_pool.h
@@ -123,6 +123,8 @@ public:
void appendConnectionStats(ConnectionPoolStats* stats) const;
+ size_t getNumConnectionsPerHost(const HostAndPort& hostAndPort) const;
+
private:
void returnConnection(ConnectionInterface* connection);
@@ -194,7 +196,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 f9e45311eff..52d523e7d97 100644
--- a/src/mongo/executor/network_interface_asio_command.cpp
+++ b/src/mongo/executor/network_interface_asio_command.cpp
@@ -238,9 +238,11 @@ void NetworkInterfaceASIO::_beginCommunication(AsyncOp* op) {
// so we can proceed with user operations after they return to this
// 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;