From 3468f8972d6a3b1a5fc9612db7e89f60bb1fd168 Mon Sep 17 00:00:00 2001 From: Abhinav Dangeti Date: Fri, 5 Feb 2021 14:42:40 -0700 Subject: [PATCH] MB-31358: Estimation of memory needed for query with highlighting + Check this test .. ``` func TestEstimate(t *testing.T) { q := []byte(`{"from":8996,"highlight":{},"query":{"bool":false,"field":"free_parking"},"size":405}`) var sr *SearchRequest err := json.Unmarshal(q, &sr) if err != nil { t.Fatal(err) } x := MemoryNeededForSearchResult(sr) fmt.Println(x) } ``` + For the query, the MemoryNeededForSearchResult API claims that it needs .. 6363433784 bytes (that's over 6GB!). + Fixing the size calculation estimate when the query requests for "fields" to be returned or "highlighting", basing the number of results returned on the collector's PreAllocSizeSkipCap. --- search.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/search.go b/search.go index a9d00b935..aced23f75 100644 --- a/search.go +++ b/search.go @@ -600,11 +600,11 @@ func MemoryNeededForSearchResult(req *SearchRequest) uint64 { estimate += len(req.Facets) * fr.Size() } - // highlighting, store + // overhead from highlighting, store var d document.Document if len(req.Fields) > 0 || req.Highlight != nil { - for i := 0; i < (req.Size + req.From); i++ { - estimate += (req.Size + req.From) * d.Size() + for i := 0; i < numDocMatches; i++ { + estimate += numDocMatches * d.Size() } }