From e92e39eddff988dc7732abb35ac2edbba130e5c8 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sat, 28 Sep 2019 20:30:58 +0300 Subject: [PATCH] app/vmselect/netstorage: reduce the number of disk seeks when the query processes big number of time series --- app/vmselect/netstorage/netstorage.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/vmselect/netstorage/netstorage.go b/app/vmselect/netstorage/netstorage.go index 0bcbd546a..a024f59b8 100644 --- a/app/vmselect/netstorage/netstorage.go +++ b/app/vmselect/netstorage/netstorage.go @@ -786,6 +786,14 @@ func ProcessSearchQuery(at *auth.Token, sq *storage.SearchQuery, fetchData bool, pts.addrs = addrs } + // Sort rss.packedTimeseries by the first addr offset in order + // to reduce the number of disk seeks during unpacking in RunParallel. + // In this case tmpBlocksFile must be read almost sequentially. + sort.Slice(rss.packedTimeseries, func(i, j int) bool { + pts := rss.packedTimeseries + return pts[i].addrs[0].offset < pts[j].addrs[0].offset + }) + return &rss, isPartialResult, nil }