[rules-users] Pooling stateful sessions to have threaded executions of a ruleset

Maxime Falaize maxime.falaize at gmail.com
Wed Apr 9 05:20:08 EDT 2014


I confirm that the multithreaded rules evaluation is not currently
supported. See
https://github.com/droolsjbpm/drools/blob/master/drools-core/src/main/java/org/drools/core/RuleBaseConfiguration.java#L683


2014-04-07 12:27 GMT+02:00 Maxime Falaize <maxime.falaize at gmail.com>:

> I'm sorry but I don't understand what you are talking about. In this
> article, there is nothing about multithreaded rules evaluation. It just
> says that the Phreak algorithm is designed for thread safety and *future*multicore processors exploitation. It doesn't mean that it is already
> multithreaded. Moreover I tested my appliciation with and without
> multithreaded sessions (I am using Drools 6.0.1.Final) and I noted a faster
> execution in the multithreaded one.
>
>
> 2014-04-04 13:53 GMT+02:00 jmercier <jmercier at genoscope.cns.fr>:
>
> Le 04/03/2014 09:55, Maxime Falaize a écrit :
>> > Hello,
>> >
>> > I want to ask you if it is a good practive to pool stateful sessions
>> > for a specific ruleset to improve the execution performance.
>> > Actually in my application I execute my rules by calling SOAP
>> > webservice. For performance purpose, I test multithreaded calls to my
>> > webservice and I noted that when I pool sessions in the server side,
>> > it improves the performance a lot.
>> >
>> > To pool sessions, I just declare multiple ksession tag in my
>> > kmodule.xml :
>> >
>> > <kbase name="KBase" packages="com.example.*">
>> >         <ksession name="KSession1"/>
>> >          <ksession name="KSession2"/>
>> >         <ksession name="KSession3"/>
>> >         <ksession name="KSession4"/>
>> >         <ksession name="KSession5"/>
>> >  </kbase>
>> >
>> > In my spring webservice endpoint I just put that code to handle the
>> > pool :
>> >
>> > @Endpoint
>> > public class ExampleEndpoint implements InitializingBean {
>> >
>> >     @Autowired
>> >     private ExampleRuleService ruleService;
>> >      private Map<Integer, Boolean> isRunningMap = new
>> > HashMap<Integer, Boolean>();
>> >     private static final int NB_POOL_SESSIONS = 5;
>> >
>> >     @PayloadRoot(localPart = "com.example.ExampleRequest")
>> >      @ResponsePayload
>> >     public ExampleResponse handleRequest(
>> >             @RequestPayload ExampleRequest request) throws
>> > InterruptedException {
>> >         KieServices ks = KieServices.Factory.get();
>> >         KieContainer kc = ks.getKieClasspathContainer();
>> >          while (true) {
>> >             for (int i = 0; i < NB_POOL_SESSIONS; i++) {
>> >                 boolean run = false;
>> >
>> >                 synchronized (isRunningMap) {
>> >                     if (!isRunningMap.get(i)) {
>> >                          isRunningMap.put(i, true);
>> >                         run = true;
>> >                     }
>> >                 }
>> >
>> >                 if (run) {
>> >                     KieSession ksession = kc.newKieSession("KSession"
>> > + (i + 1));
>> >                      ExampleResponse response =
>> > ruleService.run(ksession, request);
>> >                     ksession.dispose();
>> >
>> >                     isRunningMap.put(i, false);
>> >                     return response;
>> >                  }
>> >             }
>> >             Thread.sleep(100);
>> >         }
>> >     }
>> >
>> >     public void afterPropertiesSet() throws Exception {
>> >         for (int i = 1; i <= NB_POOL_SESSIONS; i++) {
>> >             isRunningMap.put((i - 1), false);
>> >          }
>> >     }
>> >
>> > }
>> >
>> > It works well because in my benchmark I improve 5 times the
>> > performance (as I have 5 different threads) but I wondered if it is a
>> > good practice and if it does not hide any issues that I could have in
>> > the future.
>> >
>> > Thanks for your help.
>> >
>> > --
>> > Maxime FALAIZE
>> > _______________________________________________
>> > rules-users mailing list
>> > rules-users at lists.jboss.org
>> > https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>> Hi maxime,
>>
>> I do not remember if use drools 6 or drools 5. If you using drools 6.
>> Phreaks algorithm use multi threading according to use 'from
>> accummulate' far i understand here:
>>
>> http://planet.jboss.org/post/drools_6_performance_with_the_phreak_algorithm
>>
>> Instead to put a thread by ksession here rules evaluation are
>> multi-threaded.
>>
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
>
> --
> Maxime FALAIZE
>



-- 
Maxime FALAIZE
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20140409/6167f041/attachment.html 


More information about the rules-users mailing list