5 Replies Latest reply on Jan 20, 2006 11:18 AM by manik

    Using JBossCache to implement a global working queue

    freter

      Hi,

      I wonder if I should rather use JBossCache or JGroups (or maybe something completely different) to implement a solution for the following problem:

      I my current project, we have a core server and a number of of so called optimization servers. Both types of servers are implemented using Spring and run on Tomcat each. The core server needs to send sends optimization requests to the optimization servers which in turn pick up their work pckage and start processing. (The business case is to achieve a maximum load factor on cargo trains). The problem is that some optimization requests may be executed in parallel, while others may not be executed in parallel. So we do need something like a global hashmap that stores a list of all optimization requests along with an information whether any of the optimization servers is working on this package.

      At first, I thought it might be a good idea to use JGroups and the DistributedHashmap, but then I read the JavaDoc deprecation comment "Use JBossCache instead" :-) So, which one should I use?

      Peter

        • 1. Re: Using JBossCache to implement a global working queue
          manik

          Simple rule of thumb - for sharing data across multiple nodes, use JBossCache. For broadcasting messages to servers, use JGroups. JGroups messages may be calls to remote methods, and may include data payloads. This is how JBossCache is implemented.

          Sounds to me what you need is a JMS message queue though!! :) You can achieve similar functionality with JBossCache + transactions though.

          • 2. Re: Using JBossCache to implement a global working queue
            freter

             

            "manik.surtani@jboss.com" wrote:
            Sounds to me what you need is a JMS message queue though!! :)

            Not sure. Imagine the following case:
            You have two connections. One of them goes from Hamburg to Verona, the oter one goes from Berlin to verona. The connections will be operated by three trains: T1 from Hamburg to Hannover, T2 from Berlin to Hannover, T3 from Hannover to Verona. In order to maximize the load factor, the optimization servers now have to answer requests like "can we accept 10 additional containers for the connection Hamburg to Verona?". Another request might be "can we accept another 5 containers from Berlin to Verona". These requests might arrive at the same time, but they cannot be processed in parallel, but must be serialized. You can only parallelize requests like "is there room for 5 containers from Hamburg to Hannover" and "is there room for 10 containers from Berlin to Hannover" - because they do not share a common leg.

            If we only had one optimization server, this wouldn't be much of a problem. So, a work package may only be removed from the working queue after it has been sucessfully optimized. I am not sure if one can achieve this with JMS.

            • 3. Re: Using JBossCache to implement a global working queue
              manik

              Ok, fair enough - makes more sense now. Yeah, JBossCache is probably your answer, not JGroups.

              • 4. Re: Using JBossCache to implement a global working queue
                freter

                 

                "manik.surtani@jboss.com" wrote:
                Ok, fair enough - makes more sense now. Yeah, JBossCache is probably your answer, not JGroups.


                Thanks for your answer, Manik.

                Something that struck me: is "Cache" the right term for what JBossCache does? It seems to me that it is more like a global transactional store for everything and nothing in particular...

                • 5. Re: Using JBossCache to implement a global working queue
                  manik

                  Yes, we do have that debate quite often! It did start as a pure cache, and kind of grew into a distributed, transactional object store. We're even going to be releasing a product that uses AOP to cluster objects and replicate transparent to user code. See

                  http://www.onjava.com/pub/a/onjava/2005/11/09/jboss-pojo-cache.html

                  Cheers,
                  Manik