Skip to content

Commit

Permalink
SERVER-23243 Replace the easy-to-remove usages of Listener::getElapse…
Browse files Browse the repository at this point in the history
…dTimeMillis()
  • Loading branch information
WaleyChen committed Apr 25, 2016
1 parent 3e9149a commit 046441d
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/mongo/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ env.Install(
's/coreshard',
's/mongoscore',
's/sharding_initialization',
'util/clock_sources',
'util/ntservice',
'util/options_parser/options_parser_init',
]))
Expand Down
1 change: 1 addition & 0 deletions src/mongo/db/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 15 additions & 11 deletions src/mongo/db/commands/server_status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -92,11 +92,12 @@ class CmdServerStatus : public Command {
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
Expand All @@ -108,11 +109,13 @@ class CmdServerStatus : public Command {
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

Expand Down Expand Up @@ -141,7 +144,7 @@ class CmdServerStatus : public Command {
result.append(section->getSectionName(), data);
timeBuilder.appendNumber(
static_cast<string>(str::stream() << "after " << section->getSectionName()),
Listener::getElapsedTimeMillis() - start);
durationCount<Milliseconds>(clock->now() - runStart));
}

// --- counters
Expand All @@ -166,8 +169,9 @@ class CmdServerStatus : public Command {
}
}

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);
Expand All @@ -185,7 +189,7 @@ class CmdServerStatus : public Command {
}

private:
const unsigned long long _started;
const Date_t _started;
bool _runCalled;

typedef map<string, ServerStatusSection*> SectionMap;
Expand Down
2 changes: 2 additions & 0 deletions src/mongo/db/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion src/mongo/db/exec/plan_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
1 change: 1 addition & 0 deletions src/mongo/db/ftdc/ftdc_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
5 changes: 3 additions & 2 deletions src/mongo/db/repl/rs_rollback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/mongo/db/s/sharding_state_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions src/mongo/db/service_context_d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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();
}

Expand Down
4 changes: 4 additions & 0 deletions src/mongo/s/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions src/mongo/s/sharding_test_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 046441d

Please sign in to comment.