From 97549c3c630042dc57a60479eb5ba75b6180ec27 Mon Sep 17 00:00:00 2001 From: Gao Date: Tue, 17 Oct 2023 11:45:58 +0800 Subject: [PATCH] Record knowhere index build time (#148) Signed-off-by: chasingegg --- include/knowhere/prometheus_client.h | 1 + src/common/index.cc | 9 ++++++++- src/common/prometheus_client.cc | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/knowhere/prometheus_client.h b/include/knowhere/prometheus_client.h index 7083e6f73..8a437d56a 100644 --- a/include/knowhere/prometheus_client.h +++ b/include/knowhere/prometheus_client.h @@ -78,6 +78,7 @@ DECLARE_PROMETHEUS_COUNTER(knowhere_build_count); DECLARE_PROMETHEUS_COUNTER(knowhere_search_count); DECLARE_PROMETHEUS_COUNTER(knowhere_ann_iterator_count); DECLARE_PROMETHEUS_COUNTER(knowhere_range_search_count); +DECLARE_PROMETHEUS_HISTOGRAM(knowhere_build_latency); DECLARE_PROMETHEUS_HISTOGRAM(knowhere_search_topk); DECLARE_PROMETHEUS_HISTOGRAM(knowhere_search_latency); DECLARE_PROMETHEUS_HISTOGRAM(knowhere_ann_iterator_init_latency); diff --git a/src/common/index.cc b/src/common/index.cc index 0bedb4a29..3d372ffe2 100644 --- a/src/common/index.cc +++ b/src/common/index.cc @@ -40,9 +40,16 @@ Index::Build(const DataSet& dataset, const Json& json) { RETURN_IF_ERROR(cfg->CheckAndAdjustForBuild()); #ifdef NOT_COMPILE_FOR_SWIG + TimeRecorder rc("Build index", 2); + auto res = this->node->Build(dataset, *cfg); + auto span = rc.ElapseFromBegin("done"); + span *= 0.000001; // convert to s + knowhere_build_latency.Observe(span); knowhere_build_count.Increment(); +#else + auto res = this->node->Build(dataset, *cfg); #endif - return this->node->Build(dataset, *cfg); + return res; } template diff --git a/src/common/prometheus_client.cc b/src/common/prometheus_client.cc index 791a14245..83b6a21cc 100644 --- a/src/common/prometheus_client.cc +++ b/src/common/prometheus_client.cc @@ -29,6 +29,7 @@ DEFINE_PROMETHEUS_COUNTER(knowhere_build_count, "knowhere index build count") DEFINE_PROMETHEUS_COUNTER(knowhere_search_count, "knowhere search count") DEFINE_PROMETHEUS_COUNTER(knowhere_ann_iterator_count, "knowhere ann iterator count") DEFINE_PROMETHEUS_COUNTER(knowhere_range_search_count, "knowhere range search count") +DEFINE_PROMETHEUS_HISTOGRAM(knowhere_build_latency, "index build latency in knowhere (s)") DEFINE_PROMETHEUS_HISTOGRAM(knowhere_search_topk, "knowhere search topk") DEFINE_PROMETHEUS_HISTOGRAM(knowhere_search_latency, "search latency in knowhere (ms)") DEFINE_PROMETHEUS_HISTOGRAM(knowhere_ann_iterator_init_latency, "ann iterator init latency in knowhere (ms)")