Skip to content

Commit 63cf5ae

Browse files
author
Xin Dong
committed
Log the slow query based on how long the query takes to run.
1 parent edcbe96 commit 63cf5ae

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/Constants.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,6 @@ const char* MT_TIME_INSERT_LATENCY_US = "dl_insert_latency_useconds";
7676
const char* MT_HIST_INSERT_SZ = "dl_insert_size_bytes";
7777
const char* MT_HIST_TR_PER_REQUEST = "dl_tr_per_request";
7878
const char* MT_RATE_IDX_REBUILD = "dl_index_rebuild_rate";
79+
const uint64_t SLOW_QUERY_THRESHOLD_SECONDS = 10;
7980

8081
} // namespace DocLayerConstants

src/Constants.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ extern const char* MT_TIME_INSERT_LATENCY_US;
8989
extern const char* MT_HIST_INSERT_SZ;
9090
extern const char* MT_HIST_TR_PER_REQUEST;
9191
extern const char* MT_RATE_IDX_REBUILD;
92+
// TODO: make this part of the knob/options instead of constants?
93+
extern const uint64_t SLOW_QUERY_THRESHOLD_SECONDS;
9294

9395
} // namespace DocLayerConstants
9496

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 queryLatencySeconds = (timer_int() - startTime) / 1000;
518+
DocumentLayer::metricReporter->captureTime(DocLayerConstants::MT_TIME_QUERY_LATENCY_US, queryLatencySeconds);
519+
520+
if (slowQueryLogging && queryLatencySeconds >= DocLayerConstants::SLOW_QUERY_THRESHOLD_SECONDS) {
521+
TraceEvent("SlowQuery")
522+
.detail("Threshold", DocLayerConstants::SLOW_QUERY_THRESHOLD_SECONDS)
523+
.detail("Duration", queryLatencySeconds)
524+
.detail("Query", query->toString());
525+
}
519526

520527
return Void();
521528
}

0 commit comments

Comments
 (0)