Skip to content

Commit

Permalink
Record knowhere index build time (#148)
Browse files Browse the repository at this point in the history
Signed-off-by: chasingegg <[email protected]>
  • Loading branch information
chasingegg authored Oct 17, 2023
1 parent 95be2bb commit 97549c3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/knowhere/prometheus_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion src/common/index.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,16 @@ Index<T>::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 <typename T>
Expand Down
1 change: 1 addition & 0 deletions src/common/prometheus_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down

0 comments on commit 97549c3

Please sign in to comment.