Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.infinispan.lucene.profiling;
  
  import java.io.File;
  
PerformanceCompareStressTest is useful to get an idea on relative performance between Infinispan in local or clustered mode against a RAMDirectory or FSDirectory. To be reliable set a long DURATION_MS and a number of threads similar to the use case you're interested in: results might vary on the number of threads because of the lock differences. This is not meant as a benchmark but used to detect regressions. This requires Lucene > 2.9.1 or Lucene > 3.0.0 because of https://issues.apache.org/jira/browse/LUCENE-2095

Author(s):
Sanne Grinovero
Since:
4.0
 
 @SuppressWarnings("unchecked")
 @Test(groups = "profiling", testName = "lucene.profiling.PerformanceCompareStressTest", sequential = true)
 public class PerformanceCompareStressTest {

   
The number of terms in the dictionary used as source of terms by the IndexWriter to produce new documents
 
    private static final int DICTIONARY_SIZE = 800 * 1000;

   
Concurrent Threads in tests
 
    private static final int READER_THREADS = 5;
    private static final int WRITER_THREADS = 1;
    
    private static final int CHUNK_SIZE = 512 * 1024;
 
    private static final String indexName = "tempIndexName";
 
    private static final long DURATION_MS = 2 * 60 * 1000;
 
    private Cache cache;
 
 
    @Test
    public void profileTestRAMDirectory() throws InterruptedExceptionIOException {
       RAMDirectory dir = new RAMDirectory();
       stressTestDirectory(dir"RAMDirectory");
    }
 
    @Test
    public void profileTestFSDirectory() throws InterruptedExceptionIOException {
       File indexDir = new File(new File("."), );
       boolean directoriesCreated = indexDir.mkdirs();
       assert directoriesCreated : "couldn't create directory for FSDirectory test";
       FSDirectory dir = FSDirectory.open(indexDir);
       stressTestDirectory(dir"FSDirectory");
    }
    
    @Test
       // TestingUtil.setDelayForCache(cache, 0, 0);
       Directory dir = DirectoryBuilder.newDirectoryInstance().chunkSize().create();
       stressTestDirectory(dir"InfinispanClustered-delayedIO:0");
       verifyDirectoryState();
    }
 
    @Test
       TestingUtil.setDelayForCache(, 4, 4);
       Directory dir = DirectoryBuilder.newDirectoryInstance().chunkSize().create();
       stressTestDirectory(dir"InfinispanClustered-delayedIO:4");
       verifyDirectoryState();
    }
 
    @Test
       TestingUtil.setDelayForCache(, 40, 40);
       Directory dir = DirectoryBuilder.newDirectoryInstance().chunkSize().create();
       stressTestDirectory(dir"InfinispanClustered-delayedIO:40");
       verifyDirectoryState();
   }
   @Test
      CacheContainer cacheContainer = CacheTestSupport.createLocalCacheManager();
      try {
          = cacheContainer.getCache();
         Directory dir = DirectoryBuilder.newDirectoryInstance().chunkSize().create();
         stressTestDirectory(dir"InfinispanLocal");
         verifyDirectoryState();
      } finally {
         cacheContainer.stop();
      }
   }
   @Test(enabled=false)//to prevent invocations from some versions of TestNG
   public static void stressTestDirectory(Directory dirString testLabelthrows InterruptedExceptionIOException {
      SharedState state = new SharedState();
      CacheTestSupport.initializeDirectory(dir);
      for (int i = 0; i < i++) {
         e.execute(new LuceneReaderThread(dirstate));
      }
      for (int i = 0; i < i++) {
         e.execute(new LuceneWriterThread(dirstate));
      }
      e.shutdown();
      state.startWaitingThreads();
      Thread.sleep();
      long searchesCount = state.incrementIndexSearchesCount(0);
      long writerTaskCount = state.incrementIndexWriterTaskCount(0);
      state.quit();
      boolean terminatedCorrectly = e.awaitTermination(20, .);
      AssertJUnit.assertTrue(terminatedCorrectly);
      ..println("Test " + testLabel + " run in " +  + "ms:\n\tSearches: " + searchesCount + "\n\t" + "Writes: "
               + writerTaskCount);
   }
   public void beforeTest() {
       = TestCacheManagerFactory.createClusteredCacheManager(
            CacheTestSupport.createTestConfiguration(.));
      .start();
       = .getCache();
      .clear();
   }
   public void afterTest() {
      TestingUtil.killCaches();
      TestingUtil.killCacheManagers();
      TestingUtil.recursiveFileRemove();
   }
   
   private void verifyDirectoryState() {
      DirectoryIntegrityCheck.verifyDirectoryStructure(true);
   }

   
It's much better to compare performance out of the scope of TestNG by running this directly as TestNG enables assertions. Suggested test switches: -Xmx2G -Xms2G -XX:MaxPermSize=128M -XX:+HeapDumpOnOutOfMemoryError -Xss512k -XX:HeapDumpPath=/tmp/java_heap -Djava.net.preferIPv4Stack=true -Djgroups.bind_addr=127.0.0.1 -Xbatch -server -XX:+UseCompressedOops -XX:+UseLargePages -XX:LargePageSizeInBytes=2m -XX:+AlwaysPreTouch
   public static void main(String[] argsthrows InterruptedExceptionIOException {
      test.beforeTest();
      try {
         test.profileTestRAMDirectory();
      }
      finally {
         test.afterTest();
      }
      test.beforeTest();
      try {
         test.profileTestFSDirectory();
      }
      finally {
         test.afterTest();
      }
      test.beforeTest();
      try {
         test.profileInfinispanLocalDirectory();
      }
      finally {
         test.afterTest();
      }
      test.beforeTest();
      try {
      }
      finally {
         test.afterTest();
      }
   }
New to GrepCode? Check out our FAQ X