From fe864792b5a67ea64b3bb953ba74ca712801dbc5 Mon Sep 17 00:00:00 2001 From: Cory LaNou Date: Wed, 11 Feb 2015 09:34:59 -0700 Subject: [PATCH] map should do more work locally before passing up to reduce --- cmd/influxd/config.go | 2 +- influxql/engine.go | 56 ++++++++++++++++++++++++++----------------- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/cmd/influxd/config.go b/cmd/influxd/config.go index 8d6a229ca9..eedffc6179 100644 --- a/cmd/influxd/config.go +++ b/cmd/influxd/config.go @@ -58,7 +58,7 @@ type Config struct { } `toml:"authentication"` Admin struct { - Port int `toml:"port"` + Port int `toml:"port"` } `toml:"admin"` HTTPAPI struct { diff --git a/influxql/engine.go b/influxql/engine.go index c29a3deedf..7e1a649093 100644 --- a/influxql/engine.go +++ b/influxql/engine.go @@ -669,54 +669,66 @@ func ReduceMean(key Key, values []interface{}, e *Emitter) { // MapMin collects the values to pass to the reducer func MapMin(itr Iterator, e *Emitter, tmin int64) { - var values []float64 + var min *float64 for k, v := itr.Next(); k != 0; k, v = itr.Next() { - values = append(values, v.(float64)) + if min == nil { + m := v.(float64) + min = &m + } + m := math.Min(*min, v.(float64)) + min = &m + } + if min != nil { + e.Emit(Key{tmin, itr.Tags()}, *min) } - e.Emit(Key{tmin, itr.Tags()}, values) } // ReduceMin computes the min of value. func ReduceMin(key Key, values []interface{}, e *Emitter) { var min *float64 + for _, value := range values { - vals := value.([]float64) - for _, v := range vals { - // Initialize min - if min == nil { - min = &v - } - m := math.Min(*min, v) - min = &m + v := value.(float64) + // Initialize min + if min == nil { + min = &v } + m := math.Min(*min, v) + min = &m } e.Emit(key, min) } // MapMax collects the values to pass to the reducer func MapMax(itr Iterator, e *Emitter, tmax int64) { - var values []float64 + var max *float64 for k, v := itr.Next(); k != 0; k, v = itr.Next() { - values = append(values, v.(float64)) + if max == nil { + m := v.(float64) + max = &m + } + m := math.Max(*max, v.(float64)) + max = &m + } + if max != nil { + e.Emit(Key{tmax, itr.Tags()}, *max) } - e.Emit(Key{tmax, itr.Tags()}, values) } // ReduceMax computes the max of value. func ReduceMax(key Key, values []interface{}, e *Emitter) { var max *float64 + for _, value := range values { - vals := value.([]float64) - for _, v := range vals { - // Initialize max - if max == nil { - max = &v - } - m := math.Max(*max, v) - max = &m + v := value.(float64) + // Initialize max + if max == nil { + max = &v } + m := math.Max(*max, v) + max = &m } e.Emit(key, max) }