Browse Source

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.
pull/268/head
Julius Volz 12 years ago
parent
commit
f2b48b8c4a
  1. 6
      storage/metric/operation.go
  2. 10
      storage/metric/operation_test.go

6
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
}

10
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)

Loading…
Cancel
Save