Re: [rules-users] Compiling .drl files inside of a JUnit test
Edson wrote: Right now, Drools uses JUnit for all its unit and integration tests. Take a look at the integration tests and I think you will figure out: http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/ Thanks for the link but I do not see how this helps with my problem. Perhaps it would if I could see the actual .drl files. For example, when I use getClass().getResourceAsStream(...) a null is returned but even it that part worked, it wouldn't be any different than what I currently have. Seeing the .drl file is not the problem. Getting the import statements in the .drl file to actually find the proper classes is. Do you know how the actual .drl files used in the unit testing are referring to the objects they need? Ron _ Use video conversation to talk face-to-face with Windows Live Messenger. http://www.windowslive.com/messenger/connect_your_way.html?ocid=TXT_TAGLM_WL_Refresh_messenger_video_072008 ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Compiling .drl files inside of a JUnit test
Mark Proctor wrote: You don't have your DRLs in the correct location, our DRLs mirror the path of the class that is loading them via getClass().getResourceAsStream(): http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/ It just does a loadClass on the classLoader, as long as your classes are in the classpath it will find them. So, when the compiler is compiling the rules file, it will inherit the classpath from Eclipse? Or it should? To me, the key is your phrase as long as your classes are in the classpath. As far as Eclipse is concerned they are, but what classpath is used by the compiler of the .drl file? There is an entire complex directory structure to the project and the unit tests are in one directory which is far removed from the source for the classes yet when other unit tests run, they see everything as expected, which my test class extending TestCase also sees, but not the compiler compiling the .drl file. Apologies for being so slow with this but I'm learning Java and Drools at the same time, not an ideal situation. Thanks for the help! Ron _ Use video conversation to talk face-to-face with Windows Live Messenger. http://www.windowslive.com/messenger/connect_your_way.html?ocid=TXT_TAGLM_WL_Refresh_messenger_video_072008 ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Compiling .drl files inside of a JUnit test
I'm sure other people have run into this. I'm trying to build a unit test that checks the compilation of an external .drl file. My questions are: How do I get the compiler to locate all the .class files that I reference? When JUnit runs, where does it run from or how can its runtime classpath be manipulated? Any help appreciated! Ron _ Keep your kids safer online with Windows Live Family Safety. http://www.windowslive.com/family_safety/overview.html?ocid=TXT_TAGLM_WL_family_safety_072008 ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
RE: [rules-users] How to check for a variable number of conditions ina rule?
Mike, I think the collect will work, I'll have to look at it more closely because the ordering of elements in the array is significant so I'm not sure I can just break the elements up into facts and let collect group them however it will. As a follow up, while my solution of using a global in the LHS works, is the problem with changing the global simply that the engine will not see the changes? For my case, the global is set before the rules engine is called and it will not change while the engine runs. Ron Mike wrote: Have a look at the Alarms example for Collect in the (4.0.5) manual. This should give you a good starting point. Cheers, Mike _ With Windows Live for mobile, your contacts travel with you. http://www.windowslive.com/mobile/overview.html?ocid=TXT_TAGLM_WL_mobile_072008 ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] How to check for a variable number of conditions in a rule?
Greetings! I want to create a rule that checks a fact which contains an array to see if n or more of the elements of that array have a specific value. The number of elements to check will vary from invocation to invocation of the rules engine and will likely be added as a global. I can do this by using a helper function. Say, for example, I have: rule fire_when_testFlags_true when eval(testFlags(flags, limit.intValue())); then System.out.println(Yup, + limit + or more flags are true!); end Where flags and limit are both globals. Then I can define testFlags as: function boolean testFlags(Flags flags, int threshold) { int count = 0; for(int i=0; i flags.getSize(); i++) { if (flags.getValue(i)) { count++; if (count= threshold) { return true; } } } return false; } This works but violates the warning not to use a global that isn't immutable in the LHS of a rule. Does anyone have an idea about how to implement a rule that in effect has an arbitrary number of conditions to be tested? Ron _ Keep your kids safer online with Windows Live Family Safety. http://www.windowslive.com/family_safety/overview.html?ocid=TXT_TAGLM_WL_family_safety_072008 ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
RE: [rules-users] Drools 4 poor performance scaling?
Eric- Mark has my test code and said he'll look at it in a few days. I'm sure he'll reply here but if not, I'll post it. My question for you is how quickly does fireAllRules() run for you? As I said, with only 95 facts loaded it is taking my machine (dual core 2 GHz box, Fedora Core 6) almost 5 seconds. Ron Subject: RE: [rules-users] Drools 4 poor performance scaling? Date: Mon, 30 Jun 2008 11:46:15 -0400 From: [EMAIL PROTECTED] To: rules-users@lists.jboss.org We are having a similar problem, although our fact count is much higher. Performance seems pretty good and consistent until about 400k facts, then performance degrades significantly. Part of the degradation is from bigger and more frequent GCs, but not all of it. Time to load first 100k facts: ~1 min Time to load next 100k facts: ~1 min Time to load next 100k facts: ~2 min Time to load next 100k facts: ~4 min This trend continues, going from 600k to 700k facts takes over 7 minutes. We're running 4.0.7 on a 4 CPU box with 12 GB, 64 bit RH Linux and 64 bit JRockit 5. We've allocated a 9 GB heap for the VM using large pages, so no memory paging is happening. JRockit is started w/ the -XXagressive parameter, which enables large pages and the more efficient hash function in HashMap which was introduced in Java5 update 8. http://e-docs.bea.com/jrockit/jrdocs/refman/optionXX.html The end state is over 700k facts, with the possibility of nearly 1M facts in production. After end state is reached and we issue a few GC requests, if looks like our memory per fact is almost 9k, which seems quite high as most of the facts are very simple. Could that be due to our liberal use of insertLogical and TMS? We've tried performing a commit every few hundred fact insertions by issuing a fireAllRules periodically, and that seems to have helped marginally. I tried disabling shadow proxies and a few of our ~390 test cases fail and one loops indefinitely. I'm pretty sure we could fix those, but don't want to bother if this isn't a realistic solution. Any thoughts? Thanks Eric -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ron Kneusel Sent: Thursday, June 26, 2008 12:47 PM To: rules-users@lists.jboss.org Subject: [rules-users] Drools 4 poor performance scaling? I am testing Drools 4 for our application and while sequential mode is very fast I get very poor scaling when I increase the number of facts for stateful or stateless sessions. I want to make sure I'm not doing something foolish before deciding on whether or not to use Drools because from what I am reading online it should be fast with the number of facts I have. The scenario: I have 1000 rules in a DRL file. They are all of the form: rule rule when Data(type == 0, value 0.185264); Data(type == 3, value 0.198202); then insert(new AlarmRaised(0)); warnings.setAlarm(0, true); end where the ranges checked on the values and the types are randomly generated. Then, I create a Stateful session and run in a loop timing how long it takes the engine to fire all rules as the number of inserted facts increases: // Run for(j=0; j 100; j+=5) { if (j==0) { nfacts = 1; } else { nfacts = j; } System.out.println(nfacts + :); // Get a working memory StatefulSession wm = ruleBase.newStatefulSession(); // Global - output warnings = new Alarm(); wm.setGlobal(warnings, warnings); // Add facts st = (new Date()).getTime(); for(i=0; i nfacts; i++) { wm.insert(new Data(rand.nextInt(4), rand.nextDouble()-0.5)); } en = (new Date()).getTime(); System.out.println(facts = + (en-st)); // Now run the rules st = (new Date()).getTime(); wm.fireAllRules(); en = (new Date()).getTime(); System.out.println(rules = + (en-st)); // Clean up wm.dispose(); System.out.println(\n); } This code is based on the HelloWorldExample.java code from the manual and the setup for the rule base is the same as in the manual. As the number of facts increases runtime increases dramatically: facts -- runtime (ms) 10 -- 168 20 -- 166 30 -- 344 40 -- 587 50 -- 1215 60 -- 1931 70 -- 2262 80 -- 3000 90 -- 4754 with a maximum memory use of about 428 MB RAM. By contrast, if I use sequential stateless sessions, everything runs in about 1-5 ms. Is there something in my set up that would cause this, or is this how one would expect Drools to scale? I read about people using thousands of facts so I suspect I'm
RE: [rules-users] Drools 4 poor performance scaling?
A small update. I ran the example below starting with 90 rules and running down to 1. The execution time remains the same so I don't think the problem has to do with something left over from the previous call to fireAllRules(). This really should be a simple example and I am still at a loss as to why it doesn't work quickly. Again, any help appreciated! Ron -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ron Kneusel Sent: Thursday, June 26, 2008 12:47 PM To: rules-users@lists.jboss.org Subject: [rules-users] Drools 4 poor performance scaling? I am testing Drools 4 for our application and while sequential mode is very fast I get very poor scaling when I increase the number of facts for stateful or stateless sessions. I want to make sure I'm not doing something foolish before deciding on whether or not to use Drools because from what I am reading online it should be fast with the number of facts I have. The scenario: I have 1000 rules in a DRL file. They are all of the form: rule rule when Data(type == 0, value 0.185264); Data(type == 3, value 0.198202); then insert(new AlarmRaised(0)); warnings.setAlarm(0, true); end where the ranges checked on the values and the types are randomly generated. Then, I create a Stateful session and run in a loop timing how long it takes the engine to fire all rules as the number of inserted facts increases: // Run for(j=0; j 100; j+=5) { if (j==0) { nfacts = 1; } else { nfacts = j; } System.out.println(nfacts + :); // Get a working memory StatefulSession wm = ruleBase.newStatefulSession(); // Global - output warnings = new Alarm(); wm.setGlobal(warnings, warnings); // Add facts st = (new Date()).getTime(); for(i=0; i nfacts; i++) { wm.insert(new Data(rand.nextInt(4), rand.nextDouble()-0.5)); } en = (new Date()).getTime(); System.out.println(facts = + (en-st)); // Now run the rules st = (new Date()).getTime(); wm.fireAllRules(); en = (new Date()).getTime(); System.out.println(rules = + (en-st)); // Clean up wm.dispose(); System.out.println(\n); } This code is based on the HelloWorldExample.java code from the manual and the setup for the rule base is the same as in the manual. As the number of facts increases runtime increases dramatically: facts -- runtime (ms) 10 -- 168 20 -- 166 30 -- 344 40 -- 587 50 -- 1215 60 -- 1931 70 -- 2262 80 -- 3000 90 -- 4754 with a maximum memory use of about 428 MB RAM. By contrast, if I use sequential stateless sessions, everything runs in about 1-5 ms. Is there something in my set up that would cause this, or is this how one would expect Drools to scale? I read about people using thousands of facts so I suspect I'm setting something up incorrectly. Any help appreciated! Ron _ Need to know now? Get instant answers with Windows Live Messenger. http://www.windowslive.com/messenger/connect_your_way.html?ocid=TXT_TAGLM_WL_Refresh_messenger_062008 ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Drools 4 poor performance scaling?
I am testing Drools 4 for our application and while sequential mode is very fast I get very poor scaling when I increase the number of facts for stateful or stateless sessions. I want to make sure I'm not doing something foolish before deciding on whether or not to use Drools because from what I am reading online it should be fast with the number of facts I have. The scenario: I have 1000 rules in a DRL file. They are all of the form: rule rule when Data(type == 0, value 0.185264); Data(type == 3, value 0.198202); then insert(new AlarmRaised(0)); warnings.setAlarm(0, true); end where the ranges checked on the values and the types are randomly generated. Then, I create a Stateful session and run in a loop timing how long it takes the engine to fire all rules as the number of inserted facts increases: // Run for(j=0; j 100; j+=5) { if (j==0) { nfacts = 1; } else { nfacts = j; } System.out.println(nfacts + :); // Get a working memory StatefulSession wm = ruleBase.newStatefulSession(); // Global - output warnings = new Alarm(); wm.setGlobal(warnings, warnings); // Add facts st = (new Date()).getTime(); for(i=0; i nfacts; i++) { wm.insert(new Data(rand.nextInt(4), rand.nextDouble()-0.5)); } en = (new Date()).getTime(); System.out.println(facts = + (en-st)); // Now run the rules st = (new Date()).getTime(); wm.fireAllRules(); en = (new Date()).getTime(); System.out.println(rules = + (en-st)); // Clean up wm.dispose(); System.out.println(\n); } This code is based on the HelloWorldExample.java code from the manual and the setup for the rule base is the same as in the manual. As the number of facts increases runtime increases dramatically: facts -- runtime (ms) 10 -- 168 20 -- 166 30 -- 344 40 -- 587 50 -- 1215 60 -- 1931 70 -- 2262 80 -- 3000 90 -- 4754 with a maximum memory use of about 428 MB RAM. By contrast, if I use sequential stateless sessions, everything runs in about 1-5 ms. Is there something in my set up that would cause this, or is this how one would expect Drools to scale? I read about people using thousands of facts so I suspect I'm setting something up incorrectly. Any help appreciated! Ron _ The other season of giving begins 6/24/08. Check out the i’m Talkathon. http://www.imtalkathon.com?source=TXT_EML_WLH_SeasonOfGiving ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
RE: [rules-users] Advice sought on choosing Stateful or Stateless sessions
Mark Proctor wrote: 1. Do stateless sessions execute faster than stateful? I'm assuming that even if they don't, they use memory more efficiently? no. not unless you set sequential mode, but even then it's only faster if you have a very large number of facts.Mark, thanks for the reply. What about memory use? I saw that with a stateful session when I added 500 facts I was easily using 1 GB of RAM before the entire thing crashed. I'm assuming that not tracking state will dramatically decrease memory use? standard statless sessions just wrap a stateful session, so you can't insert or modify from outside the engine but a rule can insert/modify. If you run in sequential mode you have no inference, insert/modify do not work.Ok, this clears things up. Standard stateless has an agenda, sequentail has no agenda the rules are fired in the order they are defined.It seems that sequential is what I want then since I don't see much dependence between rules in th! at one is necessarily more important than the others and I can fiddle with salience if one is.The fog is lifting, thanks!Ron _ Introducing Live Search cashback . It's search that pays you back! http://search.live.com/cashback/?pkw=form=MIJAAF/publ=HMTGL/crea=introsrchcashback ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Drools memory use issues
Greetings! I'm using Drools 4 and have a simple test setup with 4 rules. If I run with a few facts (simple objects that hold a type and a floating point value only) everything works as advertised. If I bump the number of facts up to 100 it runs most of the time without changing the defaults on the virtual machine. However, if I change the number of facts to 500 and change the virtual machine memory limits to 1024 MB the engine grinds to a halt and eventually dies with an out of memory error. What are the reasonable limits for Drools in terms of facts in the working memory and number of rules? I will try a test with hundreds of rules today but I was very surprised, and disappointed, to see that so few facts eat so much memory. The project my company needs Drools for will likely have to run the engine on a working memory with about 100..150 facts and do so every 1 to 2 seconds. Can Drools keep up? How can performance be improved? Thanks! Ron _ Introducing Live Search cashback . It's search that pays you back! http://search.live.com/cashback/?pkw=form=MIJAAF/publ=HMTGL/crea=introsrchcashback ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Advice sought on choosing Stateful or Stateless sessions
Greetings! I read through the manual, but it is a little too terse regarding when one might choose Stateless versus Stateful sessions. My initial testing has been with Stateful sessions and these work nicely but memory use explodes as the number of facts added increases much beyond 100. So, my questions: 1. Do stateless sessions execute faster than stateful? I'm assuming that even if they don't, they use memory more effciently? 2. I read that stateless sessions do not allow for facts to be modified yet I saw an example online which was using insert() in the DRL file. Will this work if there is a rule that has not already fired but might after the insert? In a stateless session will a rule only fire once and ignore new facts? (I believe so). 3. It also seems that a stateless session has no agenda and therefore will simply fire the first rule that matches so that salience must be used to prioritize rules. Is this correct? 3. The difference between a stateless session and a sequential stateless session is also unclear (to me) from the manual. Can someone explain it? What I am looking to build is essentially a filter, something that gets a bunch of input facts and applies the rules to see if any alarms should be raised based on the inputs. My test programs have been using a global which tracks the alarms raised. I just look at it after the engine has run and use it as my output. Each run of the rules engine is separate from the previous run, ie, there is no accumulation of knowledge, which is why I think a stateless session is the way to go but I'm not sure. Any help appreciated! Ron _ The i’m Talkathon starts 6/24/08. For now, give amongst yourselves. http://www.imtalkathon.com?source=TXT_EML_WLH_LearnMore_GiveAmongst ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Running Drools 4 examples
Greetings! I am attempting to run the HelloWorld example for Drools 4. I have Eclipse 3.3 setup on Windows with the Drools plugin. I have created a project with the Drools examples and added all the Drools .jar files to the project. Everything compiles. When I initially ran HelloWorldExample.java it appeared that it could not find the HelloWorld.drl file. So, I moved that file into the same directory as HelloWorldExample.java and ran again. This time I am getting an error that the JDT compiler is not found even though it appears that there are JDT jar files in the Eclipse plugins. I also attempted to run this example under Linux from the command line. In this case I placed all the Drools .jar files into the JRE ext folder and changed the source code to use the Janino compiler by adding: // Set up for the Janino compiler, not Eclipse System.setProperty(drools.dialect.java.compiler, JANINO); PackageBuilderConfiguration cfg = new PackageBuilderConfiguration(); JavaDialectConfiguration javaConf = (JavaDialectConfiguration)cfg.getDialectConfiguration(java); This version compiles with javac and runs with java -cp . HelloWorldExample but gives me an error within the compiler while compiling the .drl file: Exception in thread main java.lang.StringIndexOutOfBoundsException: String index out of range: -1 at java.lang.String.substring(String.java:1938) at org.drools.base.ClassTypeResolver.importClass(ClassTypeResolver.java:242) at org.drools.base.ClassTypeResolver.resolveType(ClassTypeResolver.java:158) at org.drools.rule.builder.dialect.mvel.MVELDialect.addImport(MVELDialect.java:257) at org.drools.compiler.DialectRegistry.addImport(DialectRegistry.java:98) at org.drools.compiler.PackageBuilder.mergePackage(PackageBuilder.java:377) at org.drools.compiler.PackageBuilder.newPackage(PackageBuilder.java:350) at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:267) at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:167) at HelloWorldExample.main(HelloWorldExample.java:39) It is dying on this line: builder.addPackageFromDrl( source ); My version of HelloWorldExample.java the same as the given example except for the addition of the lines above for Janino. My ultimate goal is to run this all under Linux, I am not an Eclipse user. Any help getting this working would be greatly appreciated! Ron _ Introducing Live Search cashback . It's search that pays you back! http://search.live.com/cashback/?pkw=form=MIJAAF/publ=HMTGL/crea=introsrchcashback ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users