Last year Mark posted an entry here talking about the idea of Left & Right Unlinking for Rete networks. I wanted to understand the internals of Drools, so that task seemed a perfect opportunity to dig into the engine. Maybe a little too complex. A month later, Mark came back with Lazily Enabled Truth Maintenance, which felt like an achievable goal, so I decided to give it a shot and posted a patch some days later. I then started to work on Left & Right Unlinking on my spare time and finished a sort of “alpha” version later in November, but with a month of vacations in December plus a hard time coming back to real life, I’ve just been able to send a pull request last month.
This first implementation unlinks only the right side of JoinNodes and, once it’s linked, never unlink it again. I did tried unlinking also the left side and allowing nodes to link and unlink themselves according to whether or not there were tuples on their left and right memories, but the results were not satisfactory yet with a lot of churn going on. This first simpler version with only the right side unlinked, already shows some improvements on response time and memory usage for rule bases where, for a given session, some of the rules never get executed. That’s usually the case for decision services. If you think your use case falls into this category, give it a try and let us know the results!
By default all nodes are still linked and nothing is changed in the existing implementation, but you can activate the L&R Unlinking by setting the drools.lrUnlinkingEnabled property to true in your knowledge base configuration. It’s been recently merged and is available with the 5.2.x snapshot.
The next step is probably to generify the solution to all Beta nodes (it’s Join node specific, today) and to try to unlink both sides in a more aggressive way, as described by Mark in the original article.