diff --git a/src/graph/executor/Executor.cpp b/src/graph/executor/Executor.cpp index 5450722f02b..b6ae9f242d1 100644 --- a/src/graph/executor/Executor.cpp +++ b/src/graph/executor/Executor.cpp @@ -209,6 +209,11 @@ Executor *Executor::makeExecutor(QueryContext *qctx, const PlanNode *node) { return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kLimit: { + stats::StatsManager::addValue(kNumLimitExecutors); + if (FLAGS_enable_space_level_metrics && spaceName != "") { + stats::StatsManager::addValue( + stats::StatsManager::counterWithLabels(kNumLimitExecutors, {{"space", spaceName}})); + } return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kSample: { diff --git a/src/graph/executor/query/LimitExecutor.cpp b/src/graph/executor/query/LimitExecutor.cpp index 236d8fe3cf6..c700b582c6b 100644 --- a/src/graph/executor/query/LimitExecutor.cpp +++ b/src/graph/executor/query/LimitExecutor.cpp @@ -5,11 +5,13 @@ #include "graph/executor/query/LimitExecutor.h" #include "graph/planner/plan/Query.h" - +#include "graph/stats/GraphStats.h" namespace nebula { namespace graph { folly::Future LimitExecutor::execute() { + auto start_ts = std::chrono::steady_clock::now(); + auto &spaceName = qctx()->rctx() ? qctx()->rctx()->session()->spaceName() : ""; SCOPED_TIMER(&execTime_); auto* limit = asNode(node()); @@ -31,6 +33,14 @@ folly::Future LimitExecutor::execute() { builder.value(result.valuePtr()); iter->select(offset, count); builder.iter(std::move(result).iter()); + auto diff = std::chrono::steady_clock::now() - start_ts; + stats::StatsManager::addValue( + kLimitExecutorsLatencyUs, + std::chrono::duration_cast(diff).count()); + if (FLAGS_enable_space_level_metrics && spaceName != "") { + stats::StatsManager::addValue( + stats::StatsManager::histoWithLabels(kLimitExecutorsLatencyUs, {{"space", spaceName}})); + } return finish(builder.build()); } else { DataSet ds; diff --git a/src/graph/stats/GraphStats.cpp b/src/graph/stats/GraphStats.cpp index f03cd46885b..395f67f3fd4 100644 --- a/src/graph/stats/GraphStats.cpp +++ b/src/graph/stats/GraphStats.cpp @@ -32,6 +32,8 @@ stats::CounterId kOptimizerLatencyUs; stats::CounterId kNumAggregateExecutors; stats::CounterId kNumSortExecutors; +stats::CounterId kNumLimitExecutors; +stats::CounterId kLimitExecutorsLatencyUs; stats::CounterId kNumIndexScanExecutors; stats::CounterId kNumOpenedSessions; @@ -66,6 +68,10 @@ void initGraphStats() { kNumIndexScanExecutors = stats::StatsManager::registerStats("num_indexscan_executors", "rate, sum"); + kNumLimitExecutors = stats::StatsManager::registerStats("num_Limit_executors", "rate, sum"); + kLimitExecutorsLatencyUs = stats::StatsManager::registerHisto( + "limit_executors_latency_us", 1000, 0, 2000, "avg, p75, p95, p99, p999"); + kNumOpenedSessions = stats::StatsManager::registerStats("num_opened_sessions", "rate, sum"); kNumAuthFailedSessions = stats::StatsManager::registerStats("num_auth_failed_sessions", "rate, sum"); diff --git a/src/graph/stats/GraphStats.h b/src/graph/stats/GraphStats.h index a1facbbf574..e91fd355ce8 100644 --- a/src/graph/stats/GraphStats.h +++ b/src/graph/stats/GraphStats.h @@ -33,6 +33,8 @@ extern stats::CounterId kOptimizerLatencyUs; // Executor extern stats::CounterId kNumAggregateExecutors; extern stats::CounterId kNumSortExecutors; +extern stats::CounterId kNumLimitExecutors; +extern stats::CounterId kLimitExecutorsLatencyUs; extern stats::CounterId kNumIndexScanExecutors; // Server client traffic