From e067fff4e3f3079d070ec168f32c24db9a51a944 Mon Sep 17 00:00:00 2001 From: Geert Bosch Date: Wed, 10 Dec 2014 17:15:45 -0500 Subject: SERVER-16493: Have Client own Locker to amortize initialization cost --- src/mongo/db/client.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'src/mongo/db/client.cpp') diff --git a/src/mongo/db/client.cpp b/src/mongo/db/client.cpp index f7722b7dbec..1b4efbb5281 100644 --- a/src/mongo/db/client.cpp +++ b/src/mongo/db/client.cpp @@ -51,8 +51,10 @@ #include "mongo/db/auth/privilege.h" #include "mongo/db/catalog/database_holder.h" #include "mongo/db/commands.h" +#include "mongo/db/concurrency/lock_state.h" #include "mongo/db/curop.h" #include "mongo/db/dbwebserver.h" +#include "mongo/db/global_environment_experiment.h" #include "mongo/db/instance.h" #include "mongo/db/json.h" #include "mongo/db/jsobj.h" @@ -107,6 +109,17 @@ namespace mongo { clients.insert(client); } +namespace { + // Create an appropriate new locker for the storage engine in use. Caller owns. + Locker* newLocker() { + if (isMMAPV1()) { + return new MMAPV1LockerImpl(); + } + + return new LockerImpl(); + } +} + Client::Client(const string& desc, AbstractMessagingPort *p) : ClientBasic(p), _desc(desc), @@ -114,6 +127,7 @@ namespace mongo { _connectionId(p ? p->connectionId() : 0), _god(0), _txn(NULL), + _locker(newLocker()), _lastOp(0), _shutdown(false) { @@ -335,13 +349,19 @@ namespace mongo { } void Client::setOperationContext(OperationContext* txn) { - // We can only set or unset the OperationContexts, never swap them. - invariant((txn == NULL) ^ (_txn == NULL)); + // We can only set the OperationContext once before resetting it. + invariant(txn != NULL && _txn == NULL); boost::unique_lock uniqueLock(_lock); _txn = txn; } + void Client::resetOperationContext() { + invariant(_txn != NULL); + boost::unique_lock uniqueLock(_lock); + _txn = NULL; + } + string Client::clientAddress(bool includePort) const { if( _curOp ) return _curOp->getRemoteString(includePort); -- cgit v1.2.1