Skip to content

Commit 194d376

Browse files
authored
Merge pull request #170 from dongxinEric/misc/49/time-based-slow-query-logging
2 parents edcbe96 + 34093ae commit 194d376

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/ExtMsg.actor.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,15 @@ ACTOR static Future<Void> doRun(Reference<ExtMsgQuery> query, Reference<ExtConne
514514
}
515515
}
516516

517-
DocumentLayer::metricReporter->captureTime(DocLayerConstants::MT_TIME_QUERY_LATENCY_US,
518-
(timer_int() - startTime) / 1000);
517+
uint64_t queryLatencyMicroSeconds = (timer_int() - startTime) / 1000;
518+
DocumentLayer::metricReporter->captureTime(DocLayerConstants::MT_TIME_QUERY_LATENCY_US, queryLatencyMicroSeconds);
519+
520+
if (slowQueryLogging && queryLatencyMicroSeconds >= DOCLAYER_KNOBS->SLOW_QUERY_THRESHOLD_MICRO_SECONDS) {
521+
TraceEvent(SevWarn, "SlowQuery")
522+
.detail("ThresholdMicroSeconds", DOCLAYER_KNOBS->SLOW_QUERY_THRESHOLD_MICRO_SECONDS)
523+
.detail("DurationMicroSeconds", queryLatencyMicroSeconds)
524+
.detail("Query", query->toString());
525+
}
519526

520527
return Void();
521528
}

src/Knobs.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ DocLayerKnobs::DocLayerKnobs(bool enable) {
4444
init(MAX_RETURNABLE_DATA_SIZE, (1 << 20) * 16);
4545
init(CURSOR_EXPIRY, 60 * 10); /* seconds */
4646
init(DEFAULT_RETURNABLE_DATA_SIZE, (1 << 20) * 4);
47+
init(SLOW_QUERY_THRESHOLD_MICRO_SECONDS, 10 * 1000 * 1000);
4748
}
4849

4950
bson::BSONObj DocLayerKnobs::dumpKnobs() const {

src/Knobs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class DocLayerKnobs : public Knobs {
3737
int MAX_RETURNABLE_DATA_SIZE;
3838
int CURSOR_EXPIRY;
3939
int DEFAULT_RETURNABLE_DATA_SIZE;
40+
int SLOW_QUERY_THRESHOLD_MICRO_SECONDS;
4041

4142
explicit DocLayerKnobs(bool randomize = false);
4243

0 commit comments

Comments
 (0)