From f84331abdea214efb1530416a4957ba2dda81e43 Mon Sep 17 00:00:00 2001 From: Andrey Meshkov Date: Thu, 27 Feb 2020 14:02:05 +0300 Subject: [PATCH] Merge: -(dnsforward): fixing an issue with the querylog speed Squashed commit of the following: commit 7db062d2ce40369fc6c7eaa89f678c660d531516 Author: Andrey Meshkov Date: Thu Feb 27 12:08:58 2020 +0300 *(dnsforward): added comment about oldest commit dbec84d8a8c60ca040faa59f8aa818ed5959e92a Author: Simon Zolin Date: Thu Feb 27 11:16:58 2020 +0300 fix commit d6df1ee28b3918e8d1676ff6ab4b516d46fe4202 Author: Andrey Meshkov Date: Wed Feb 26 20:42:11 2020 +0300 -(dnsforward): fixing an issue with the querylog speed --- querylog/qlog.go | 10 +++++++--- querylog/querylog_search.go | 20 +++++++++++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/querylog/qlog.go b/querylog/qlog.go index a0570011..55020612 100644 --- a/querylog/qlog.go +++ b/querylog/qlog.go @@ -231,6 +231,13 @@ func (l *queryLog) getData(params getDataParams) map[string]interface{} { // remove extra records entries = entries[(len(entries) - getDataLimit):] } + if len(entries) == getDataLimit { + // change the "oldest" value here. + // we cannot use the "oldest" we got from "searchFiles" anymore + // because after adding in-memory records and removing extra records + // the situation has changed + oldest = entries[len(entries)-1].Time + } // init the response object var data = []map[string]interface{}{} @@ -246,9 +253,6 @@ func (l *queryLog) getData(params getDataParams) map[string]interface{} { len(entries), total, params.OlderThan, time.Since(now)) var result = map[string]interface{}{} - if len(entries) == getDataLimit { - oldest = entries[0].Time - } result["oldest"] = "" if !oldest.IsZero() { result["oldest"] = oldest.Format(time.RFC3339Nano) diff --git a/querylog/querylog_search.go b/querylog/querylog_search.go index 236c1940..f9493af9 100644 --- a/querylog/querylog_search.go +++ b/querylog/querylog_search.go @@ -36,10 +36,16 @@ func (l *queryLog) searchFiles(params getDataParams) ([]*logEntry, time.Time, in err = r.SeekStart() } else { err = r.Seek(params.OlderThan.UnixNano()) + if err == nil { + // Read to the next record right away + // The one that was specified in the "oldest" param is not needed, + // we need only the one next to it + _, err = r.ReadNext() + } } if err != nil { - log.Error("Failed to Seek(): %v", err) + log.Debug("Cannot Seek() to %v: %v", params.OlderThan, err) return entries, oldest, 0 } @@ -54,12 +60,16 @@ func (l *queryLog) searchFiles(params getDataParams) ([]*logEntry, time.Time, in break } - if entry != nil { - entries = append(entries, entry) - } - oldestNano = ts total++ + + if entry != nil { + entries = append(entries, entry) + if len(entries) == getDataLimit { + // Do not read more than "getDataLimit" records at once + break + } + } } oldest = time.Unix(0, oldestNano)