Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add builtinFuncs to ExecutionState.Funcs as desired to reduce memory usage. #2178

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Features

- [#2154](https://github.com/influxdata/kapacitor/pull/2154): Add ability to skip ssl verification with an alert post node. Thanks @itsHabib!
- [#2177](https://github.com/influxdata/kapacitor/issues/2177): NewFunctions func occupies many memory when state_count has large working_cardinality

### Bugfixes

Expand Down
2 changes: 1 addition & 1 deletion tick/stateful/eval_function_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func eval(n NodeEvaluator, scope *Scope, executionState ExecutionState) (interfa
}

func lookupFunc(name string, funcs Funcs, scope ReadOnlyScope) Func {
f := funcs[name]
f := funcs.Get(name)
if f != nil {
return f
}
Expand Down
2 changes: 1 addition & 1 deletion tick/stateful/execution_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type ExecutionState struct {

func CreateExecutionState() ExecutionState {
return ExecutionState{
Funcs: NewFunctions(),
Funcs: NewEmptyFuncs(),
}
}

Expand Down
28 changes: 28 additions & 0 deletions tick/stateful/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,29 @@ func FuncDomains(f Func) Domains {
// Lookup for functions
type Funcs map[string]Func

func (funcs Funcs) Get(name string) Func {
if f := funcs[name]; f != nil {
return f
}
if f := statelessFuncs[name]; f != nil {
funcs[name] = f
return f
}
switch name {
case "sigma":
funcs[name] = &sigma{}
return funcs[name]
case "count":
funcs[name] = &count{}
return funcs[name]
case "spread":
funcs[name] = &spread{min: math.Inf(+1), max: math.Inf(-1)}
return funcs[name]
default:
return nil
}
}

var statelessFuncs Funcs

var builtinFuncs Funcs
Expand Down Expand Up @@ -252,6 +275,11 @@ func NewFunctions() Funcs {
return funcs
}

// Return empty Funcs
func NewEmptyFuncs() Funcs {
return make(Funcs, 0)
}

type math1Func func(float64) float64
type math1 struct {
name string
Expand Down