app/vmselect/netstorage: reset big result values every 10 seconds instead of after processing every time series

This should reduce GC pressure when processing time series with big number of rows
This commit is contained in:
Aliaksandr Valialkin 2020-06-24 19:36:55 +03:00
parent 8dec17470d
commit 05d754d7bb

View File

@ -12,6 +12,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmstorage" "github.com/VictoriaMetrics/VictoriaMetrics/app/vmstorage"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil" "github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/decimal" "github.com/VictoriaMetrics/VictoriaMetrics/lib/decimal"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/fasttime"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/storage" "github.com/VictoriaMetrics/VictoriaMetrics/lib/storage"
"github.com/VictoriaMetrics/metrics" "github.com/VictoriaMetrics/metrics"
) )
@ -89,6 +90,7 @@ func init() {
func timeseriesWorker(workerID uint) { func timeseriesWorker(workerID uint) {
var rs Result var rs Result
var rsLastResetTime uint64
for tsw := range timeseriesWorkCh { for tsw := range timeseriesWorkCh {
rss := tsw.rss rss := tsw.rss
if time.Until(rss.deadline.Deadline) < 0 { if time.Until(rss.deadline.Deadline) < 0 {
@ -104,9 +106,11 @@ func timeseriesWorker(workerID uint) {
} }
tsw.rowsProcessed = len(rs.Values) tsw.rowsProcessed = len(rs.Values)
tsw.doneCh <- nil tsw.doneCh <- nil
if cap(rs.Values) > 1024*1024 && 4*len(rs.Values) < cap(rs.Values) { currentTime := fasttime.UnixTimestamp()
if cap(rs.Values) > 1024*1024 && 4*len(rs.Values) < cap(rs.Values) && currentTime-rsLastResetTime > 10 {
// Reset rs in order to preseve memory usage after processing big time series with millions of rows. // Reset rs in order to preseve memory usage after processing big time series with millions of rows.
rs = Result{} rs = Result{}
rsLastResetTime = currentTime
} }
} }
} }