summaryrefslogtreecommitdiff
path: root/src/mongo/client/connpool.cpp
diff options
context:
space:
mode:
authorCelina Tala <celinahtala@gmail.com>2022-10-10 18:04:41 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-10-10 19:08:12 +0000
commit760512deceaf560464c271ce41ac09754ae308b1 (patch)
treef19c54554d14afe0e290900dc2e51d82f570a9bc /src/mongo/client/connpool.cpp
parent9d5bb60d991c246700db2dc1d619b7d72dcaf7e4 (diff)
downloadmongo-760512deceaf560464c271ce41ac09754ae308b1.tar.gz
SERVER-65132 Added metrics for ScopedDbConnection to acquire egress connections
Diffstat (limited to 'src/mongo/client/connpool.cpp')
-rw-r--r--src/mongo/client/connpool.cpp37
1 files changed, 32 insertions, 5 deletions
diff --git a/src/mongo/client/connpool.cpp b/src/mongo/client/connpool.cpp
index 5a15159ac4b..984751d1767 100644
--- a/src/mongo/client/connpool.cpp
+++ b/src/mongo/client/connpool.cpp
@@ -43,10 +43,12 @@
#include "mongo/client/global_conn_pool.h"
#include "mongo/client/replica_set_monitor.h"
#include "mongo/config.h"
+#include "mongo/db/server_feature_flags_gen.h"
#include "mongo/executor/connection_pool_stats.h"
#include "mongo/logv2/log.h"
#include "mongo/stdx/chrono.h"
#include "mongo/util/exit.h"
+#include "mongo/util/fail_point.h"
#include "mongo/util/net/socket_exception.h"
#if !defined(__has_feature)
@@ -69,8 +71,16 @@ const int kDefaultMaxInUse = std::numeric_limits<int>::max();
auto makeDuration(double secs) {
return Milliseconds(static_cast<Milliseconds::rep>(1000 * secs));
}
+
+void recordWaitTime(PoolForHost& p, DBClientBase* conn, Date_t connRequestedAt) {
+ if (gFeatureFlagConnHealthMetrics.isEnabledAndIgnoreFCV() && conn) {
+ p.recordConnectionWaitTime(connRequestedAt);
+ }
+}
} // namespace
+MONGO_FAIL_POINT_DEFINE(injectWaitTimeForConnpoolAcquisition);
+
using std::endl;
using std::list;
using std::map;
@@ -286,9 +296,16 @@ public:
const std::string& host,
double timeout,
Connect connect) {
+ auto connRequestedAt = Date_t::now();
+ if (MONGO_unlikely(injectWaitTimeForConnpoolAcquisition.shouldFail())) {
+ injectWaitTimeForConnpoolAcquisition.execute([&](const BSONObj& data) {
+ sleepFor(Milliseconds(data["sleepTimeMillis"].numberInt()));
+ });
+ }
+
while (!(_this->_inShutdown.load())) {
// Get a connection from the pool, if there is one.
- std::unique_ptr<DBClientBase> c(_this->_get(host, timeout));
+ std::unique_ptr<DBClientBase> c(_this->_get(host, timeout, connRequestedAt));
if (c) {
// This call may throw.
_this->onHandedOut(c.get());
@@ -318,7 +335,8 @@ public:
// should throw if they cannot create a connection.
auto c = connect();
invariant(c);
- return _this->_finishCreate(host, timeout, c);
+ auto conn = _this->_finishCreate(host, timeout, c, connRequestedAt);
+ return conn;
}
}
}
@@ -354,7 +372,9 @@ void DBConnectionPool::shutdown() {
}
}
-DBClientBase* DBConnectionPool::_get(const string& ident, double socketTimeout) {
+DBClientBase* DBConnectionPool::_get(const string& ident,
+ double socketTimeout,
+ Date_t& connRequestedAt) {
uassert(ErrorCodes::ShutdownInProgress,
"Can't use connection pool during shutdown",
!globalInShutdownDeprecated());
@@ -363,7 +383,9 @@ DBClientBase* DBConnectionPool::_get(const string& ident, double socketTimeout)
p.setMaxPoolSize(_maxPoolSize);
p.setSocketTimeout(socketTimeout);
p.initializeHostName(ident);
- return p.get(this, socketTimeout);
+ auto c = p.get(this, socketTimeout);
+ recordWaitTime(p, c, connRequestedAt);
+ return c;
}
int DBConnectionPool::openConnections(const string& ident, double socketTimeout) {
@@ -374,13 +396,15 @@ int DBConnectionPool::openConnections(const string& ident, double socketTimeout)
DBClientBase* DBConnectionPool::_finishCreate(const string& ident,
double socketTimeout,
- DBClientBase* conn) {
+ DBClientBase* conn,
+ Date_t& connRequestedAt) {
{
stdx::lock_guard<Latch> L(_mutex);
PoolForHost& p = _pools[PoolKey(ident, socketTimeout)];
p.setMaxPoolSize(_maxPoolSize);
p.initializeHostName(ident);
p.createdOne(conn);
+ recordWaitTime(p, conn, connRequestedAt);
}
try {
@@ -598,6 +622,9 @@ void DBConnectionPool::appendConnectionStats(executor::ConnectionPoolStats* stat
0,
0,
Milliseconds{0}};
+ if (gFeatureFlagConnHealthMetrics.isEnabledAndIgnoreFCV()) {
+ hostStats.acquisitionWaitTimes = i->second.connectionWaitTimeStats();
+ }
stats->updateStatsForHost("global", host, hostStats);
}
}