7 Replies Latest reply on Jan 9, 2012 9:36 AM by dstanic

    Session Management - only one inside application or one by processs

    gardellajp

      Hi,

       

      I have some questions about how manage sessions. I read official doc and says:

       

      Chapter 4. Core Engine: API

       

      Sessions can be created based on a knowledge base and are used to execute processes and interact with the engine.  You can create as many independent session as you need and creating a session is considered relatively lightweight.  How many sessions you create is up to you.  In general, most simple cases start out with creating one session that is then called from various places in your application.  You could decide to create multiple sessions if for example you want to have multiple independent processing units (for example, if you want all processes from one customer to be completely independent from processes for another customer, you could create an independent session for each customer) or if you need multiple sessions for scalability reasons.  If you don't know what to do, simply start by having one knowledge base that contains all your process definitions and one create session that you then use to execute all your processes.

       

      After read it, I want decide how manage session, so.

       

      1) Create one session inside application and never dispose it.

      2) Create a session per process. So when I start a process, I save somewhere the information about which sessionId must use for a processId.

       

      I like option two, with persistent sessions. So when I start a process, I do:

       

       start>>
              StatefulKnowledgeSession ksession = newSession();      
      
              // start a new process instance
              ProcessInstance instance = ksession.startProcess(id, params);      
              
              ProcessIntanceInfo(instance.getId(), ksession.getId());
              
              ksession.dispose();
      
              return p;
      

       

      So in my application I save p. When I must interact with p, I load the session associate with p.getProcessId(). Cool, I have a session persistent per process.

       

      But when I go deep in implementation, I found some problems, for example related events. I want listen when a task is complete so I attach some listener to the session when I load/start it. But after work with the session I dispose it, so the listener don't work. I think the solution is this:

       

       

      long processId = p.getProcessId();
      int sessionId =  p.getSessionId();
      StatefulKnowledgeSession s = loadSession(sessionId);
      attachListeners(s);
      
      TaskClient t = ....;
      
      t.complete( taskId, serId, outputData, responseHandler );
      
      responseHandler.waitTillDone(5000);
      
      s.dispose();
      
      

       

      Now, the questions:

       

      1) With this code, is safe except that the listener will listen the event of complete task?

      2) Is this a good way to manage sessions? I don't find a good tutorial or document of differents strategies for handle sessions.

       

      Thanks for your time,

      Juan

        • 1. Re: Session Management - only one inside application or one by processs
          gardellajp

          Any?

          • 2. Re: Session Management - only one inside application or one by processs
            salaboy21

            I'm writing a chapter of the jBPM5 Dev Guide about that exactly, because there is no good document about it.

            The other option is to use one session to execute a set of correlated processes that can be kept together. It really depends on your business scenario. I will do my best to get the book ready and published asap.

            1 of 1 people found this helpful
            • 3. Re: Session Management - only one inside application or one by processs
              dstanic

              Hello, is there any progress on this?

               

              Do you have any advice if we use the ESB and one central service which serves as a controller

              that manages all the requests from clients and handle process creation, signaling events, etc.

               

              How to handle session in that case?

               

              Thanks

              • 4. Re: Session Management - only one inside application or one by processs
                salaboy21

                It depends on what do you want to do with the session. So it's up to the one that is defining the architecture to decide if to use one or more sessions. It depends on the data and what you want to do. You mention that you are in an ESB, but what kind of data do you want to handle, what kind of processes and rules do you want to run, for do exactly what? these questions needs to be answered in order to decide.

                Cheers

                • 5. Re: Session Management - only one inside application or one by processs
                  dstanic

                  We are aware that this is an architectural decision, but we are also curious are there any cases from practice, or experienced advice so we do not need to learn from our mistakes .

                   

                  For example if we want to create case management system and most of the processes will be a human oriented (long running processes).  Processes will receive all data form intake forms like case info, users, notice etc.  Large part of received data will end up in database trough domain-specific service nodes. Architectural decision is that all requests go through ESB, and that one ESB service will handle all interaction with process engine.

                   

                  Now we are in doubt how to realize ESB service, should we create one session (StatefulKnowledgeSession) per process instance, or we can create one session for each end user and store somewhere session info. , or we can create one session for all.

                   

                  In the case of short running processes (integration-oriented), I would probably choose one session for all requests.

                  • 6. Re: Session Management - only one inside application or one by processs
                    gardellajp

                    Hi,

                     

                    With jBPM 5.x, I couldn't found information about about use in production enviroment (real life) and best practices. Decisions about use, for example create a new session per process instances, or use some session for multiple process instances, impact in two ways (there are lots I suppose, I'm not an expert in drools and jBPM).

                     

                    1) How you write rules:

                     

                        In the rules you must write carefully when you create multiple process with some session, becouse you can write a rule thinking that impact in one process instances, and in reallity impact in more than one

                      

                    2) Performance

                     

                       In don't have time to do stress test to verify how impact use one session per instances. In this way, you have multiple small sessions, but you access more times to database than use one session in memory.

                     

                    I except some more experience user of jBPM write best contribuition to the community. This things are very important. But, as opposite, is a free product, so if you pay support you will have answer your questions.

                     

                    Juan

                     

                    PD: Sorry my english

                    • 7. Re: Session Management - only one inside application or one by processs
                      dstanic

                      Hi Juan,

                       

                      Thanks for the reply!