Implement a shared ResourceRules structure in MeshContext #13273
Labels
kind/design
Design doc or related
kind/improvement
Improvement on an existing feature
triage/accepted
The issue was reviewed and is complete enough to start working on it
Description
Today, Kuma calls
outbound.BuildRules
method for each xDS connectionkuma/pkg/plugins/policies/core/rules/outbound/resourcerules.go
Line 86 in 4d8c12d
This results in an
outbound.ResourceRules
structure per xDS connection. That's inefficient both from a CPU and memory point of view, as significant parts of these structures are the same.Imagine a situation where a MeshService
backend
has onlyproducer
policies. In that case, allbackend
clients have exactly the samebackend
outbound configuration. But today we're computing and storing this configuration separately for each client.There is still a way for each client to redefine the configuration for the
backend
outbound – by usingconsumer
policies. That's why the shared structure inMeshContext
can't be a simpleMeshService -> Conf
map; it has to be more complex and take into account clients with different confs.Once this structure is implemented, we can switch policy plugins to use it instead of
policies.ToRules.ResourceRules
:kuma/pkg/plugins/policies/meshtimeout/plugin/v1alpha1/plugin.go
Line 71 in d3a493d
Data structure considerations
Ideally, we'd like to have a data structure that for a given policy type maps
(DPP, Mesh*Service)
toConf
, but it's clear memory-wise it's going to depend, either on:consumer
policies (each consumer policy can either match or not match the given DPP proxy)Neither of the options is ideal.
What we can do, though, is to create a data structure that for a given policy type maps
(Proxy, Mesh*Service)
to[]Conf
, so that merging all confs in[]Conf
gives the resulting structure forProxy
that consumesMesh*Service
. In that case, both memory and the lookup complexity are O(N), where N is the number ofconsumer
policies.The text was updated successfully, but these errors were encountered: