Query about performance in using data as fact or using it as Global variable
by Nikhil S. Kulkarni
Hi ,
I am using drools 5.0 in application. I am facing performance issues. I am using drls, rule flows and rule templates.
My scenario is as follows :-
Consider there is list of 20 companies.
There are about 20000 members in each company.
Now I have several rules in which condition is for specific member and specific company.
e.g.
rule 1
when comp : company
and member : Members
then
.........
End;
So similarly I passed Member list and company list as fact. But it was time consuming process.
So I have done one change.
I kept only comp:company in when condition of rule as I explained above and declare member list as global .
I created a function in rule in which I am iterating over member list and doing the same process.
Now this is taking less time.
Now my question is how efficient is this change.
Though we say that when we write specific condition in rule then it will be fired only in that case.
But when I use Agenda Event Listener class,
I come to know one thing that it creates activation-created for all possible conditions then it will fire activation-Fired for specific condition
And after that it will cancel all the activations.
So as I reduced member level fact condition my time is reduced drastically and performance improved.
So anybody can suggest me that whether I am on right track of improving time and performance or not ?
Waiting for reply.
Thanks & Regards,
Nikhil S. Kulkarni
MASTEK LTD.
In the US, we're called MAJESCOMASTEK
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Opinions expressed in this e-mail are those of the individual and not that of Mastek Limited, unless specifically indicated to that effect. Mastek Limited does not accept any responsibility or liability for it. This e-mail and attachments (if any) transmitted with it are confidential and/or privileged and solely for the use of the intended person or entity to which it is addressed. Any review, re-transmission, dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. This e-mail and its attachments have been scanned for the presence of computer viruses. It is the responsibility of the recipient to run the virus check on e-mails and attachments before opening them. If you have received this e-mail in error, kindly delete this e-mail from desktop and server.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14 years, 2 months
Exception Handling in the rule consequence
by sumatheja
Hi All,
I have a set of rules. After firing the rules if an exception occurs
in a rule the following rules are not getting evaluated. So i tried writing
a try catch block inside the consequence part of the rule, but then i get an
error saying "'unable to build the consequence.[Error:was expecting type:
java.lang.Object but found type:null]"
Here follows my code
*rule 'Test rule'
ruleflow-group "Test Ruleflow"
no-loop
when
$c:Car()
Driver()
then
try{
$c.getModel()
} catch (Exception Ee) {
System.out.println("caught an exception: "+Ee.toString());
}
end*
However if i remove the try catch block it buils fine.
Can anyone let me know if i'm missing something here.
Thanks in advance :)
--
cheers
Sumatheja
14 years, 2 months
xdrl, null and nested properties
by Veit Guna
Hi.
I'm using Drools 5.1.0 along with .xdrl files. Now I have the problem
with the following sippet:
--cut here--
<dro:and-conditional-element>
<dro:pattern object-type="TaskResults">
<dro:field-constraint field-name="lastResult">
<dro:literal-restriction evaluator="!=" value="null"/>
</dro:field-constraint>
<dro:field-constraint
field-name="lastResult.returnValues["ReturnKey"]">
<dro:literal-restriction evaluator="==" value="returnvalue"/>
</dro:field-constraint>
</dro:pattern>
</dro:and-conditional-element>
--cut here--
It compiles just fine, but when executed it fails with:
Caused by: org.drools.RuntimeDroolsException: Exception executing
predicate lastResult.returnValues["ReturnKey"] == "returnvalue"
Caused by: [Error: unable to access property (null parent): returnValues]
[Near : {... Unknown ....}]
^
[Line: 1, Column: 0]
at
org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:886)
It seems that the second field constraint is also evaluated, although
the first should already return "false". Are there no short-circuits
within pattern constraints? How would I express that best in xdrl
conform manner? Use eval?
Thanks
Veit
14 years, 2 months
Re: [rules-users] Check if fact is subset of items in the rule
by Michael Anstis
Thanks, please provide a specific example rule too.
Don't forget to keep your posts to the mailing list for the good of the
community.
On 12 October 2010 22:18, Kumar Pandey <kumar.pandey(a)gmail.com> wrote:
> Michale
> Thanks for the response.
> Here's the link for the thread .
>
>
> http://drools-java-rules-engine.46999.n3.nabble.com/Check-if-fact-is-subs...
>
> and the original about matching strings in two arrays.
>
> http://drools-java-rules-engine.46999.n3.nabble.com/Matching-strings-in-t...
>
>
> My use case is that I could have hundreds of rule and each rule could have
> its own set of strings.
> A fact object is run through these rules to see which ones are fired.
> One of the condition to check is that the a list in the fact is not a
> subset of list in the rule.
> That is fire the rule only if list in fact is not a subset of list in rule.
>
> Thanks
> Kumar
>
>
> On Tue, Oct 12, 2010 at 12:38 PM, Michael Anstis <michael.anstis(a)gmail.com
> > wrote:
>
>> OK, I admit I don't have the original thread anymore.
>>
>> If I am not wrong (which is always a possibility) for Wolfgang's operator
>> to work you'd need to externalise the superset from the rule into
>> WorkingMemory. You could have a rule with higher salience construct the
>> superset WM fact.
>>
>> If you don't mind re-posting or providing a link to the complete thread
>> (on Nabble or somewhere) I'll happily try to help further.
>>
>> On 12 October 2010 17:23, <kumar.pandey(a)gmail.com> wrote:
>>
>>> <quote author='Michael Anstis-2'>
>>>
>>> Wolfgang gave a great solution.
>>> </quote>
>>> Don't know if I'm missing something obvious here. I have a superset in
>>> the rule itself. Each rule has a superset list. In this case how would I use
>>> Wolfgang's solution. Its comparing through two arrays in runtime. I have not
>>> been able to construct an array construct with specific values in the rule
>>> itself.
>>>
>>
>>
>
>
14 years, 2 months
How to Capture the rule which does not get executed
by Navdeep Kumar
Hi All,
I am new to Drools. I am working on a project where nature of rules are
dynamic. I want to capture that rule which does not get executed. i need to
store that rule because i have to display that rule in the UI.
Here is my rule file
rule "FrontAxle:Capacity|FrontSuspension:Capacity"
when
b:Feature(featureClass.name=="FrontSuspension")
c:Feature(featureClass.name=="FrontAxle")
//eval(b.getCapacity() >= c.getCapacity())
then
System.out.println("These are compatible");
System.out.println(b.getFeatureClass().getName());
availablity.put(b.getFeatureClass().getName()+"-"+c.getFeatureClass().getName(),"12.35");
//availablity.put(b.getName()+"-"+c.getName(),new Double(b.getCapacity()));
insert(availablity);
end
rule "FrontSuspension:Type|FrontAxle:Type"
when
b:Feature(featureClass.name=="FrontSuspension")
c:Feature(featureClass.name=="FrontAxle")
not Feature(b.attributes.Type=="I Beam" && c.attributes.Type=="Multi Link
Air")
//NOT (FrontAxle.type = "I-Beam" AND FrontSuspension.type = "Multi-link
Air") - mounting restriction
then
System.out.println("I am in 2");
end
rule "FrontAxle:FeatureCode|FrontSuspension:Type"
when
b:Feature(featureClass.name=="FrontSuspension")
Feature(featureClass.name=="FrontAxle" && code=="002ASW")and not
Feature(b.attributes.Type=="Multi Link Air" || b.attributes.Type=="Monoleaf
Spring")
//FrontAxle.featureCode = "002ASW" AND NOT (FrontSuspension.type =
"Multi-link Air" OR FrontSuspension.type = "Monoleaf Spring")
then
System.out.println("I am in 3");
end
now if these two objects named FrontAxle and FrontSuspension are compatible
then it has to meet all the 3 rules, but if any combination of these objects
does not meet one of the rule listed above then i have to store the rule for
the displaying purpose that this combination didn't meet this rule thats why
they are not compatible. any kind of help will be appreciated.
Thanks.
14 years, 2 months
re-fire all rules
by Yaniv Itzhaki
Hi there,
Is there a way to "reset" the working memory so that all the rules will
run again when fireAllRules() is called? (I am running the startProcess
method number of times with the same working memory)
I know that normally rules will only be run again when there was a change
and the fact was updated. but in my case I like to run all rules again
in some situations without having a change on the facts.
so is there a way to do this?
Thanks
Yaniv
14 years, 2 months
Question about drools server
by Xinhua Zhu
Hi
I am a new guy on drools server. I am trying to exposed drools rules in web
services.
I downloaded Drools Guvnor Standalone from website, it includes Jboss, then
I put drools server war file in deploy folder, and start the Jboss.
When I input "http://localhost:8080/drools-5.1.1-server/" in browser, it
works well. the result is "Execution server is running".
When I input "http://localhost:8080/drools-5.1.1-server/test.jsp", the
expected result should be "echo: Hello world", but the actual result is:
Sending Message: "Hello World"
Response: "org.apache.cxf.jaxrs.impl.ResponseImpl@6231ed"
What is wrong with it? How to solve it? Thanks very much!
BR
Xinhua
14 years, 2 months
ksession.dispose() and DroolsSpringJpaManager.dispose()
by drooRam
I have question on kession.dispose(), what is the best place to call this
method?
I have a code where in i call
ksession.startProcess("someprocess", mapParam);
ksession.fireAllRules();
....
finally{
ksession.dispose();
}
If i invoke the kession.dispose() like the above, I always ended up in "No
value bound to the key" - Transaction exception.
My understanding is that all the calls to drools should be enclosed in a
transactional unit. I have done that so.
My observation is that DroolsSpringJpaManager.dispose() method is being
invoked due to my call to ksession.dispose() after the transaction has begun
from my app code and right before the transaction.aftercompletioncommit()
call.
I can see a line of code in DroolsJpaManager.dispose() method,
TransactionSynchronizationManager.unbindResource(this.emf) //
entityManagerFactory reference borrowed from application code.
My question is that why the above line of code is necessary in dispose()
method since this.emf is the reference obtained from Application code jpa
manager, since this method unbinded this resource, transaction initiated
from the application code is also trying to unbind the same resource once
everything is completed results to "No value found for this key exception".
When i comment out ksession.dispose() call from my app code, it works fine.
At this point, i am not sure when to invoke ksession.dispose() call and why
the TransactionSynchronizationManager.unbindResource(this.emf) being made
in DroolsSpringJpaManager.dispose() on a reference obtained from
JpaTransactionManager ?
-drooRam
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/ksession-dispose-and-...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 2 months
DRL Functions
by Swindells, Thomas
I've just been writing what should be a really simple function in my DRL.
What I wanted to do is to take an object in, construct another object from it and then insert both into working memory.
Eg.
function void insertBoth(Object1 object1) {
insert(new Object2(object1));
insert(object 1);
}
Rule XYZ
When
Then
insertBoth(new Object1());
End
This didn't work as expected however as it couldn't find the method insert.
I then thought, ah maybe I need to use the kcontext global to access them
function void insertBoth(Object1 object1) {
kcontext.insert(new Object2(object1));
kcontext.insert(object 1);
}
Rule XYZ
When
Then
insertBoth(new Object1());
End
This doesn't work either so what I've had to do is:
function void insertBoth(KnowledgeContext kcontext, Object1 object1) {
kcontext.getKnowledgeRuntime().insert(new Object2(object1));
kcontext.getKnowledgeRuntime().insert(object 1);
}
Rule XYZ
When
Then
insertBoth(kcontext, new Object1());
End
This is suddenly a lot more complicated than it needs to be. Why can't functions have the same access to the standard operations (insert, update, retract etc) and globals as rule actions currently do?
Should I raise an issue for this or am I missing something?
Thomas
________________________________
**************************************************************************************
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmaster(a)nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary.
NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00
**************************************************************************************
14 years, 2 months