mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-13 03:42:35 -06:00
739777cfff
This pretty substantially improves performance by avoiding to do a JSON round trip and then converting into AST types. There are a couple of fields left that require the round trip, we can iterate on this as needed to supply better options for the results and metrics. This custom ASTer leaves out the rule counts, which also helps to improve the performance. On my local machine the numbers look like: ``` name old time/op new time/op delta MaskingNop-8 129µs ± 1% 110µs ± 1% -15.19% (p=0.000 n=7+10) MaskingRuleCountsNop/1Rules-8 138µs ± 1% 111µs ± 1% -19.34% (p=0.000 n=10+10) MaskingRuleCountsNop/10Rules-8 180µs ± 1% 116µs ± 4% -35.70% (p=0.000 n=10+10) MaskingRuleCountsNop/100Rules-8 614µs ± 1% 113µs ± 1% -81.66% (p=0.000 n=10+8) MaskingRuleCountsNop/1000Rules-8 5.16ms ± 2% 0.11ms ± 1% -97.79% (p=0.000 n=10+10) MaskingErase-8 148µs ± 2% 129µs ± 0% -12.65% (p=0.000 n=10+10) name old alloc/op new alloc/op delta MaskingNop-8 56.7kB ± 0% 48.0kB ± 0% -15.43% (p=0.000 n=10+10) MaskingRuleCountsNop/1Rules-8 59.5kB ± 0% 48.0kB ± 0% -19.41% (p=0.000 n=10+10) MaskingRuleCountsNop/10Rules-8 84.9kB ± 0% 48.0kB ± 0% -43.47% (p=0.000 n=10+10) MaskingRuleCountsNop/100Rules-8 362kB ± 0% 48kB ± 0% -86.73% (p=0.000 n=9+10) MaskingRuleCountsNop/1000Rules-8 3.26MB ± 1% 0.05MB ± 0% -98.52% (p=0.000 n=10+10) MaskingErase-8 65.7kB ± 0% 57.0kB ± 0% -13.33% (p=0.000 n=10+10) name old allocs/op new allocs/op delta MaskingNop-8 1.23k ± 0% 1.12k ± 0% -8.46% (p=0.000 n=10+10) MaskingRuleCountsNop/1Rules-8 1.31k ± 0% 1.12k ± 0% -14.32% (p=0.000 n=10+10) MaskingRuleCountsNop/10Rules-8 1.98k ± 0% 1.12k ± 0% -43.30% (p=0.000 n=10+10) MaskingRuleCountsNop/100Rules-8 8.74k ± 0% 1.12k ± 0% -87.13% (p=0.000 n=10+10) MaskingRuleCountsNop/1000Rules-8 76.3k ± 0% 1.1k ± 0% -98.52% (p=0.000 n=10+10) MaskingErase-8 1.33k ± 0% 1.22k ± 0% -7.84% (p=0.000 n=10+10) ``` So the performance no longer scales with the number of rules hit, and overall the base cost is almost 20% faster. This time directly impacts round trip latency for OPA REST clients performing evaluations. Signed-off-by: Patrick East <east.patrick@gmail.com>
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
// Copyright 2017 The OPA Authors. All rights reserved.
|
|
// Use of this source code is governed by an Apache2
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package server
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/open-policy-agent/opa/ast"
|
|
"github.com/open-policy-agent/opa/metrics"
|
|
"github.com/open-policy-agent/opa/storage"
|
|
"github.com/open-policy-agent/opa/topdown"
|
|
)
|
|
|
|
// Buffer defines an interface for recording decisions.
|
|
// DEPRECATED. Use Decision Logging instead.
|
|
type Buffer interface {
|
|
// Push adds the given Info into the buffer.
|
|
Push(*Info)
|
|
|
|
// Iter iterates over the buffer, from oldest present Info to newest. It should
|
|
// call fn on each Info.
|
|
Iter(fn func(*Info))
|
|
}
|
|
|
|
// Info contains information describing a policy decision.
|
|
type Info struct {
|
|
Txn storage.Transaction
|
|
Revision string // Deprecated: Use `Bundles` instead
|
|
Bundles map[string]BundleInfo
|
|
DecisionID string
|
|
RemoteAddr string
|
|
Query string
|
|
Path string
|
|
Timestamp time.Time
|
|
Input *interface{}
|
|
InputAST ast.Value
|
|
Results *interface{}
|
|
Error error
|
|
Metrics metrics.Metrics
|
|
Trace []*topdown.Event
|
|
}
|
|
|
|
// BundleInfo contains information describing a bundle.
|
|
type BundleInfo struct {
|
|
Revision string
|
|
}
|