aws / event-ruler

Event Ruler is a Java library that allows matching many thousands of Events per second to any number of expressive and sophisticated rules.
Apache License 2.0
556 stars 58 forks source link

Adding optional Configuration to Machine that can be used to enable a… #125

Closed jonessha closed 7 months ago

jonessha commented 8 months ago

…dditional NameState re-use where each key subsequence has a single NameState

Description of changes:

Introducing Configuration for Machines, which can be extended in the future with additional functionality. Right now Configuration offers a single flag. Copying Javadoc for flag as it summarizes the change:

Normally, NameStates are re-used for a given key subsequence and pattern if this key subsequence and pattern have been previously added, or if the current rule has already added a pattern for the given key subsequence. Hence, by default, NameState re-use is opportunistic. But by setting this flag to true, NameState re-use will be forced for a key subsequence. This means that the first pattern being added for a key subsequence for a rule will re-use a NameState if that key subsequence has been added before. Meaning each key subsequence has a single NameState. This improves memory utilization exponentially in some cases but does lead to more sub-rules being stored in individual NameStates, which Ruler sometimes iterates over, which can cause a modest runtime performance regression.

Long previously pushed me in this direction when making memory improvements (https://github.com/aws/event-ruler/pull/88#issuecomment-1529216782). I made a similar change to this one before (https://github.com/aws/event-ruler/pull/88#issuecomment-1533724218) but quickly reverted after discovering that some consumers are highly sensitive to the modest runtime increase (https://github.com/aws/event-ruler/pull/88#discussion_r1194146291). This is why I am now guarding this improvement behind Configuration. Although I expect the average consumer to benefit from enabling this flag, it will start off as disabled, so as not to break any current consumers who are highly latency sensitive.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.