diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/db/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/db/commands/server_status.cpp | 26 | ||||
-rw-r--r-- | src/mongo/db/db.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/exec/plan_stats.h | 1 | ||||
-rw-r--r-- | src/mongo/db/ftdc/ftdc_test.cpp | 1 | ||||
-rw-r--r-- | src/mongo/db/repl/rs_rollback.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/s/sharding_state_test.cpp | 1 | ||||
-rw-r--r-- | src/mongo/db/service_context_d.cpp | 8 | ||||
-rw-r--r-- | src/mongo/s/server.cpp | 4 | ||||
-rw-r--r-- | src/mongo/s/sharding_test_fixture.cpp | 1 |
11 files changed, 35 insertions, 16 deletions
diff --git a/src/mongo/SConscript b/src/mongo/SConscript index 3fb79a82781..19bb5577f93 100644 --- a/src/mongo/SConscript +++ b/src/mongo/SConscript @@ -302,6 +302,7 @@ env.Install( 's/coreshard', 's/mongoscore', 's/sharding_initialization', + 'util/clock_sources', 'util/ntservice', 'util/options_parser/options_parser_init', ])) diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript index 5b68bb4454f..8f712df363f 100644 --- a/src/mongo/db/SConscript +++ b/src/mongo/db/SConscript @@ -696,6 +696,7 @@ serveronlyLibdeps = [ "$BUILD_DIR/mongo/s/coreshard", "$BUILD_DIR/mongo/s/serveronly", "$BUILD_DIR/mongo/scripting/scripting_server", + "$BUILD_DIR/mongo/util/clock_sources", "$BUILD_DIR/mongo/util/elapsed_tracker", "$BUILD_DIR/mongo/util/net/network", "$BUILD_DIR/mongo/db/storage/mmap_v1/file_allocator", diff --git a/src/mongo/db/commands/server_status.cpp b/src/mongo/db/commands/server_status.cpp index 423991bdbfc..9570b212f64 100644 --- a/src/mongo/db/commands/server_status.cpp +++ b/src/mongo/db/commands/server_status.cpp @@ -53,6 +53,7 @@ #include "mongo/util/net/ssl_manager.h" #include "mongo/util/processinfo.h" #include "mongo/util/ramlog.h" +#include "mongo/util/time_support.h" #include "mongo/util/version.h" namespace mongo { @@ -64,8 +65,7 @@ using std::stringstream; class CmdServerStatus : public Command { public: - CmdServerStatus() - : Command("serverStatus", true), _started(curTimeMillis64()), _runCalled(false) {} + CmdServerStatus() : Command("serverStatus", true), _started(Date_t::now()), _runCalled(false) {} virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; @@ -92,11 +92,12 @@ public: BSONObjBuilder& result) { _runCalled = true; - long long start = Listener::getElapsedTimeMillis(); + const auto service = txn->getServiceContext(); + const auto clock = service->getFastClockSource(); + const auto runStart = clock->now(); BSONObjBuilder timeBuilder(256); const auto authSession = AuthorizationSession::get(ClientBasic::getCurrent()); - auto service = txn->getServiceContext(); auto canonicalizer = HostnameCanonicalizationWorker::get(service); // --- basic fields that are global @@ -108,11 +109,13 @@ public: result.append("process", serverGlobalParams.binaryName); result.append("pid", ProcessId::getCurrent().asLongLong()); result.append("uptime", (double)(time(0) - serverGlobalParams.started)); - result.append("uptimeMillis", (long long)(curTimeMillis64() - _started)); - result.append("uptimeEstimate", (double)(start / 1000)); + auto uptime = clock->now() - _started; + result.append("uptimeMillis", durationCount<Milliseconds>(uptime)); + result.append("uptimeEstimate", durationCount<Seconds>(uptime)); result.appendDate("localTime", jsTime()); - timeBuilder.appendNumber("after basic", Listener::getElapsedTimeMillis() - start); + timeBuilder.appendNumber("after basic", + durationCount<Milliseconds>(clock->now() - runStart)); // --- all sections @@ -141,7 +144,7 @@ public: result.append(section->getSectionName(), data); timeBuilder.appendNumber( static_cast<string>(str::stream() << "after " << section->getSectionName()), - Listener::getElapsedTimeMillis() - start); + durationCount<Milliseconds>(clock->now() - runStart)); } // --- counters @@ -166,8 +169,9 @@ public: } } - timeBuilder.appendNumber("at end", Listener::getElapsedTimeMillis() - start); - if (Listener::getElapsedTimeMillis() - start > 1000) { + auto runElapsed = clock->now() - runStart; + timeBuilder.appendNumber("at end", durationCount<Milliseconds>(runElapsed)); + if (runElapsed > Milliseconds(1000)) { BSONObj t = timeBuilder.obj(); log() << "serverStatus was very slow: " << t << endl; result.append("timing", t); @@ -185,7 +189,7 @@ public: } private: - const unsigned long long _started; + const Date_t _started; bool _runCalled; typedef map<string, ServerStatusSection*> SectionMap; diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp index a29a65f66c4..5f3c973c476 100644 --- a/src/mongo/db/db.cpp +++ b/src/mongo/db/db.cpp @@ -116,6 +116,7 @@ #include "mongo/util/concurrency/thread_name.h" #include "mongo/util/exception_filter_win32.h" #include "mongo/util/exit.h" +#include "mongo/util/fast_clock_source_factory.h" #include "mongo/util/log.h" #include "mongo/util/net/hostname_canonicalization_worker.h" #include "mongo/util/net/message_server.h" @@ -509,6 +510,7 @@ static void _initAndListen(int listenPort) { Client::initThread("initandlisten"); _initWireSpec(); + getGlobalServiceContext()->setFastClockSource(FastClockSourceFactory::create(Milliseconds(10))); getGlobalServiceContext()->setOpObserver(stdx::make_unique<OpObserver>()); const repl::ReplSettings& replSettings = repl::getGlobalReplicationCoordinator()->getSettings(); diff --git a/src/mongo/db/exec/plan_stats.h b/src/mongo/db/exec/plan_stats.h index db63627c6fd..9c288dabb11 100644 --- a/src/mongo/db/exec/plan_stats.h +++ b/src/mongo/db/exec/plan_stats.h @@ -37,7 +37,6 @@ #include "mongo/db/jsobj.h" #include "mongo/db/query/stage_types.h" #include "mongo/util/time_support.h" -#include "mongo/util/net/listen.h" // for Listener::getElapsedTimeMillis() namespace mongo { diff --git a/src/mongo/db/ftdc/ftdc_test.cpp b/src/mongo/db/ftdc/ftdc_test.cpp index aa8429daf31..fe10d5db21e 100644 --- a/src/mongo/db/ftdc/ftdc_test.cpp +++ b/src/mongo/db/ftdc/ftdc_test.cpp @@ -112,6 +112,7 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(FTDCTestInit, ("ThreadNameInitializer"))(InitializerContext* context) { setGlobalServiceContext(stdx::make_unique<ServiceContextNoop>()); + getGlobalServiceContext()->setFastClockSource(stdx::make_unique<ClockSourceMock>()); getGlobalServiceContext()->setPreciseClockSource(stdx::make_unique<ClockSourceMock>()); Client::initThreadIfNotAlready("UnitTest"); diff --git a/src/mongo/db/repl/rs_rollback.cpp b/src/mongo/db/repl/rs_rollback.cpp index 2bcc0cd34f2..02c3323fa76 100644 --- a/src/mongo/db/repl/rs_rollback.cpp +++ b/src/mongo/db/repl/rs_rollback.cpp @@ -681,9 +681,10 @@ void syncFixUp(OperationContext* txn, // TODO: IIRC cappedTruncateAfter does not handle completely // empty. // this will crazy slow if no _id index. - long long start = Listener::getElapsedTimeMillis(); + const auto clock = txn->getServiceContext()->getFastClockSource(); + const auto findOneStart = clock->now(); RecordId loc = Helpers::findOne(txn, collection, pattern, false); - if (Listener::getElapsedTimeMillis() - start > 200) + if (clock->now() - findOneStart > Milliseconds(200)) warning() << "roll back slow no _id index for " << doc.ns << " perhaps?"; // would be faster but requires index: diff --git a/src/mongo/db/s/sharding_state_test.cpp b/src/mongo/db/s/sharding_state_test.cpp index 5bcee931b75..8291b917edd 100644 --- a/src/mongo/db/s/sharding_state_test.cpp +++ b/src/mongo/db/s/sharding_state_test.cpp @@ -91,6 +91,7 @@ void initGrid(OperationContext* txn, const ConnectionString& configConnString) { class ShardingStateTest : public mongo::unittest::Test { public: void setUp() override { + _service.setFastClockSource(stdx::make_unique<ClockSourceMock>()); _service.setPreciseClockSource(stdx::make_unique<ClockSourceMock>()); serverGlobalParams.clusterRole = ClusterRole::ShardServer; diff --git a/src/mongo/db/service_context_d.cpp b/src/mongo/db/service_context_d.cpp index ecb449e7adb..b82f89c4c05 100644 --- a/src/mongo/db/service_context_d.cpp +++ b/src/mongo/db/service_context_d.cpp @@ -39,6 +39,7 @@ #include "mongo/db/client.h" #include "mongo/db/op_observer.h" #include "mongo/db/operation_context_impl.h" +#include "mongo/db/service_context.h" #include "mongo/db/storage/storage_engine.h" #include "mongo/db/storage/storage_engine_lock_file.h" #include "mongo/db/storage/storage_engine_metadata.h" @@ -57,8 +58,11 @@ namespace mongo { MONGO_INITIALIZER(SetGlobalEnvironment)(InitializerContext* context) { setGlobalServiceContext(stdx::make_unique<ServiceContextMongoD>()); - getGlobalServiceContext()->setTickSource(stdx::make_unique<SystemTickSource>()); - getGlobalServiceContext()->setPreciseClockSource(stdx::make_unique<SystemClockSource>()); + auto service = getGlobalServiceContext(); + + service->setTickSource(stdx::make_unique<SystemTickSource>()); + service->setFastClockSource(stdx::make_unique<SystemClockSource>()); + service->setPreciseClockSource(stdx::make_unique<SystemClockSource>()); return Status::OK(); } diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp index 67d08f91033..9d508e0fd54 100644 --- a/src/mongo/s/server.cpp +++ b/src/mongo/s/server.cpp @@ -84,6 +84,7 @@ #include "mongo/util/concurrency/thread_name.h" #include "mongo/util/exception_filter_win32.h" #include "mongo/util/exit.h" +#include "mongo/util/fast_clock_source_factory.h" #include "mongo/util/log.h" #include "mongo/util/net/hostname_canonicalization_worker.h" #include "mongo/util/net/message.h" @@ -414,6 +415,8 @@ static int _main() { startSignalProcessingThread(); + getGlobalServiceContext()->setFastClockSource(FastClockSourceFactory::create(Milliseconds{10})); + // we either have a setting where all processes are in localhost or none are std::vector<HostAndPort> configServers = mongosGlobalParams.configdbs.getServers(); for (std::vector<HostAndPort>::const_iterator it = configServers.begin(); @@ -467,6 +470,7 @@ MONGO_INITIALIZER(CreateAuthorizationExternalStateFactory)(InitializerContext* c MONGO_INITIALIZER(SetGlobalEnvironment)(InitializerContext* context) { setGlobalServiceContext(stdx::make_unique<ServiceContextNoop>()); getGlobalServiceContext()->setTickSource(stdx::make_unique<SystemTickSource>()); + getGlobalServiceContext()->setFastClockSource(stdx::make_unique<SystemClockSource>()); getGlobalServiceContext()->setPreciseClockSource(stdx::make_unique<SystemClockSource>()); return Status::OK(); } diff --git a/src/mongo/s/sharding_test_fixture.cpp b/src/mongo/s/sharding_test_fixture.cpp index 329bcb18c78..27598216802 100644 --- a/src/mongo/s/sharding_test_fixture.cpp +++ b/src/mongo/s/sharding_test_fixture.cpp @@ -85,6 +85,7 @@ const stdx::chrono::seconds ShardingTestFixture::kFutureTimeout{5}; void ShardingTestFixture::setUp() { _service = stdx::make_unique<ServiceContextNoop>(); + _service->setFastClockSource(stdx::make_unique<ClockSourceMock>()); _service->setPreciseClockSource(stdx::make_unique<ClockSourceMock>()); _messagePort = stdx::make_unique<MessagingPortMock>(); _client = _service->makeClient("ShardingTestFixture", _messagePort.get()); |