3 Replies Latest reply: May 14, 2012 2:44 AM by Maciej Swiderski RSS

Questions about knowledge session and memory resource issues

pmukundan Newbie

Hi All,

 

Let me first describe the way I am trying to use JBPM.

 

Usage Scenario

I have a UI running on an application server. JBPM is deployed on top of a Tomcat in a separate JVM. At the startup of the tomcat knowledge base is loaded, knowledge session is created and kept ready for the UI to call. The UI responds to user inputs and decides to launch a process in JBPM. The UI calls the JBPM through a web service and process instance gets started. The processes contain human tasks and may run for days( those lazy humans !!). The number of process instances could become high( may be thousands). All process instances info, task info everything is required to be persisted to database.

 

Perceived Problem:

As the number of launched process instances go on increasing, the JBPM JVM shall run out of memory. The solution does not scale.

 

Approaches for problem resolution

There are two ways of handling this

 

a. Create only one session within the JBPM instance and let all process instance launches happen within this session. If JVM starts running out of memory, add more memory, more CPU firepower.

 

b. For each process start request, create a new sesson and load/unload the session as and when required. Live within whatever memory/CPU you have.

 

I am evaluating the two appraoches.

 

Questions

1. Does JBPM keep all process instance information in memory at all times ?

2. Does JBPM keep all the knowledge base in memory at all times ?

3. For approach b to work, the internal handling of JBPM should enable me to load/unload session at will. Does that work well? any firsthand experience ?

4. For approach b, if session dispose is called, do all process instances associated with that session go dormant ? In other words, if a session dispose is executed, are the process instances started by that session still in memory ?

5. My JVM crashes or needs to be restarted. Would all process instance information be loaded into memory automatically or would that be done programatically ?

 

 

If these have been answered anywhere else, please do point me to that location.

  • 1. Re: Questions about knowledge session and memory resource issues
    Maciej Swiderski Master

    pmukundan wrote:

     

    Questions

    1. Does JBPM keep all process instance information in memory at all times ?

    Process instance is kept in session (working memory) one when it is active, meaning under execution. Once done with the processing it is persisted into db.

     

    pmukundan wrote:

     

    Questions

    2. Does JBPM keep all the knowledge base in memory at all times ?

    Yes, knowledge base is kept there all the time to secure all sessions will have access to all artifacts stored in it.

     

    pmukundan wrote:

     

    3. For approach b to work, the internal handling of JBPM should enable me to load/unload session at will. Does that work well? any firsthand experience ?

     

    As far as I can tell it works well. If you keep session small you should get quite good performance.

     

     

    pmukundan wrote:


    4. For approach b, if session dispose is called, do all process instances associated with that session go dormant ? In other words, if a session dispose is executed, are the process instances started by that session still in memory ?

    Once the process instance execution is completed (by completed I mean that it reached a safe point like human task or catch events that makes process be in a sort of wait state) it is persisted into db and will now longer be active/managed object. It still resides in memory as object but it is disconnected from the session so it is safe to dispose the session.

     

     

    pmukundan wrote:

     

    5. My JVM crashes or needs to be restarted. Would all process instance information be loaded into memory automatically or would that be done programatically ?

    No, they won't be, as mentioned earlier process instances are persisted in db and retrieved only when requested. Just make sure you load knowledge base and session on startup and register all work item handlers that are required.

     

    NOTE: all my comments assume session persistence is used.

     

    HTH

  • 2. Re: Questions about knowledge session and memory resource issues
    pmukundan Newbie

    Hi Maciej,

     

    Thank you for your replay. It is very helpful. I have 1/2 followup question

     

    Assumption : Session persistance is in use. JPA/hibenate mechanism is in use. The setup is functioning.

     

    Scenario

    Whenever JBPM JVM gets a process launch request, I create a new Knowledge session. Use that ksession to lauch the process instance. The process instance hits a human task node and original launcher execution thread returns. That thread calls  ksession dispose. Now ksession is detached from process instance and task instance objects. All process instance objects get saved into database through JPA.

     

    Questions :       

                             Does the ksession object get garbage collected immediately ?

                             Do the persisted task objects/process instance objects get garbage collected ? Those are not required in memory until the user does something about the task in a separate JVM.

     

     

    Background info

    I am trying to forecast the memory requirements for the JVM.

    Memory contents of JVM at any time

         1. Whole knowledge base

         2. Active knowledge sessions( those not desposed at the moment)

         3. Process instance and related objects ( This is what I want to get clarty on !!)

  • 3. Re: Questions about knowledge session and memory resource issues
    Maciej Swiderski Master

    pmukundan wrote:

    Questions :       

                             Does the ksession object get garbage collected immediately ?

                             Do the persisted task objects/process instance objects get garbage collected ? Those are not required in memory until the user does something about the task in a separate JVM.

    As soon as you dispose the session it will be eligible to garbage collection, so I would say yes (with respect to the best practices for garbage collection). Same apply to process and task instances, they will be cleaned up as soon as there are no reference to them and since session is disposed that should be valid.

     

    HTH