[rules-users] Is there a faster way of doing this in Drools ?

soumya_sd soumya_sd at yahoo.com
Wed May 9 13:36:15 EDT 2012


Vincent Legendre wrote
> 
>> At this point I'm designing for the worst case i.e., I'm assuming the
>> rules
>> with change with every request. 
> 
> Keeping a cache will work for the worst case, but will work faster for
> "normal" (see below) cases.
>  

I don't see how can a cache would work in the worse case. I mean if the rule
is not there in the cache then I've to figure out a way to load it. So in
the worse case, you will "always" have a cache miss. Is this not correct ? 


Vincent Legendre wrote
> 
> 
>> You can imagine the user changing these rules in a span of less than a
>> minute. 
> 
> Well, no ... it is really hard to imagine that kind of frequence as a
> normal use over a long time.
> For all systems I made, rules are stable for much more than that. When
> changing rules, you may change them every minutes (to test the outcomes,
> just like debuging a java code), but the objective is to produce something
> stable that will be used in a production environment ...
> Changing rules every minutes or less in a production environment is
> definitely not a usual use-case ...
> Why your rules should change every minute ? What is the system your are
> building ? 
>  

I just gave you an example of the type of use case I want to implement -
realtime filtering of data. In this case, the data is product data and the
rules are filtering rules that the user has defined. Imagine if you want to
implement a website where the user can control the products filters. Again,
with all due respect, if you haven't seen a use case doesn't mean it doesn't
exist or is not relevant in other situations. I'm building an experimental
prototype, so for now if you can just assume that such a use case exists I
would appreciate that. 


Vincent Legendre wrote
> 
> 
>> I understand that Drools is designed for cases when rules changes often.
>> But
>> can it support something like the one I described above where rules are
>> changing at a much faster rate? 
> 
> You won't be able to speed up the compile time.
> You can only act on the volume and organization of what you are compiling.
> So, you can use cache (as said before), and may be you can also cut your
> rules in smaller packages and only recompile the package where some
> modifications take place (if it take really some mesureable time, it is
> likely also because you have plenty of rules to compile).
> If you have a single package with few rules, compile time should not be a
> problem..
> 

For now, I cannot imagine these rules to very complex. And I think I can
limit them to a single package and a few rules (less than 10.) 


Vincent Legendre wrote
> 
> 
> And a last thing : In your first post, you said :
>>Based on the timing logs the code take majority (more than 80%) of time in
>>only these two operations. Is there a way to make it faster ?
>>
>>KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();  
>>kbuilder.add(
org.drools.io.ResourceFactory.newByteArrayResource(getRule()),
>>ResourceType.DRL);
> 
> You first have to make the distinction between KnowledgeBuilder
> compilation time (up to drools code, and you can't change anything, at
> least easyly), 
> and your getRule() method (guess one of your custom code), with may be
> speeded up.
> For instance, if you can't globally cut your compiled rules into smaller
> compiled packages, may be you can cut your big resulting DRL in smaller
> pieces, regenerating only what have changed ...
>  

My getRule() just reads a drl file and returns it as a byte[]. Currently
it's taking around 0ms. So I don't think this is a bottleneck. 





--
View this message in context: http://drools.46999.n3.nabble.com/Is-there-a-faster-way-of-doing-this-in-Drools-tp3973888p3974807.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list