Skip to content

Commit 7643f3b

Browse files
authored
matchiter: capture metric NgramLookups (#608)
This instruments our matchiter code to track how often is calls Get on the underlying ngram index. We have some queries on long strings which are going much slower than expected and we suspect it is related to the work done here. This change requires a few moving pieces: - Adding the int to Stats - Instrumenting places we log/emit Stats - grpc support - capturing this work in matchiter code - updating tests to ensure correctness The last two points are the meat of this commit, while the rest was mechanical work. I reworked the TestAndSearch since into TestSearchStats since it was the only test which had useful assertions on Stats. I was surprised to see how high the ngram lookup values were for such simple queries. This makes me more confident in improving our performance here. Test Plan: go test
1 parent 93f7b0c commit 7643f3b

File tree

15 files changed

+316
-195
lines changed

15 files changed

+316
-195
lines changed

api.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,9 @@ type Stats struct {
382382
// Number of candidate matches as a result of searching ngrams.
383383
NgramMatches int
384384

385+
// NgramLookups is the number of times we accessed an ngram in the index.
386+
NgramLookups int
387+
385388
// Wall clock time for queued search.
386389
Wait time.Duration
387390

@@ -409,6 +412,7 @@ func (s *Stats) Add(o Stats) {
409412
s.FilesSkipped += o.FilesSkipped
410413
s.MatchCount += o.MatchCount
411414
s.NgramMatches += o.NgramMatches
415+
s.NgramLookups += o.NgramLookups
412416
s.ShardFilesConsidered += o.ShardFilesConsidered
413417
s.ShardsScanned += o.ShardsScanned
414418
s.ShardsSkipped += o.ShardsSkipped
@@ -438,6 +442,7 @@ func (s *Stats) Zero() bool {
438442
s.FilesSkipped > 0 ||
439443
s.MatchCount > 0 ||
440444
s.NgramMatches > 0 ||
445+
s.NgramLookups > 0 ||
441446
s.ShardFilesConsidered > 0 ||
442447
s.ShardsScanned > 0 ||
443448
s.ShardsSkipped > 0 ||

api_proto.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ func StatsFromProto(p *proto.Stats) Stats {
297297
ShardsSkippedFilter: int(p.GetShardsSkippedFilter()),
298298
MatchCount: int(p.GetMatchCount()),
299299
NgramMatches: int(p.GetNgramMatches()),
300+
NgramLookups: int(p.GetNgramLookups()),
300301
Wait: p.GetWait().AsDuration(),
301302
RegexpsConsidered: int(p.GetRegexpsConsidered()),
302303
FlushReason: FlushReasonFromProto(p.GetFlushReason()),
@@ -319,6 +320,7 @@ func (s *Stats) ToProto() *proto.Stats {
319320
ShardsSkippedFilter: int64(s.ShardsSkippedFilter),
320321
MatchCount: int64(s.MatchCount),
321322
NgramMatches: int64(s.NgramMatches),
323+
NgramLookups: int64(s.NgramLookups),
322324
Wait: durationpb.New(s.Wait),
323325
RegexpsConsidered: int64(s.RegexpsConsidered),
324326
FlushReason: s.FlushReason.ToProto(),

cmd/zoekt-webserver/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ func (s *loggedSearcher) log(ctx context.Context, q query.Q, opts *zoekt.SearchO
594594
sglog.Int("stat.ShardsSkippedFilter", st.ShardsSkippedFilter),
595595
sglog.Int("stat.MatchCount", st.MatchCount),
596596
sglog.Int("stat.NgramMatches", st.NgramMatches),
597+
sglog.Int("stat.NgramLookups", st.NgramLookups),
597598
sglog.Duration("stat.Wait", st.Wait),
598599
)
599600
}

deps.bzl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,13 +1256,7 @@ def go_dependencies():
12561256
sum = "h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=",
12571257
version = "v0.2.0",
12581258
)
1259-
go_repository(
1260-
name = "com_github_kylelemons_godebug",
1261-
build_file_proto_mode = "disable_global",
1262-
importpath = "github.com/kylelemons/godebug",
1263-
sum = "h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=",
1264-
version = "v1.1.0",
1265-
)
1259+
12661260
go_repository(
12671261
name = "com_github_labstack_echo_v4",
12681262
build_file_proto_mode = "disable_global",

eval.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ func (d *indexData) regexpToMatchTreeRecursive(r *syntax.Regexp, minTextSize int
811811
}
812812
}
813813
if len(qs) == 0 {
814-
return &noMatchTree{"const"}, isEq, false, nil
814+
return &noMatchTree{Why: "const"}, isEq, false, nil
815815
}
816816
return &orMatchTree{qs}, isEq, false, nil
817817
case syntax.OpStar:

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ require (
1818
github.com/hashicorp/go-retryablehttp v0.7.2
1919
github.com/keegancsmith/rpc v1.3.0
2020
github.com/keegancsmith/tmpfriend v0.0.0-20180423180255-86e88902a513
21-
github.com/kylelemons/godebug v1.1.0
2221
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f
2322
github.com/opentracing/opentracing-go v1.2.0
2423
github.com/peterbourgon/ff/v3 v3.3.0
@@ -34,6 +33,7 @@ require (
3433
github.com/uber/jaeger-lib v2.4.1+incompatible
3534
github.com/xanzy/go-gitlab v0.80.0
3635
github.com/xeipuuv/gojsonschema v1.2.0
36+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.39.0
3737
go.opentelemetry.io/contrib/propagators/jaeger v1.14.0
3838
go.opentelemetry.io/contrib/propagators/ot v1.14.0
3939
go.opentelemetry.io/otel v1.13.0
@@ -115,7 +115,6 @@ require (
115115
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
116116
github.com/yusufpapurcu/wmi v1.2.2 // indirect
117117
go.opencensus.io v0.24.0 // indirect
118-
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.39.0 // indirect
119118
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.13.0 // indirect
120119
go.opentelemetry.io/otel/metric v0.36.0 // indirect
121120
go.opentelemetry.io/proto/otlp v0.19.0 // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
344344
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
345345
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
346346
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
347-
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
348-
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
349347
github.com/labstack/echo/v4 v4.5.0/go.mod h1:czIriw4a0C1dFun+ObrXp7ok03xON0N1awStJ6ArI7Y=
350348
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
351349
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=

0 commit comments

Comments
 (0)