summaryrefslogtreecommitdiff
path: root/src/mongo/client
diff options
context:
space:
mode:
authorsamantharitter <samantha.ritter@10gen.com>2015-11-20 18:31:32 -0500
committersamantharitter <samantha.ritter@10gen.com>2015-12-14 15:39:39 -0500
commit7c67e25f37853c60c106d2cf08eca1b81c4133ae (patch)
tree17ac78dad87d4a200de9e51caacaf80152ef3994 /src/mongo/client
parent30d55cccf89160749c401e19fdc9872e24b01ef2 (diff)
downloadmongo-7c67e25f37853c60c106d2cf08eca1b81c4133ae.tar.gz
SERVER-21597 Fix connPoolStats to work with many NetworkInterfaces
Diffstat (limited to 'src/mongo/client')
-rw-r--r--src/mongo/client/SConscript1
-rw-r--r--src/mongo/client/connpool.cpp48
-rw-r--r--src/mongo/client/connpool.h8
3 files changed, 27 insertions, 30 deletions
diff --git a/src/mongo/client/SConscript b/src/mongo/client/SConscript
index e0a9f7fedc0..fabc96d0712 100644
--- a/src/mongo/client/SConscript
+++ b/src/mongo/client/SConscript
@@ -137,6 +137,7 @@ env.Library(
'$BUILD_DIR/mongo/db/auth/authcommon',
'$BUILD_DIR/mongo/db/commands/test_commands_enabled',
'$BUILD_DIR/mongo/db/dbmessage',
+ '$BUILD_DIR/mongo/executor/connection_pool_stats',
'$BUILD_DIR/mongo/rpc/command_status',
'$BUILD_DIR/mongo/rpc/rpc',
'$BUILD_DIR/mongo/util/net/network',
diff --git a/src/mongo/client/connpool.cpp b/src/mongo/client/connpool.cpp
index ef070e456d6..2a019db9787 100644
--- a/src/mongo/client/connpool.cpp
+++ b/src/mongo/client/connpool.cpp
@@ -35,9 +35,14 @@
#include "mongo/platform/basic.h"
#include "mongo/client/connpool.h"
+
+#include <string>
+
+#include "mongo/client/connection_string.h"
#include "mongo/client/global_conn_pool.h"
#include "mongo/client/replica_set_monitor.h"
#include "mongo/client/syncclusterconnection.h"
+#include "mongo/executor/connection_pool_stats.h"
#include "mongo/util/exit.h"
#include "mongo/util/log.h"
@@ -341,41 +346,28 @@ void DBConnectionPool::onDestroy(DBClientBase* conn) {
}
}
-void DBConnectionPool::appendInfo(BSONObjBuilder& b) {
- int totalInUse = 0;
- int totalAvailable = 0;
- long long totalCreated = 0;
-
- BSONObjBuilder bb(b.subobjStart("hosts"));
+void DBConnectionPool::appendConnectionStats(executor::ConnectionPoolStats* stats) const {
{
stdx::lock_guard<stdx::mutex> lk(_mutex);
- for (PoolMap::iterator i = _pools.begin(); i != _pools.end(); ++i) {
+ for (PoolMap::const_iterator i = _pools.begin(); i != _pools.end(); ++i) {
if (i->second.numCreated() == 0)
continue;
- auto inUse = i->second.numInUse();
- auto available = i->second.numAvailable();
- auto created = i->second.numCreated();
-
- string s = str::stream() << i->first.ident << "::" << i->first.timeout;
- BSONObjBuilder temp(bb.subobjStart(s));
-
- temp.append("inUse", inUse);
- temp.append("available", available);
- temp.appendNumber("created", created);
-
- temp.done();
-
- totalInUse += inUse;
- totalAvailable += available;
- totalCreated += created;
+ // Mongos may use either a replica set uri or a list of addresses as
+ // the identifier here, so we always take the first server parsed out
+ // as our label for connPoolStats. Note that these stats will collide
+ // with any existing stats for the chosen host.
+ auto uri = ConnectionString::parse(i->first.ident);
+ invariant(uri.isOK());
+ HostAndPort host = uri.getValue().getServers().front();
+
+ executor::ConnectionStatsPerHost hostStats{
+ static_cast<size_t>(i->second.numInUse()),
+ static_cast<size_t>(i->second.numAvailable()),
+ static_cast<size_t>(i->second.numCreated())};
+ stats->updateStatsForHost(host, hostStats);
}
}
- bb.done();
-
- b.append("totalInUse", totalInUse);
- b.append("totalAvailable", totalAvailable);
- b.appendNumber("totalCreated", totalCreated);
}
bool DBConnectionPool::serverNameCompare::operator()(const string& a, const string& b) const {
diff --git a/src/mongo/client/connpool.h b/src/mongo/client/connpool.h
index 570510ee2b3..586f1958319 100644
--- a/src/mongo/client/connpool.h
+++ b/src/mongo/client/connpool.h
@@ -42,6 +42,10 @@ namespace mongo {
class BSONObjBuilder;
class DBConnectionPool;
+namespace executor {
+struct ConnectionPoolStats;
+} // namespace executor
+
/**
* not thread safe
* thread safety is handled by DBConnectionPool
@@ -224,7 +228,7 @@ public:
void release(const std::string& host, DBClientBase* c);
void addHook(DBConnectionHook* hook); // we take ownership
- void appendInfo(BSONObjBuilder& b);
+ void appendConnectionStats(executor::ConnectionPoolStats* stats) const;
/**
* Clears all connections for all host.
@@ -274,7 +278,7 @@ private:
typedef std::map<PoolKey, PoolForHost, poolKeyCompare> PoolMap; // servername -> pool
- stdx::mutex _mutex;
+ mutable stdx::mutex _mutex;
std::string _name;
// The maximum number of connections we'll save in the pool per-host