summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTyler Kaye <tyler.kaye@mongodb.com>2018-10-22 17:23:11 -0400
committerTyler Kaye <tyler.kaye@mongodb.com>2019-01-28 09:58:54 -0500
commitcdf319123d8e5d3cd169e2a11aec6aea0b951bf1 (patch)
treea8f046ca114f65812b7d01d5289c8aca327bb195 /src
parent82e05d6c201fa59223aa40340a5d4ad84b32ac65 (diff)
downloadmongo-cdf319123d8e5d3cd169e2a11aec6aea0b951bf1.tar.gz
SERVER-34422-ThreadMetrics: ServerStatus now returns the number of active client operations
Diffstat (limited to 'src')
-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 8ffa987a49d..f2f72ac6ed0 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() {
@@ -235,6 +237,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>());
@@ -252,6 +258,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);
@@ -342,6 +351,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 32091a06ca1..31ad873085a 100644
--- a/src/mongo/db/service_context.h
+++ b/src/mongo/db/service_context.h
@@ -435,6 +435,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 3cb3e71a589..a988293b0ea 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"
@@ -246,6 +247,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"));