Skip to content

Commit

Permalink
enhance: add metrics for segment prune latnecy(#30376) (#34364)
Browse files Browse the repository at this point in the history
related: #30376
pr: #34094

Signed-off-by: MrPresent-Han <[email protected]>
Co-authored-by: MrPresent-Han <[email protected]>
  • Loading branch information
MrPresent-Han and MrPresent-Han authored Jul 4, 2024
1 parent 9087b6f commit e12b701
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
14 changes: 11 additions & 3 deletions internal/querynodev2/delegator/segment_pruner.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/milvus-io/milvus/pkg/util/distance"
"github.com/milvus-io/milvus/pkg/util/funcutil"
"github.com/milvus-io/milvus/pkg/util/merr"
"github.com/milvus-io/milvus/pkg/util/timerecord"
"github.com/milvus-io/milvus/pkg/util/typeutil"
)

Expand All @@ -48,7 +49,7 @@ func PruneSegments(ctx context.Context,
// no need to prune
return
}

tr := timerecord.NewTimeRecorder("PruneSegments")
var collectionID int64
var expr []byte
if searchReq != nil {
Expand Down Expand Up @@ -120,16 +121,23 @@ func PruneSegments(ctx context.Context,
item.Segments = newSegments
sealedSegments[idx] = item
}
filterRatio := float32(realFilteredSegments) / float32(totalSegNum)
metrics.QueryNodeSegmentPruneRatio.
WithLabelValues(fmt.Sprint(collectionID), fmt.Sprint(typeutil.IsVectorType(clusteringKeyField.GetDataType()))).
Observe(float64(realFilteredSegments / totalSegNum))
Observe(float64(filterRatio))
log.Ctx(ctx).Debug("Pruned segment for search/query",
zap.Int("filtered_segment_num[stats]", len(filteredSegments)),
zap.Int("filtered_segment_num[excluded]", realFilteredSegments),
zap.Int("total_segment_num", totalSegNum),
zap.Float32("filtered_ratio", float32(realFilteredSegments)/float32(totalSegNum)),
zap.Float32("filtered_ratio", filterRatio),
)
}

metrics.QueryNodeSegmentPruneLatency.WithLabelValues(fmt.Sprint(collectionID),
fmt.Sprint(typeutil.IsVectorType(clusteringKeyField.GetDataType()))).
Observe(float64(tr.ElapseSpan().Milliseconds()))
log.Ctx(ctx).Debug("Pruned segment for search/query",
zap.Duration("duration", tr.ElapseSpan()))
}

type segmentDisStruct struct {
Expand Down
13 changes: 13 additions & 0 deletions pkg/metrics/querynode_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,18 @@ var (
isVectorFieldLabelName,
})

QueryNodeSegmentPruneLatency = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: milvusNamespace,
Subsystem: typeutil.QueryNodeRole,
Name: "segment_prune_latency",
Help: "latency of segment prune",
Buckets: buckets,
}, []string{
collectionIDLabelName,
isVectorFieldLabelName,
})

QueryNodeEvictedReadReqCount = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: milvusNamespace,
Expand Down Expand Up @@ -789,6 +801,7 @@ func RegisterQueryNode(registry *prometheus.Registry) {
registry.MustRegister(QueryNodeDiskCacheEvictBytes)
registry.MustRegister(QueryNodeDiskCacheEvictDuration)
registry.MustRegister(QueryNodeDiskCacheEvictGlobalDuration)
registry.MustRegister(QueryNodeSegmentPruneLatency)
registry.MustRegister(QueryNodeApplyBFCost)
registry.MustRegister(QueryNodeForwardDeleteCost)
registry.MustRegister(QueryNodeSegmentPruneRatio)
Expand Down

0 comments on commit e12b701

Please sign in to comment.