summaryrefslogtreecommitdiff
path: root/src/mongo/executor/connection_pool.cpp
diff options
context:
space:
mode:
authorsamantharitter <samantha.ritter@10gen.com>2015-09-22 11:19:30 -0400
committersamantharitter <samantha.ritter@10gen.com>2015-10-13 08:34:17 -0400
commit4877c6b197438495d9fdd88317d4b79d565014c6 (patch)
treecaf9d06036f844774753abbbf68e985378269249 /src/mongo/executor/connection_pool.cpp
parent16d50744c22953720be2cd96fd536c6416d96295 (diff)
downloadmongo-4877c6b197438495d9fdd88317d4b79d565014c6.tar.gz
SERVER-20283 Update connPoolStats command to include multiple connection pools
Diffstat (limited to 'src/mongo/executor/connection_pool.cpp')
-rw-r--r--src/mongo/executor/connection_pool.cpp76
1 files changed, 74 insertions, 2 deletions
diff --git a/src/mongo/executor/connection_pool.cpp b/src/mongo/executor/connection_pool.cpp
index 0fb0e1ded00..aa5e995600b 100644
--- a/src/mongo/executor/connection_pool.cpp
+++ b/src/mongo/executor/connection_pool.cpp
@@ -29,6 +29,7 @@
#include "mongo/executor/connection_pool.h"
+#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/stdx/memory.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/scopeguard.h"
@@ -57,7 +58,7 @@ public:
~SpecificPool();
/**
- * Get's a connection from the specific pool. Sinks a unique_lock from the
+ * Gets a connection from the specific pool. Sinks a unique_lock from the
* parent to preserve the lock on _mutex
*/
void getConnection(const HostAndPort& hostAndPort,
@@ -66,7 +67,7 @@ public:
GetConnectionCallback cb);
/**
- * Cascade a failure across existing connections and requests. Invoking
+ * Cascades a failure across existing connections and requests. Invoking
* this function drops all current connections and fails all current
* requests with the passed status.
*/
@@ -78,6 +79,21 @@ public:
*/
void returnConnection(ConnectionInterface* connection, stdx::unique_lock<stdx::mutex> lk);
+ /**
+ * Returns the number of connections currently checked out of the pool.
+ */
+ size_t inUseConnections(const stdx::unique_lock<stdx::mutex>& lk);
+
+ /**
+ * Returns the number of available connections in the pool.
+ */
+ size_t availableConnections(const stdx::unique_lock<stdx::mutex>& lk);
+
+ /**
+ * Returns the total number of connections ever created in this pool.
+ */
+ size_t createdConnections(const stdx::unique_lock<stdx::mutex>& lk);
+
private:
using OwnedConnection = std::unique_ptr<ConnectionInterface>;
using OwnershipPool = std::unordered_map<ConnectionInterface*, OwnedConnection>;
@@ -118,6 +134,8 @@ private:
size_t _generation;
bool _inFulfillRequests;
+ size_t _created;
+
/**
* The current state of the pool
*
@@ -187,6 +205,44 @@ void ConnectionPool::get(const HostAndPort& hostAndPort,
pool->getConnection(hostAndPort, timeout, std::move(lk), std::move(cb));
}
+void ConnectionPool::appendConnectionStats(BSONObjBuilder* b) {
+ size_t inUse = 0u;
+ size_t available = 0u;
+ size_t created = 0u;
+
+ BSONObjBuilder hostBuilder(b->subobjStart("hosts"));
+
+ stdx::unique_lock<stdx::mutex> lk(_mutex);
+
+ for (const auto& kv : _pools) {
+ std::string label = kv.first.toString();
+ BSONObjBuilder hostInfo(hostBuilder.subobjStart(label));
+
+ auto& pool = kv.second;
+ auto inUseConnections = pool->inUseConnections(lk);
+ auto availableConnections = pool->availableConnections(lk);
+ auto createdConnections = pool->createdConnections(lk);
+ hostInfo.appendNumber("inUse", inUseConnections);
+ hostInfo.appendNumber("available", availableConnections);
+ hostInfo.appendNumber("created", createdConnections);
+
+ hostInfo.done();
+
+ // update available and created
+ inUse += inUseConnections;
+ available += availableConnections;
+ created += createdConnections;
+ }
+
+ hostBuilder.done();
+
+ b->appendNumber("totalInUse", inUse);
+ b->appendNumber("totalAvailable", available);
+ b->appendNumber("totalCreated", created);
+
+ return;
+}
+
void ConnectionPool::returnConnection(ConnectionInterface* conn) {
stdx::unique_lock<stdx::mutex> lk(_mutex);
@@ -203,12 +259,26 @@ ConnectionPool::SpecificPool::SpecificPool(ConnectionPool* parent, const HostAnd
_requestTimer(parent->_factory->makeTimer()),
_generation(0),
_inFulfillRequests(false),
+ _created(0),
_state(State::kRunning) {}
ConnectionPool::SpecificPool::~SpecificPool() {
DESTRUCTOR_GUARD(_requestTimer->cancelTimeout();)
}
+size_t ConnectionPool::SpecificPool::inUseConnections(const stdx::unique_lock<stdx::mutex>& lk) {
+ return _checkedOutPool.size();
+}
+
+size_t ConnectionPool::SpecificPool::availableConnections(
+ const stdx::unique_lock<stdx::mutex>& lk) {
+ return _readyPool.size();
+}
+
+size_t ConnectionPool::SpecificPool::createdConnections(const stdx::unique_lock<stdx::mutex>& lk) {
+ return _created;
+}
+
void ConnectionPool::SpecificPool::getConnection(const HostAndPort& hostAndPort,
Milliseconds timeout,
stdx::unique_lock<stdx::mutex> lk,
@@ -414,6 +484,8 @@ void ConnectionPool::SpecificPool::spawnConnections(stdx::unique_lock<stdx::mute
auto connPtr = handle.get();
_processingPool[connPtr] = std::move(handle);
+ ++_created;
+
// Run the setup callback
lk.unlock();
connPtr->setup(_parent->_options.refreshTimeout,