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));