diff options
author | va-kuznecov <va-kuznecov@ydb.tech> | 2023-10-02 19:57:00 +0300 |
---|---|---|
committer | va-kuznecov <va-kuznecov@ydb.tech> | 2023-10-02 20:47:55 +0300 |
commit | 0c3173cd44d7607c95d012a3e98b4d45440242b4 (patch) | |
tree | 415cad7804aaf6a741d57ee0f023b2191c65c1e1 | |
parent | 380dae609bb5bda6b421cc7a862089b48cfdb830 (diff) | |
download | ydb-0c3173cd44d7607c95d012a3e98b4d45440242b4.tar.gz |
Fix TotalDurationMs in query stats KIKIMR-18823
Fix TotalDurationMs in query stats KIKIMR-18823
KIKIMR-18823 fixed time spent statistics
For some queries(literal or kpi) tasks
do not have any input/output channels.
And time statistics count time from lowest
row start in these channels.
For case, when we don't have any channel, firstRowMs will be MAX_INT
and in this case we take stage start as
lowest time.
-rw-r--r-- | ydb/core/kqp/executer_actor/kqp_executer_stats.cpp | 7 | ||||
-rw-r--r-- | ydb/core/kqp/opt/kqp_query_plan.cpp | 9 | ||||
-rw-r--r-- | ydb/library/yql/dq/actors/protos/dq_stats.proto | 1 |
3 files changed, 12 insertions, 5 deletions
diff --git a/ydb/core/kqp/executer_actor/kqp_executer_stats.cpp b/ydb/core/kqp/executer_actor/kqp_executer_stats.cpp index 6617f44e293..e667be9be0b 100644 --- a/ydb/core/kqp/executer_actor/kqp_executer_stats.cpp +++ b/ydb/core/kqp/executer_actor/kqp_executer_stats.cpp @@ -167,10 +167,11 @@ void TQueryExecutionStats::AddComputeActorStats(ui32 /* nodeId */, NYql::NDqProt UpdateAggr(stageStats->MutableOutputRows(), task.GetOutputRows()); UpdateAggr(stageStats->MutableOutputBytes(), task.GetOutputBytes()); + UpdateMinMax(stageStats->MutableStartTimeMs(), task.GetStartTimeMs()); UpdateMinMax(stageStats->MutableFirstRowTimeMs(), task.GetFirstRowTimeMs()); UpdateMinMax(stageStats->MutableFinishTimeMs(), task.GetFinishTimeMs()); - stageStats->SetDurationUs((stageStats->GetFinishTimeMs().GetMax() - stageStats->GetFirstRowTimeMs().GetMin()) * 1'000); + stageStats->SetDurationUs((stageStats->GetFinishTimeMs().GetMax() - stageStats->GetStartTimeMs().GetMin()) * 1'000); for (auto ingressStat : task.GetIngress()) { UpdateAggr(&(*stageStats->MutableIngressBytes())[ingressStat.GetName()], ingressStat.GetBytes()); @@ -179,6 +180,7 @@ void TQueryExecutionStats::AddComputeActorStats(ui32 /* nodeId */, NYql::NDqProt UpdateAggr(&(*stageStats->MutableEgressBytes())[egressStat.GetName()], egressStat.GetBytes()); } } + } if (CollectProfileStats(StatsMode)) { @@ -253,10 +255,11 @@ void TQueryExecutionStats::AddDatashardStats(NYql::NDqProto::TDqComputeActorStat UpdateAggr(stageStats->MutableOutputRows(), task.GetOutputRows()); UpdateAggr(stageStats->MutableOutputBytes(), task.GetOutputBytes()); + UpdateMinMax(stageStats->MutableStartTimeMs(), task.GetStartTimeMs()); UpdateMinMax(stageStats->MutableFirstRowTimeMs(), task.GetFirstRowTimeMs()); UpdateMinMax(stageStats->MutableFinishTimeMs(), task.GetFinishTimeMs()); - stageStats->SetDurationUs((stageStats->GetFinishTimeMs().GetMax() - stageStats->GetFirstRowTimeMs().GetMin()) * 1'000); + stageStats->SetDurationUs((stageStats->GetFinishTimeMs().GetMax() - stageStats->GetStartTimeMs().GetMin()) * 1'000); for (auto& tableStats: task.GetTables()) { auto* tableAggrStats = GetOrCreateTableAggrStats(stageStats, tableStats.GetTablePath()); diff --git a/ydb/core/kqp/opt/kqp_query_plan.cpp b/ydb/core/kqp/opt/kqp_query_plan.cpp index cd4498eb029..689b4ec49ea 100644 --- a/ydb/core/kqp/opt/kqp_query_plan.cpp +++ b/ydb/core/kqp/opt/kqp_query_plan.cpp @@ -1869,9 +1869,12 @@ TString AddExecStatsToTxPlan(const TString& txPlanJson, const NYql::NDqProto::TD SetNonZero(node, "OutputRows", taskStats.GetOutputRows()); SetNonZero(node, "OutputBytes", taskStats.GetOutputBytes()); - SetNonZero(node, "FirstRowTimeMs", taskStats.GetFirstRowTimeMs()); - SetNonZero(node, "FinishTimeMs", taskStats.GetFinishTimeMs()); + // equals to max if there was no first row + if(taskStats.GetFirstRowTimeMs() != std::numeric_limits<ui64>::max()) { + SetNonZero(node, "FirstRowTimeMs", taskStats.GetFirstRowTimeMs()); + } SetNonZero(node, "StartTimeMs", taskStats.GetStartTimeMs()); + SetNonZero(node, "FinishTimeMs", taskStats.GetFinishTimeMs()); SetNonZero(node, "ComputeTimeUs", taskStats.GetComputeCpuTimeUs()); SetNonZero(node, "WaitTimeUs", taskStats.GetWaitTimeUs()); @@ -1917,7 +1920,7 @@ TString AddExecStatsToTxPlan(const TString& txPlanJson, const NYql::NDqProto::TD } stats["TotalTasks"] = (*stat)->GetTotalTasksCount(); - stats["TotalDurationMs"] = (*stat)->GetFinishTimeMs().GetMax() - (*stat)->GetFirstRowTimeMs().GetMin(); + stats["TotalDurationMs"] = (*stat)->GetDurationUs() / 1000; stats["TotalCpuTimeUs"] = (*stat)->GetCpuTimeUs().GetSum(); stats["TotalInputRows"] = (*stat)->GetInputRows().GetSum(); stats["TotalInputBytes"] = (*stat)->GetInputBytes().GetSum(); diff --git a/ydb/library/yql/dq/actors/protos/dq_stats.proto b/ydb/library/yql/dq/actors/protos/dq_stats.proto index d898d3dfaa5..f0051319fab 100644 --- a/ydb/library/yql/dq/actors/protos/dq_stats.proto +++ b/ydb/library/yql/dq/actors/protos/dq_stats.proto @@ -236,6 +236,7 @@ message TDqStageStats { TDqStatsMinMax FirstRowTimeMs = 13; TDqStatsMinMax FinishTimeMs = 14; + TDqStatsMinMax StartTimeMs = 21; uint64 DurationUs = 15; // microseconds from min(task_first_row_time) to max(task_finish_time) repeated TDqTableAggrStats Tables = 16; // is it required? |