10 Replies Latest reply on Oct 4, 2011 11:14 AM by Galder Zamarreño

    cache reading performance

    Lin Ye Novice

      I did some performance testing on Infinispan earlier last year, and the data for both reading and updating are satisfactory. Especially, the reading is real fast. However, recently the reading performance data we measured in our application is not good. I tried to create a very simple test with a local cache, and the reading is slow. Basically, for my following simple code, the update took less than 300 millisenconds, while the reading took around 12 seconds. Could you please suggest what I made wrong here?

       

      import java.util.ArrayList;

      import java.util.HashMap;

      import java.util.List;

      import java.util.Map;

      import org.infinispan.Cache;

      import org.infinispan.manager.DefaultCacheManager;

       

      public class ReadingTest {

          public final static int SIZE = 50000;

         

          public ReadingTest() {

          }

       

          public static void main(String[] args) {

              ReadingTest test = new ReadingTest();

              test.run();

          }

         

          public void run() {

              DefaultCacheManager cacheManager = new DefaultCacheManager();

              Cache cache = cacheManager.getCache();

              System.out.println("cache mode " + cache.getConfiguration().getCacheModeString());

             

              List<String> list = new ArrayList<String>(SIZE);

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

                  list.add(String.valueOf(i));

              }

             

              Map<String, String> map = new HashMap<String, String>(SIZE);

              for (String s : list) {

                  map.put(s, s);

              }

             

              long timeBefore = System.currentTimeMillis();

              cache.putAll(map);

              long time = System.currentTimeMillis() - timeBefore;

              System.out.println("Updated " + SIZE + " values in " + time + " milliseconds");

        

              List retList = new ArrayList(SIZE);

              timeBefore = System.currentTimeMillis();

              for (String s : list) {

                  retList.add(cache.get(s));

              }

              time = System.currentTimeMillis() - timeBefore;

              System.out.println("Read " + SIZE + " values in " + time + " milliseconds");

          }

             

      }