Skip to content

Commit

Permalink
Record knowhere index build time
Browse files Browse the repository at this point in the history
Signed-off-by: chasingegg <[email protected]>
  • Loading branch information
chasingegg committed Oct 16, 2023
1 parent 32f8308 commit 056e16a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
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
11 changes: 9 additions & 2 deletions src/common/index.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
// Unless required by applicable law or agreed to in writing, software distributed under the License
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations under the License.

#include "knowhere/index.h"

#include "fmt/format.h"
#include "knowhere/comp/time_recorder.h"
#include "knowhere/dataset.h"
#include "knowhere/expected.h"
Expand Down 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(fmt::format("Build index on {} rows with dim {}", dataset.GetRows(), dataset.GetDim()), 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 056e16a

Please sign in to comment.