From: <jbo...@li...> - 2006-04-21 12:04:09
|
Author: woolfel Date: 2006-04-21 08:04:04 -0400 (Fri, 21 Apr 2006) New Revision: 3884 Modified: labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/GenerateRuleSet.java labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetPerformanceTest.java Log: updated the rule generator and performance test so I can run tests with 2k rules and 1 to 3 conditions per rule. peter Modified: labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/GenerateRuleSet.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/GenerateRuleSet.java 2006-04-21 11:47:56 UTC (rev 3883) +++ labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/GenerateRuleSet.java 2006-04-21 12:04:04 UTC (rev 3884) @@ -4,13 +4,91 @@ public class GenerateRuleSet { - /** + String linebreak = System.getProperty("line.separator"); + String tab = " "; + + /** * */ public GenerateRuleSet() { super(); } + public void generate3Condition(String outputFile, int count) { + try { + FileWriter writer = new FileWriter(outputFile); + StringBuffer buf = new StringBuffer(); + // delcare the package + buf.append("package org.drools.samples" + linebreak); + buf.append("import com.sample.benchmark.models.Account;" + linebreak + linebreak); + // now loop + for (int idx=0; idx < count; idx++) { + buf.append("rule rule" + idx + "" + linebreak); + buf.append(" when" + linebreak); + buf.append(" $acc : Account(status == \"standard\", title == \"mr\", accountId == \"acc" + idx + + "\")" + linebreak); + buf.append(" then" + linebreak); + buf.append(" System.out.println(\"rule" + idx + " fired\");" + linebreak); + buf.append("end" + linebreak + linebreak); + } + writer.write(buf.toString()); + writer.close(); + System.out.println("Generated " + count + " rules to " + outputFile); + } catch (Exception e) { + + } + } + + public void generate2Condition(String outputFile, int count) { + try { + FileWriter writer = new FileWriter(outputFile); + StringBuffer buf = new StringBuffer(); + // delcare the package + buf.append("package org.drools.samples" + linebreak); + buf.append("import com.sample.benchmark.models.Account;" + linebreak + linebreak); + // now loop + for (int idx=0; idx < count; idx++) { + buf.append("rule rule" + idx + "" + linebreak); + buf.append(" when" + linebreak); + buf.append(" $acc : Account(status == \"standard\", accountId == \"acc" + idx + + "\")" + linebreak); + buf.append(" then" + linebreak); + buf.append(" System.out.println(\"rule" + idx + " fired\");" + linebreak); + buf.append("end" + linebreak + linebreak); + } + writer.write(buf.toString()); + writer.close(); + System.out.println("Generated " + count + " rules to " + outputFile); + } catch (Exception e) { + + } + } + + public void generateOneCondition(String outputFile, int count) { + try { + FileWriter writer = new FileWriter(outputFile); + StringBuffer buf = new StringBuffer(); + // delcare the package + buf.append("package org.drools.samples" + linebreak); + buf.append("import com.sample.benchmark.models.Account;" + linebreak + linebreak); + // now loop + for (int idx=0; idx < count; idx++) { + buf.append("rule rule" + idx + "" + linebreak); + buf.append(" when" + linebreak); + buf.append(" $acc : Account(accountId == \"acc" + idx + + "\")" + linebreak); + buf.append(" then" + linebreak); + buf.append(" System.out.println(\"rule" + idx + " fired\");" + linebreak); + buf.append("end" + linebreak + linebreak); + } + writer.write(buf.toString()); + writer.close(); + System.out.println("Generated " + count + " rules to " + outputFile); + } catch (Exception e) { + + } + } + public static void main(String[] args) { // the number of rules int count = 100; @@ -19,38 +97,26 @@ if (args == null || args.length < 1) { // print out a message of the options System.out.println("No parameters were set. Please provide a rule count"); - System.out.println("and filename."); + System.out.println("filename, ruleType: 1, 2 or 3."); System.out.println(""); - System.out.println("example: GenerateRuleSet 1000 1000rules.drl"); + System.out.println("example: GenerateRuleSet 1000 1000rules.drl 1"); } else { if (args[0] != null) { count = Integer.parseInt(args[0]); outputFile = args[1]; } - String linebreak = System.getProperty("line.separator"); - String tab = " "; - try { - FileWriter writer = new FileWriter(outputFile); - StringBuffer buf = new StringBuffer(); - // delcare the package - buf.append("package org.drools.samples" + linebreak); - buf.append("import com.sample.benchmark.models.Account;" + linebreak + linebreak); - // now loop - for (int idx=0; idx < count; idx++) { - buf.append("rule rule" + idx + "" + linebreak); - buf.append(" when" + linebreak); - buf.append(" $acc : Account(status == \"standard\", title == \"mr\", accountId == \"acc" + idx + - "\")" + linebreak); - buf.append(" then" + linebreak); - buf.append(" System.out.println(\"rule" + idx + " fired\");" + linebreak); - buf.append("end" + linebreak + linebreak); - } - writer.write(buf.toString()); - writer.close(); - System.out.println("Generated " + count + " rules to " + outputFile); - } catch (Exception e) { - + int type = 1; + if (args[2] != null) { + type = Integer.parseInt(args[2]); } + GenerateRuleSet grs = new GenerateRuleSet(); + if (type == 3) { + grs.generate3Condition(outputFile,count); + } else if (type == 2) { + grs.generate2Condition(outputFile, count); + } else { + grs.generateOneCondition(outputFile,count); + } } } Modified: labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetPerformanceTest.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetPerformanceTest.java 2006-04-21 11:47:56 UTC (rev 3883) +++ labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetPerformanceTest.java 2006-04-21 12:04:04 UTC (rev 3884) @@ -234,4 +234,173 @@ e.printStackTrace(); } } + + /** + * + * + */ + public void test2KRuleFire() { + try { + int factCount = 50000; + String file = "2000_rules_1condition.drl"; + int loop = 5; + long totalload = 0; + long totalassert = 0; + long totalfire = 0; + for (int c=0; c < loop; c++) { + long loadStart = System.currentTimeMillis(); + RuleBase ruleBase = readRule(file); + long loadEnd = System.currentTimeMillis(); + long loadet = loadEnd - loadStart; + totalload += loadet; + System.out.println("time to load " + file + + " " + loadet + "ms"); + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + ArrayList objects = new ArrayList(); + // create the objects + for (int idx=0; idx < factCount; idx++) { + Account acc = new Account(); + acc.setAccountId("acc"+idx); + acc.setTitle("mr"); + acc.setStatus("standard"); + objects.add(acc); + } + Iterator itr = objects.iterator(); + long assertStart = System.currentTimeMillis(); + while( itr.hasNext() ) { + workingMemory.assertObject(itr.next()); + } + long assertEnd = System.currentTimeMillis(); + long assertet = assertEnd - assertStart; + totalassert += assertet; + System.out.println("time to assert " + assertet + + " ms"); + long fireStart = System.currentTimeMillis(); + workingMemory.fireAllRules(); + long fireEnd = System.currentTimeMillis(); + long fireet = fireEnd - fireStart; + totalfire += fireet; + System.out.println("time to fireAllRules " + fireet + + " ms"); + workingMemory.dispose(); + } + System.out.println(file); + System.out.println("number of objects asserted " + factCount); + System.out.println("average load " + (totalload/loop) + " ms"); + System.out.println("average assert " + (totalassert/loop) + " ms"); + System.out.println("average fire " + (totalfire/loop) + " ms"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void test2KRuleFire2Conditions() { + try { + int factCount = 50000; + String file = "2000_rules_2condition.drl"; + int loop = 5; + long totalload = 0; + long totalassert = 0; + long totalfire = 0; + for (int c=0; c < loop; c++) { + long loadStart = System.currentTimeMillis(); + RuleBase ruleBase = readRule(file); + long loadEnd = System.currentTimeMillis(); + long loadet = loadEnd - loadStart; + totalload += loadet; + System.out.println("time to load " + file + + " " + loadet + "ms"); + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + ArrayList objects = new ArrayList(); + // create the objects + for (int idx=0; idx < factCount; idx++) { + Account acc = new Account(); + acc.setAccountId("acc"+idx); + acc.setTitle("mr"); + acc.setStatus("standard"); + objects.add(acc); + } + Iterator itr = objects.iterator(); + long assertStart = System.currentTimeMillis(); + while( itr.hasNext() ) { + workingMemory.assertObject(itr.next()); + } + long assertEnd = System.currentTimeMillis(); + long assertet = assertEnd - assertStart; + totalassert += assertet; + System.out.println("time to assert " + assertet + + " ms"); + long fireStart = System.currentTimeMillis(); + workingMemory.fireAllRules(); + long fireEnd = System.currentTimeMillis(); + long fireet = fireEnd - fireStart; + totalfire += fireet; + System.out.println("time to fireAllRules " + fireet + + " ms"); + workingMemory.dispose(); + } + System.out.println(file); + System.out.println("number of objects asserted " + factCount); + System.out.println("average load " + (totalload/loop) + " ms"); + System.out.println("average assert " + (totalassert/loop) + " ms"); + System.out.println("average fire " + (totalfire/loop) + " ms"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void test2KRuleFire3Conditions() { + try { + int factCount = 50000; + String file = "2000_rules_3condition.drl"; + int loop = 5; + long totalload = 0; + long totalassert = 0; + long totalfire = 0; + for (int c=0; c < loop; c++) { + long loadStart = System.currentTimeMillis(); + RuleBase ruleBase = readRule(file); + long loadEnd = System.currentTimeMillis(); + long loadet = loadEnd - loadStart; + totalload += loadet; + System.out.println("time to load " + file + + " " + loadet + "ms"); + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + ArrayList objects = new ArrayList(); + // create the objects + for (int idx=0; idx < factCount; idx++) { + Account acc = new Account(); + acc.setAccountId("acc"+idx); + acc.setTitle("mr"); + acc.setStatus("standard"); + objects.add(acc); + } + Iterator itr = objects.iterator(); + long assertStart = System.currentTimeMillis(); + while( itr.hasNext() ) { + workingMemory.assertObject(itr.next()); + } + long assertEnd = System.currentTimeMillis(); + long assertet = assertEnd - assertStart; + totalassert += assertet; + System.out.println("time to assert " + assertet + + " ms"); + long fireStart = System.currentTimeMillis(); + workingMemory.fireAllRules(); + long fireEnd = System.currentTimeMillis(); + long fireet = fireEnd - fireStart; + totalfire += fireet; + System.out.println("time to fireAllRules " + fireet + + " ms"); + workingMemory.dispose(); + } + System.out.println(file); + System.out.println("number of objects asserted " + factCount); + System.out.println("average load " + (totalload/loop) + " ms"); + System.out.println("average assert " + (totalassert/loop) + " ms"); + System.out.println("average fire " + (totalfire/loop) + " ms"); + } catch (Exception e) { + e.printStackTrace(); + } + } } |