summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTyler Kaye <tyler.kaye@mongodb.com>2018-10-22 17:23:11 -0400
committerJason Carey <jcarey@argv.me>2019-03-12 16:36:56 -0400
commit701cf71ba3e8ffa706bfb49d3ea2d44dc1654126 (patch)
treebe5d36fe8cd89246a5b1421140872566e8b05d54
parent6df770b3a6dc44170389050a4063ffb027357b46 (diff)
downloadmongo-701cf71ba3e8ffa706bfb49d3ea2d44dc1654126.tar.gz
SERVER-34422-ThreadMetrics: ServerStatus now returns the number of active client operations
(cherry picked from commit cdf319123d8e5d3cd169e2a11aec6aea0b951bf1)
-rw-r--r--src/mongo/db/service_context.cpp13
-rw-r--r--src/mongo/db/service_context.h5
-rw-r--r--src/mongo/transport/service_entry_point_impl.cpp4
3 files changed, 22 insertions, 0 deletions
diff --git a/src/mongo/db/service_context.cpp b/src/mongo/db/service_context.cpp
index d1089916327..0930c9c9a61 100644
--- a/src/mongo/db/service_context.cpp
+++ b/src/mongo/db/service_context.cpp
@@ -59,6 +59,8 @@ using ConstructorActionList = stdx::list<ServiceContext::ConstructorDestructorAc
ServiceContext* globalServiceContext = nullptr;
+AtomicWord<int> _numCurrentOps{0};
+
} // namespace
bool hasGlobalServiceContext() {
@@ -239,6 +241,10 @@ void ServiceContext::ClientDeleter::operator()(Client* client) const {
ServiceContext::UniqueOperationContext ServiceContext::makeOperationContext(Client* client) {
auto opCtx = std::make_unique<OperationContext>(client, _nextOpId.fetchAndAdd(1));
+ if (client && client->session()) {
+ _numCurrentOps.addAndFetch(1);
+ }
+
onCreate(opCtx.get(), _clientObservers);
if (!opCtx->lockState()) {
opCtx->setLockState(std::make_unique<LockerNoop>());
@@ -256,6 +262,9 @@ ServiceContext::UniqueOperationContext ServiceContext::makeOperationContext(Clie
void ServiceContext::OperationContextDeleter::operator()(OperationContext* opCtx) const {
auto client = opCtx->getClient();
+ if (client && client->session()) {
+ _numCurrentOps.subtractAndFetch(1);
+ }
auto service = client->getServiceContext();
{
stdx::lock_guard<Client> lk(*client);
@@ -356,6 +365,10 @@ void ServiceContext::notifyStartupComplete() {
_startupCompleteCondVar.notify_all();
}
+int ServiceContext::getActiveClientOperations() {
+ return _numCurrentOps.load();
+}
+
namespace {
/**
diff --git a/src/mongo/db/service_context.h b/src/mongo/db/service_context.h
index 96e965d53c7..55b0545171e 100644
--- a/src/mongo/db/service_context.h
+++ b/src/mongo/db/service_context.h
@@ -432,6 +432,11 @@ public:
*/
void notifyStartupComplete();
+ /*
+ * Returns the number of active client operations
+ */
+ int getActiveClientOperations();
+
/**
* Set the OpObserver.
*/
diff --git a/src/mongo/transport/service_entry_point_impl.cpp b/src/mongo/transport/service_entry_point_impl.cpp
index a4935cb0fdc..2dc1562ffdb 100644
--- a/src/mongo/transport/service_entry_point_impl.cpp
+++ b/src/mongo/transport/service_entry_point_impl.cpp
@@ -37,6 +37,7 @@
#include <vector>
#include "mongo/db/auth/restriction_environment.h"
+#include "mongo/db/service_context.h"
#include "mongo/transport/service_state_machine.h"
#include "mongo/transport/session.h"
#include "mongo/util/log.h"
@@ -244,6 +245,9 @@ void ServiceEntryPointImpl::appendStats(BSONObjBuilder* bob) const {
bob->append("current", static_cast<int>(sessionCount));
bob->append("available", static_cast<int>(_maxNumConnections - sessionCount));
bob->append("totalCreated", static_cast<int>(_createdConnections.load()));
+ if (auto sc = getGlobalServiceContext()) {
+ bob->append("active", static_cast<int>(sc->getActiveClientOperations()));
+ }
if (_adminInternalPool) {
BSONObjBuilder section(bob->subobjStart("adminConnections"));