diff --git a/internal/querynodev2/tasks/query_task.go b/internal/querynodev2/tasks/query_task.go index 079f16d6f7..751860c09e 100644 --- a/internal/querynodev2/tasks/query_task.go +++ b/internal/querynodev2/tasks/query_task.go @@ -2,7 +2,9 @@ package tasks import ( "context" + "fmt" "strconv" + "time" "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" "github.com/milvus-io/milvus/internal/proto/internalpb" @@ -87,9 +89,8 @@ func (t *QueryTask) Execute() error { return err } defer retrievePlan.Delete() - - results, searchedSegments, err := segments.Retrieve(t.ctx, t.segmentManager, retrievePlan, t.req) - defer t.segmentManager.Segment.Unpin(searchedSegments) + results, querySegments, err := segments.Retrieve(t.ctx, t.segmentManager, retrievePlan, t.req) + defer t.segmentManager.Segment.Unpin(querySegments) if err != nil { return err } @@ -98,8 +99,13 @@ func (t *QueryTask) Execute() error { t.req, t.collection.Schema(), ) - + beforeReduce := time.Now() reducedResult, err := reducer.Reduce(t.ctx, results) + + metrics.QueryNodeReduceLatency.WithLabelValues( + fmt.Sprint(paramtable.GetNodeID()), + metrics.QueryLabel, + metrics.ReduceSegments).Observe(float64(time.Since(beforeReduce).Milliseconds())) if err != nil { return err } diff --git a/internal/querynodev2/tasks/task.go b/internal/querynodev2/tasks/task.go index 96a37fe2de..545de27bbf 100644 --- a/internal/querynodev2/tasks/task.go +++ b/internal/querynodev2/tasks/task.go @@ -194,8 +194,11 @@ func (t *SearchTask) Execute() error { return err } defer segments.DeleteSearchResultDataBlobs(blobs) - reduceLatency := tr.RecordSpan() - + metrics.QueryNodeReduceLatency.WithLabelValues( + fmt.Sprint(paramtable.GetNodeID()), + metrics.SearchLabel, + metrics.ReduceSegments). + Observe(float64(tr.RecordSpan().Milliseconds())) for i := range t.originNqs { blob, err := segments.GetSearchResultDataBlob(blobs, i) if err != nil { @@ -213,12 +216,6 @@ func (t *SearchTask) Execute() error { bs := make([]byte, len(blob)) copy(bs, blob) - metrics.QueryNodeReduceLatency.WithLabelValues( - fmt.Sprint(paramtable.GetNodeID()), - metrics.SearchLabel, - metrics.ReduceSegments). - Observe(float64(reduceLatency.Milliseconds())) - task.result = &internalpb.SearchResults{ Base: &commonpb.MsgBase{ SourceID: paramtable.GetNodeID(), @@ -235,6 +232,7 @@ func (t *SearchTask) Execute() error { }, } } + return nil }