diff options
author | samantharitter <samantha.ritter@10gen.com> | 2015-09-22 11:19:30 -0400 |
---|---|---|
committer | samantharitter <samantha.ritter@10gen.com> | 2015-10-13 08:34:17 -0400 |
commit | 4877c6b197438495d9fdd88317d4b79d565014c6 (patch) | |
tree | caf9d06036f844774753abbbf68e985378269249 /src/mongo/executor | |
parent | 16d50744c22953720be2cd96fd536c6416d96295 (diff) | |
download | mongo-4877c6b197438495d9fdd88317d4b79d565014c6.tar.gz |
SERVER-20283 Update connPoolStats command to include multiple connection pools
Diffstat (limited to 'src/mongo/executor')
-rw-r--r-- | src/mongo/executor/connection_pool.cpp | 76 | ||||
-rw-r--r-- | src/mongo/executor/connection_pool.h | 7 | ||||
-rw-r--r-- | src/mongo/executor/network_interface.h | 8 | ||||
-rw-r--r-- | src/mongo/executor/network_interface_asio.cpp | 4 | ||||
-rw-r--r-- | src/mongo/executor/network_interface_asio.h | 1 | ||||
-rw-r--r-- | src/mongo/executor/network_interface_impl.cpp | 2 | ||||
-rw-r--r-- | src/mongo/executor/network_interface_impl.h | 1 | ||||
-rw-r--r-- | src/mongo/executor/network_interface_mock.cpp | 2 | ||||
-rw-r--r-- | src/mongo/executor/network_interface_mock.h | 1 | ||||
-rw-r--r-- | src/mongo/executor/task_executor.h | 7 | ||||
-rw-r--r-- | src/mongo/executor/thread_pool_task_executor.cpp | 4 | ||||
-rw-r--r-- | src/mongo/executor/thread_pool_task_executor.h | 2 |
12 files changed, 110 insertions, 5 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, diff --git a/src/mongo/executor/connection_pool.h b/src/mongo/executor/connection_pool.h index d46b18b9812..a5d1676bf0e 100644 --- a/src/mongo/executor/connection_pool.h +++ b/src/mongo/executor/connection_pool.h @@ -38,6 +38,9 @@ #include "mongo/util/net/hostandport.h" namespace mongo { + +class BSONObjBuilder; + namespace executor { /** @@ -110,9 +113,7 @@ public: void get(const HostAndPort& hostAndPort, Milliseconds timeout, GetConnectionCallback cb); - /** - * TODO add a function returning connection pool stats - */ + void appendConnectionStats(BSONObjBuilder* b); private: void returnConnection(ConnectionInterface* connection); diff --git a/src/mongo/executor/network_interface.h b/src/mongo/executor/network_interface.h index 8b151b5b54e..8776506b0fe 100644 --- a/src/mongo/executor/network_interface.h +++ b/src/mongo/executor/network_interface.h @@ -36,6 +36,9 @@ #include "mongo/stdx/functional.h" namespace mongo { + +class BSONObjBuilder; + namespace executor { /** @@ -59,6 +62,11 @@ public: virtual std::string getDiagnosticString() = 0; /** + * Appends connection information to the provided BSONObjBuilder. + */ + virtual void appendConnectionStats(BSONObjBuilder* b) = 0; + + /** * Starts up the network interface. * * It is valid to call all methods except shutdown() before this method completes. That is, diff --git a/src/mongo/executor/network_interface_asio.cpp b/src/mongo/executor/network_interface_asio.cpp index 0379738ee93..19f38107de6 100644 --- a/src/mongo/executor/network_interface_asio.cpp +++ b/src/mongo/executor/network_interface_asio.cpp @@ -90,6 +90,10 @@ std::string NetworkInterfaceASIO::getDiagnosticString() { return output; } +void NetworkInterfaceASIO::appendConnectionStats(BSONObjBuilder* b) { + _connectionPool.appendConnectionStats(b); +} + std::string NetworkInterfaceASIO::getHostName() { return getHostNameCached(); } diff --git a/src/mongo/executor/network_interface_asio.h b/src/mongo/executor/network_interface_asio.h index 2c44039b48c..91fc0858824 100644 --- a/src/mongo/executor/network_interface_asio.h +++ b/src/mongo/executor/network_interface_asio.h @@ -100,6 +100,7 @@ public: NetworkInterfaceASIO(Options = Options()); std::string getDiagnosticString() override; + void appendConnectionStats(BSONObjBuilder* b) override; std::string getHostName() override; void startup() override; void shutdown() override; diff --git a/src/mongo/executor/network_interface_impl.cpp b/src/mongo/executor/network_interface_impl.cpp index 869ea22d0b2..e7eb502e320 100644 --- a/src/mongo/executor/network_interface_impl.cpp +++ b/src/mongo/executor/network_interface_impl.cpp @@ -87,6 +87,8 @@ std::string NetworkInterfaceImpl::getDiagnosticString() { return output; } +void NetworkInterfaceImpl::appendConnectionStats(BSONObjBuilder* b) {} + void NetworkInterfaceImpl::startup() { stdx::unique_lock<stdx::mutex> lk(_mutex); invariant(!_inShutdown); diff --git a/src/mongo/executor/network_interface_impl.h b/src/mongo/executor/network_interface_impl.h index 793e574a552..bc422c59be0 100644 --- a/src/mongo/executor/network_interface_impl.h +++ b/src/mongo/executor/network_interface_impl.h @@ -77,6 +77,7 @@ public: NetworkInterfaceImpl(std::unique_ptr<NetworkConnectionHook> hook); ~NetworkInterfaceImpl(); std::string getDiagnosticString() override; + void appendConnectionStats(BSONObjBuilder* b) override; void startup() override; void shutdown() override; void waitForWork() override; diff --git a/src/mongo/executor/network_interface_mock.cpp b/src/mongo/executor/network_interface_mock.cpp index d62b13d87ae..fe0aef336be 100644 --- a/src/mongo/executor/network_interface_mock.cpp +++ b/src/mongo/executor/network_interface_mock.cpp @@ -63,6 +63,8 @@ std::string NetworkInterfaceMock::getDiagnosticString() { return "NetworkInterfaceMock diagnostics here"; } +void NetworkInterfaceMock::appendConnectionStats(BSONObjBuilder* b) {} + Date_t NetworkInterfaceMock::now() { stdx::lock_guard<stdx::mutex> lk(_mutex); return _now_inlock(); diff --git a/src/mongo/executor/network_interface_mock.h b/src/mongo/executor/network_interface_mock.h index 0b231295595..8272bf84509 100644 --- a/src/mongo/executor/network_interface_mock.h +++ b/src/mongo/executor/network_interface_mock.h @@ -75,6 +75,7 @@ public: NetworkInterfaceMock(); virtual ~NetworkInterfaceMock(); + virtual void appendConnectionStats(BSONObjBuilder* b); virtual std::string getDiagnosticString(); //////////////////////////////////////////////////////////////////////////////// diff --git a/src/mongo/executor/task_executor.h b/src/mongo/executor/task_executor.h index 74ba98048c4..be7d61b6a1b 100644 --- a/src/mongo/executor/task_executor.h +++ b/src/mongo/executor/task_executor.h @@ -43,6 +43,7 @@ namespace mongo { +class BSONObjBuilder; class OperationContext; namespace executor { @@ -230,6 +231,12 @@ public: */ virtual void wait(const CallbackHandle& cbHandle) = 0; + /** + * Appends information about the underlying network interface's connections to the given + * builder. + */ + virtual void appendConnectionStats(BSONObjBuilder* b) = 0; + protected: TaskExecutor(); diff --git a/src/mongo/executor/thread_pool_task_executor.cpp b/src/mongo/executor/thread_pool_task_executor.cpp index d70c89abfd4..dae256abc09 100644 --- a/src/mongo/executor/thread_pool_task_executor.cpp +++ b/src/mongo/executor/thread_pool_task_executor.cpp @@ -342,6 +342,10 @@ void ThreadPoolTaskExecutor::wait(const CallbackHandle& cbHandle) { waitForEvent(cbState->finishedEvent); } +void ThreadPoolTaskExecutor::appendConnectionStats(BSONObjBuilder* b) { + _net->appendConnectionStats(b); +} + void ThreadPoolTaskExecutor::cancelAllCommands() { _net->cancelAllCommands(); } diff --git a/src/mongo/executor/thread_pool_task_executor.h b/src/mongo/executor/thread_pool_task_executor.h index e709440dd92..e983c91de49 100644 --- a/src/mongo/executor/thread_pool_task_executor.h +++ b/src/mongo/executor/thread_pool_task_executor.h @@ -80,6 +80,8 @@ public: void cancel(const CallbackHandle& cbHandle) override; void wait(const CallbackHandle& cbHandle) override; + void appendConnectionStats(BSONObjBuilder* b) override; + /** * Cancels all commands on the network interface. */ |