From f2b48b8c4ae253cef5f53ffa7673af6232bafcf5 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Wed, 22 May 2013 00:53:25 +0200 Subject: [PATCH] Make getValuesAtIntervalOp consume all chunk data in one pass. This is mainly a small performance improvement, since we skip past the last extracted time immediately if it was also the last sample in the chunk, instead of trying to extract non-existent values before the chunk end again and again and only gradually approaching the end of the chunk. --- storage/metric/operation.go | 6 +++--- storage/metric/operation_test.go | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/storage/metric/operation.go b/storage/metric/operation.go index 595cfaf19..f390caaae 100644 --- a/storage/metric/operation.go +++ b/storage/metric/operation.go @@ -161,12 +161,12 @@ func (g *getValuesAtIntervalOp) ExtractSamples(in model.Values) (out model.Value lastExtractedTime := out[len(out)-1].Timestamp in = in.TruncateBefore(lastExtractedTime.Add(1)) g.from = g.from.Add(g.interval) - if lastExtractedTime.Equal(lastChunkTime) { - break - } for !g.from.After(lastExtractedTime) { g.from = g.from.Add(g.interval) } + if lastExtractedTime.Equal(lastChunkTime) { + break + } if g.from.After(g.through) { break } diff --git a/storage/metric/operation_test.go b/storage/metric/operation_test.go index 772f439da..a7744ce3a 100644 --- a/storage/metric/operation_test.go +++ b/storage/metric/operation_test.go @@ -1610,6 +1610,16 @@ func TestGetValuesAtIntervalOp(t *testing.T) { t.Fatalf("%d. expected length %d, got %d: %v", i, len(scenario.out), len(actual), scenario.op) t.Fatalf("%d. expected length %d, got %d", i, len(scenario.out), len(actual)) } + + if len(scenario.in) < 1 { + continue + } + opTime := scenario.op.CurrentTime() + lastExtractedTime := scenario.out[len(scenario.out)-1].Timestamp + if opTime != nil && opTime.Before(lastExtractedTime) { + t.Fatalf("%d. expected op.CurrentTime() to be nil or after current chunk, %v, %v", i, scenario.op.CurrentTime(), scenario.out) + } + for j, out := range scenario.out { if out != actual[j] { t.Fatalf("%d. expected output %v, got %v", i, scenario.out, actual)