About Geoffrey De Smet

Geoffrey De Smet (Red Hat) is the lead and founder of OptaPlanner. Before joining Red Hat in 2010, he was formerly employed as a Java consultant, an A.I. researcher and an enterprise application project lead.

Drools 6 Performance with the PHREAK Algorithm

Drools 6 introduces a new lazy matching algorithm. The details of that algorithm have been covered in two previous blogs:

The first article discussed performance and why the batch and lazy aspects of the algorithm, make it hard to compare.

“One final point on performance. One single rule in general will not evaluate any faster with PHREAK than it does with RETE. For a given rule and same data set, which using a root context object to enable and disable matching, both attempt the same amount of matches and produce the same number of rule instances, and take roughly the same time. Except for the use case with subnetworks and accumulates.

PHREAK can however be considered more forgiving that RETE for poorly written rule bases and with a more graceful degradation of performance as the number of rules and complexity increases.

RETE will also churn away producing partial machines for rules that do not have data in all the joins; where as PHREAK will avoid this.

So it’s not that PHREAK is faster than RETE, it just won’t slow down as much as your system grows!”

More recently the OptaPlanner team started benchmarking the same set of rules between ReteOO and Phreak: Which rule engine algorithm is faster: ReteOO or Phreak? 

They found that that three tests were 20% faster, and one test 4% slower. A user left a comment, for that article, relating at 17% performance difference.


The OptaPlanner team have invested time into making sure the way they write the rules do not hit any Rete walls.  They have removed many of the issues, such as multiple accumulates in a single rule.

One user was interested in what happens if you implement rules in a way known to cause problems with ReteOO, would it handle it more gracefully. They created 4 rules, each with two accumulates. The DRL file can be found here, and a copy of one of the rules is shown below:

rule gold_account
  account: Account()
  Number(this >= 50000) from accumulate(t: Transaction(source == account); sum(t.amount))
  Number(this >= 50000) from accumulate(t: Transaction(target == account); sum(t.amount))
  //System.out.println("Gold account: " + account);

The results were promising, a 400% (5x) performance gain for Phreak :) This is mostly enabled by the way that Phreak evaluates rules in batches, avoiding a lot of wasted work. It certainly shows we’ve achieved one of the aims quoted from the earlier paragraph:

“PHREAK can however be considered more forgiving that RETE for poorly written rule bases and with a more graceful degradation of performance as the number of rules and complexity increases.”

The algorithm so far has been designed for correctness, especially with regards to thread safety and future multi-core exploitation. So this is just the start, we still have plenty more optimisations and improvements to do.

Reference: Drools 6 Performance with the PHREAK Algorithm from our JCG partner Geoffrey De Smet at the Drools & jBPM blog.
Related Whitepaper:

Functional Programming in Java: Harnessing the Power of Java 8 Lambda Expressions

Get ready to program in a whole new way!

Functional Programming in Java will help you quickly get on top of the new, essential Java 8 language features and the functional style that will change and improve your code. This short, targeted book will help you make the paradigm shift from the old imperative way to a less error-prone, more elegant, and concise coding style that’s also a breeze to parallelize. You’ll explore the syntax and semantics of lambda expressions, method and constructor references, and functional interfaces. You’ll design and write applications better using the new standards in Java 8 and the JDK.

Get it Now!  

Leave a Reply

3 × = nine

Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below: