Monday, November 21, 2011

Primary Key Variables and Rule Activations in Pachinko

While Pachinko is a Rete-inspired rule engine, it contains features that make it suitable for stream-oriented event processing. One such feature is its use of Primary Key variables.

In the simplest form of rule engines, a rule fires any time a fact the rule depends on is modified. This is how Pachinko operates if all the rule parameters used are Variables.

However, in a stream processing environment, it's not always desirable to have a rule fire any time any one of its parameters changes. For example, a rule which compares the share price of a seldom traded stock against the current Dow Jones average would require significant compute resources if it recalculated any time Either the share price OR the Dow changed, since even though the share price of the stock might only change a couple of times a day, the Dow is fluctuating continuously.

In that case, what's desired is a way to tell the engine to only recalculate when an IMPORTANT value (the share price) changes, and to use the most recent unimportant value (the Dow) but don't bother recalculating every time the unimportant value changes.

To make Pachinko do this, use PKVariables for the important values and Variables for the unimportant values. The rule won't fire at all until all variables have received values, but thereafter, the rule will only recalculate when one of the PKVariables changes value.

To get the latest version of Pachinko incorporating this feature and sample JUnit tests exercising it, go here.

No comments: