5 Replies Latest reply on Aug 26, 2011 12:28 PM by sannegrinovero

    Configuring and using TransactionManager in Infinispan 4.2.1FINAL

    renzos

      Hi guys, I'm experiencing problems with TransactionManager in my app. I would like to use JBossStandaloneJTAManager and I followed the directions of the user guide (https://docs.jboss.org/author/display/ISPN/Infinispan+transactions), but I can't find out how to make it works. Everytime I get this message:

       

      [CUT]

       

      [main] DEBUG org.infinispan.factories.ComponentRegistry  - Looking in configuration for an instance of interface javax.transaction.TransactionManager that may have been injected from an external source.

      482  [main] DEBUG org.infinispan.transaction.lookup.GenericTransactionManagerLookup  - Trying to lookup TransactionManager for JBoss, JRun4

      483  [main] DEBUG org.infinispan.transaction.lookup.GenericTransactionManagerLookup  - Failed to perform a lookup for [java:/TransactionManager (JBoss, JRun4)]

      483  [main] DEBUG org.infinispan.transaction.lookup.GenericTransactionManagerLookup  - Trying to lookup TransactionManager for Resin 3.x

      483  [main] DEBUG org.infinispan.transaction.lookup.GenericTransactionManagerLookup  - Failed to perform a lookup for [java:comp/TransactionManager (Resin 3.x)]

      483  [main] DEBUG org.infinispan.transaction.lookup.GenericTransactionManagerLookup  - Trying to lookup TransactionManager for Sun Glassfish

      483  [main] DEBUG org.infinispan.transaction.lookup.GenericTransactionManagerLookup  - Failed to perform a lookup for [java:appserver/TransactionManager (Sun Glassfish)]

      483  [main] DEBUG org.infinispan.transaction.lookup.GenericTransactionManagerLookup  - Trying to lookup TransactionManager for Borland, Sun

      483  [main] DEBUG org.infinispan.transaction.lookup.GenericTransactionManagerLookup  - Failed to perform a lookup for [java:pm/TransactionManager (Borland, Sun)]

      483  [main] DEBUG org.infinispan.transaction.lookup.GenericTransactionManagerLookup  - Trying to lookup TransactionManager for BEA WebLogic

      483  [main] DEBUG org.infinispan.transaction.lookup.GenericTransactionManagerLookup  - Failed to perform a lookup for [javax.transaction.TransactionManager (BEA WebLogic)]

      483  [main] DEBUG org.infinispan.transaction.lookup.GenericTransactionManagerLookup  - Trying to lookup TransactionManager for Resin, Orion, JOnAS (JOTM)

      484  [main] DEBUG org.infinispan.transaction.lookup.GenericTransactionManagerLookup  - Failed to perform a lookup for [java:comp/UserTransaction (Resin, Orion, JOnAS (JOTM))]

      484  [main] DEBUG org.infinispan.transaction.lookup.GenericTransactionManagerLookup  - Trying WebSphere 5.1: com.ibm.ws.Transaction.TransactionManagerFactory

      484  [main] DEBUG org.infinispan.transaction.lookup.GenericTransactionManagerLookup  - Trying WebSphere 5.0: com.ibm.ejs.jts.jta.TransactionManagerFactory

      484  [main] DEBUG org.infinispan.transaction.lookup.GenericTransactionManagerLookup  - Trying WebSphere 4: com.ibm.ejs.jts.jta.JTSXA

      484  [main] DEBUG org.infinispan.transaction.lookup.GenericTransactionManagerLookup  - Couldn't find any WebSphere TransactionManager factory class, neither for WebSphere version 5.1 nor 5.0 nor 4

      487  [main] DEBUG org.infinispan.transaction.tm.DummyTransactionManager  - Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial

      487  [main] WARN  org.infinispan.transaction.lookup.GenericTransactionManagerLookup  - Falling back to DummyTransactionManager from Infinispan

       

      [CUT]

       

      This is my XML config file, thanks for your help:

       

      <?xml version="1.0" encoding="UTF-8"?>

      <infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

          xmlns="urn:infinispan:config:4.0">

         

          <global>

              <globalJmxStatistics enabled="true" jmxDomain="infinispan" allowDuplicateDomains="true"/>

              <transport clusterName="infinispan-cluster" />

              <serialization marshallerClass="org.infinispan.marshall.VersionAwareMarshaller" version="1.0"/>

          </global>

         

          <default>

              <locking

                 isolationLevel="REPEATABLE_READ"

                 lockAcquisitionTimeout="20000"

                 writeSkewCheck="false"

                 concurrencyLevel="500"

                 useLockStriping="true" />

              <clustering mode="replication">

                  <sync replTimeout="20000" />

                  <!--Uncomment this for async replication.-->

                  <!--<async useReplQueue="true" replQueueInterval="10000" replQueueMaxElements="500"/>-->

              </clustering>

              <transaction

                  transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"

                  syncRollbackPhase="false"

                  syncCommitPhase="false"

                  useEagerLocking="false"/>

                  <deadlockDetection enabled="true" spinDuration="1000"/>

                 

          </default>

         

      </infinispan>

        • 1. Re: Configuring and using TransactionManager in Infinispan 4.2.1FINAL
          sannegrinovero

          Hi Renzo,

          what kind of application is this? Are you deploying it in an application server (meaning you want to lookup the TransactionManager), or do you want to start a standalone TransactionManager?

          • 2. Re: Configuring and using TransactionManager in Infinispan 4.2.1FINAL
            renzos

            Hi Sanne, thanks for your answer. I think I need a standalone TransactionManager, the app I'm writing is for my thesis and it's a sort of benchmark/stress test I would like to run on many nodes at the same time, each node should do the following steps:

             

            1. After creating the Cache it populates 100 cache entries with random values only if it's the first node of the cluster (to avoid null entries)

            2. Then it loads some parameters from an XML file (for example the number k of threads I would like to start ...etc)

            3. Then it starts k threads and in each one there are some cache gets or puts (randomly) with random generated value in case of put.

            4. Each thread goes ahead in this way indipendently, and depending on the parameter n read in the XML file, after n operations (gets/puts) the thread stops itself for a while doing cache operations and starts again with gets/puts. This behaviour forever.

             

            So I need TransactionManager in order to put each cache.get and cache.put operations in a transaction (tm.begin() and tm.commit()).

             

            Here my code:

             

            public class Node {

                private String PATH="HERE THE PATH";

                private EmbeddedCacheManager manager;

             

               public Node() throws IOException {

                  DOMConfigurator.configure("log4j.xml");

               }  

             

               public void run(int uniqueNode, String PATH) throws IOException  {

                                  

                        manager = new DefaultCacheManager(PATH+"my-config-file.xml");

                        Cache cache = manager.getCache("benchCache");

                      

                        TransactionManager tm = cache.getAdvancedCache().getTransactionManager();

             

                        //if it's the first Node I need to populate the 100 cache entries I'm gonna use with the test

                        if(uniqueNode==1){

                            for(int z=0; z<100; z++){

                                Object put = cache.put("chiave"+z, z);

                            }

                        }

             

                        SAXBuilder builder = new SAXBuilder();

                        Document document = null;

                    try {

                        document = builder.build(new File(PATH+"parametri.xml"));

                    } catch (JDOMException ex) {

                        Logger.getLogger(Node.class.getName()).log(Level.SEVERE, null, ex);

                    } catch (IOException ex) {

                        System.out.println("file parametri.xml non trovato, controllare che sia nella stessa dir");

                        System.exit(0);

                        //Logger.getLogger(Node.class.getName()).log(Level.SEVERE, null, ex);

                    }

             

                        Element rootElement = document.getRootElement();

                        List children = rootElement.getChildren();

                        Iterator iterator = children.iterator();

                        System.out.println("Carico i parametri dal file di configurazione ...\n");

                        int k=0;    // Number of threads             

                        int m=0;    //Number of transactions per thread

                        int n=0;    //Number of operations per transaction

                        int w=0;    //PUT probability

                        int r=0;    //Number of times I generate a random number between 2 transactions or 2 operations (this is better than using sleep() to avoid                            CPU scheduler to release CPU)

                        while (iterator.hasNext()){

                              Element element = (Element)iterator.next();

                              String descrizione = element.getChildText("descrizione");

                              String variabile = element.getChildText("variabile");

                              String valore = element.getChildText("valore");

                              int valorenum=Integer.parseInt(valore);

                              if("k".equals(variabile))

                                  k=valorenum;

                              if("m".equals(variabile))

                                  m=valorenum;

                              if("n".equals(variabile))

                                  n=valorenum;

                              if("w".equals(variabile))

                                  w=valorenum;

                              if("r".equals(variabile))

                                  r=valorenum;

                              System.out.println(descrizione+" ("+variabile+") = "+valore);

             

                          }

                          System.out.println("Press ENTER to continue");

                          Scanner kb=new Scanner(System.in);

             

                          //create k Threads

                          for(int i=0; i<k; i++){

                              new Thread(new RunnableImpl(i,m,r,n,w,cache)).start();

                          }

             

                }

             

                static class RunnableImpl implements Runnable {

             

                    private final int m;

                    private final int r;

                    private final int i;

                    private final int n;

                    private final int w;

                    private Cache defaultCache;

             

                    public RunnableImpl(int i, int m, int r, int n, int w, Cache defaultCache) {

                        this.m = m;

                        this.n = n;

                        this.r = r;

                        this.i = i;

                        this.w = w;

                        this.defaultCache = defaultCache;

             

                    }

             

                    @Override

                       public void run() {

             

                        int h=0, t=0;

                        do{

                            int op_iter=0;

                            while(op_iter<r){

                                int random = (int) Math.round(Math.random() * 10000);

                                System.out.println("thread "+i+": "+random);

                                op_iter++;

                            }

             

                            for(int y=0; y<n; y++){

                                //generate random numbers

                                op_iter=0;

                                while(op_iter<r){

                                    int random = (int) Math.round(Math.random() * 10000);

                                    System.out.println("thread "+i+": "+random);

                                    op_iter++;

                                }

                                //PUT or GET with probability driven by w parameter

                                HERE I WOULD LIKE TO START THE TRANSACTION WITH tm.begin()

                                int op_type=(int) Math.round(Math.random() *100);

                                if (op_type<w)

                                    op_type=0;

                                else op_type=1;

                                switch(op_type){

                                    case 0: System.out.println("thread "+i+": Sorted a put"); defaultCache.put("chiave"+Math.round((int)Math.random() *100), (int)Math.random() *100); break;

                                    case 1: System.out.println("thread "+i+": Sorted a get, read value: "+defaultCache.get("chiave"+(int)Math.round(Math.random() *100))); break;

                            }

                           HERE I WOULD LIKE TO COMMIT THE TRANSACTION WITH tm.commit()

                            }

             

                            //if m = 0 the number of transactions is infinity

                            if(m==0) t=-1;

                            else t++;

                            h++;

                         }

                         while(t<m);

                       }

               }

            }

            • 3. Re: Configuring and using TransactionManager in Infinispan 4.2.1FINAL
              sannegrinovero

              Why do you need transactions at all?

              It seems you could use batching, if you start a batch Infinispan will start it's integrated DummyTransactionManager.

              This is a very simple transaction manager used only to write multiple values in batch, not able to do for example a rollback.

               

              The problem with starting a standalone transaction manger is that you'll have to configure it, and you can do that in many ways. Especially since you're running a little benchmark you will get very different results according to different configurations.

               

              A suggestion: in the code I'm seeying the number of operations is going to be much slower compared to what Infinispan could do, because of the System.out operations and the String concatenations ("+" operator on String). Remove that, or log something every N loops only, and it will be much faster.

               

              Also if a Thread hits an exception, it will die without telling you. You should use an Executor instead of using a Thread directly, and make sure to catch every possible error when dealing with a Runnable.

              1 of 1 people found this helpful
              • 4. Re: Configuring and using TransactionManager in Infinispan 4.2.1FINAL
                renzos

                Why do you need transactions at all?

                I thought I needed transactions cause I'm running more nodes at the same time, each one with a benchmark instance like this one with multiple threads, so 2 or more threads could try to read or write the same cache entry.

                A suggestion: in the code I'm seeying the number of operations is going to be much slower compared to what Infinispan could do, because of the System.out operations and the String concatenations ("+" operator on String). Remove that, or log something every N loops only, and it will be much faster.

                Thanks for reading the whole code, I'm gonna consider that.

                Also if a Thread hits an exception, it will die without telling you. You should use an Executor instead of using a Thread directly, and make sure to catch every possible error when dealing with a Runnable.

                Never used an Executor, I'm gonna get infos on google about the differences with Threads and get back here with a modified code, hope it'll be working.

                • 5. Re: Configuring and using TransactionManager in Infinispan 4.2.1FINAL
                  sannegrinovero

                  I thought I needed transactions cause I'm running more nodes at the same time, each one with a benchmark instance like this one with multiple threads, so 2 or more threads could try to read or write the same cache entry.

                  That is not a problem for Infinispan, unless you're in need to simulate something different.