From 779a5226f2e951f1b854bb479c1dc3257cc53905 Mon Sep 17 00:00:00 2001 From: Yudong Cai Date: Thu, 14 Dec 2023 15:50:46 +0800 Subject: [PATCH] Cherry-pick #294 #298 from main Signed-off-by: Yudong Cai --- include/knowhere/prometheus_client.h | 8 ++------ src/common/index.cc | 29 +++++++++++++++++++++------- src/common/prometheus_client.cc | 8 ++------ 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/include/knowhere/prometheus_client.h b/include/knowhere/prometheus_client.h index 8a437d56a..c7a517197 100644 --- a/include/knowhere/prometheus_client.h +++ b/include/knowhere/prometheus_client.h @@ -74,13 +74,9 @@ extern const std::unique_ptr prometheusClient; #define DECLARE_PROMETHEUS_COUNTER(name_counter) extern prometheus::Counter& name_counter; #define DECLARE_PROMETHEUS_HISTOGRAM(name_histogram) extern prometheus::Histogram& name_histogram; -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_load_latency); DECLARE_PROMETHEUS_HISTOGRAM(knowhere_search_latency); -DECLARE_PROMETHEUS_HISTOGRAM(knowhere_ann_iterator_init_latency); DECLARE_PROMETHEUS_HISTOGRAM(knowhere_range_search_latency); +DECLARE_PROMETHEUS_HISTOGRAM(knowhere_ann_iterator_init_latency); } // namespace knowhere diff --git a/src/common/index.cc b/src/common/index.cc index 3d372ffe2..e7871134b 100644 --- a/src/common/index.cc +++ b/src/common/index.cc @@ -45,7 +45,6 @@ Index::Build(const DataSet& dataset, const Json& json) { 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 @@ -88,8 +87,6 @@ Index::Search(const DataSet& dataset, const Json& json, const BitsetView& bit auto span = rc.ElapseFromBegin("done"); span *= 0.001; // convert to ms knowhere_search_latency.Observe(span); - knowhere_search_count.Increment(); - knowhere_search_topk.Observe(cfg->k.value()); #else auto res = this->node->Search(dataset, *cfg, bitset); #endif @@ -117,7 +114,6 @@ Index::AnnIterator(const DataSet& dataset, const Json& json, const BitsetView auto span = rc.ElapseFromBegin("done"); span *= 0.001; // convert to ms knowhere_search_latency.Observe(span); - knowhere_ann_iterator_count.Increment(); #else auto res = this->node->AnnIterator(dataset, *cfg, bitset); #endif @@ -144,7 +140,6 @@ Index::RangeSearch(const DataSet& dataset, const Json& json, const BitsetView auto span = rc.ElapseFromBegin("done"); span *= 0.001; // convert to ms knowhere_range_search_latency.Observe(span); - knowhere_range_search_count.Increment(); #else auto res = this->node->RangeSearch(dataset, *cfg, bitset); #endif @@ -197,7 +192,17 @@ Index::Deserialize(const BinarySet& binset, const Json& json) { if (res != Status::success) { return res; } - return this->node->Deserialize(binset, *cfg); + +#ifdef NOT_COMPILE_FOR_SWIG + TimeRecorder rc("Load index", 2); + res = this->node->Deserialize(binset, *cfg); + auto span = rc.ElapseFromBegin("done"); + span *= 0.001; // convert to ms + knowhere_load_latency.Observe(span); +#else + res = this->node->Deserialize(binset, *cfg); +#endif + return res; } template @@ -216,7 +221,17 @@ Index::DeserializeFromFile(const std::string& filename, const Json& json) { if (res != Status::success) { return res; } - return this->node->DeserializeFromFile(filename, *cfg); + +#ifdef NOT_COMPILE_FOR_SWIG + TimeRecorder rc("Load index from file", 2); + res = this->node->DeserializeFromFile(filename, *cfg); + auto span = rc.ElapseFromBegin("done"); + span *= 0.001; // convert to ms + knowhere_load_latency.Observe(span); +#else + res = this->node->DeserializeFromFile(filename, *cfg); +#endif + return res; } template diff --git a/src/common/prometheus_client.cc b/src/common/prometheus_client.cc index 83b6a21cc..9486a5336 100644 --- a/src/common/prometheus_client.cc +++ b/src/common/prometheus_client.cc @@ -25,14 +25,10 @@ const std::unique_ptr prometheusClient = std::make_unique