当前位置: 首页>>代码示例>>Java>>正文


Java EvictionThread类代码示例

本文整理汇总了Java中org.apache.hadoop.hbase.io.hfile.LruBlockCache.EvictionThread的典型用法代码示例。如果您正苦于以下问题:Java EvictionThread类的具体用法?Java EvictionThread怎么用?Java EvictionThread使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


EvictionThread类属于org.apache.hadoop.hbase.io.hfile.LruBlockCache包,在下文中一共展示了EvictionThread类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testBackgroundEvictionThread

import org.apache.hadoop.hbase.io.hfile.LruBlockCache.EvictionThread; //导入依赖的package包/类
@Test
public void testBackgroundEvictionThread() throws Exception {
  long maxSize = 100000;
  long blockSize = calculateBlockSizeDefault(maxSize, 9); // room for 9, will evict

  LruBlockCache cache = new LruBlockCache(maxSize, blockSize, TEST_UTIL.getConfiguration());

  CachedItem [] blocks = generateFixedBlocks(10, blockSize, "block");

  EvictionThread evictionThread = cache.getEvictionThread();
  assertTrue(evictionThread != null);

  // Make sure eviction thread has entered run method
  while (!evictionThread.isEnteringRun()) {
    Thread.sleep(1);
  }

  // Add all the blocks
  for (CachedItem block : blocks) {
    cache.cacheBlock(block.cacheKey, block);
  }

  // Let the eviction run
  int n = 0;
  while(cache.getEvictionCount() == 0) {
    Thread.sleep(200);
    assertTrue(n++ < 20);
  }
  System.out.println("Background Evictions run: " + cache.getEvictionCount());

  // A single eviction run should have occurred
  assertEquals(cache.getEvictionCount(), 1);
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:34,代码来源:TestLruBlockCache.java

示例2: testBackgroundEvictionThread

import org.apache.hadoop.hbase.io.hfile.LruBlockCache.EvictionThread; //导入依赖的package包/类
@Test
public void testBackgroundEvictionThread() throws Exception {
  long maxSize = 100000;
  long blockSize = calculateBlockSizeDefault(maxSize, 9); // room for 9, will evict

  LruBlockCache cache = new LruBlockCache(maxSize,blockSize);

  CachedItem [] blocks = generateFixedBlocks(10, blockSize, "block");

  EvictionThread evictionThread = cache.getEvictionThread();
  assertTrue(evictionThread != null);

  // Make sure eviction thread has entered run method
  while (!evictionThread.isEnteringRun()) {
    Thread.sleep(1);
  }
  

  // Add all the blocks
  for (CachedItem block : blocks) {
    cache.cacheBlock(block.cacheKey, block);
  }

  // Let the eviction run
  int n = 0;
  while(cache.getEvictionCount() == 0) {
    Thread.sleep(200);
    assertTrue(n++ < 10);
  }
  System.out.println("Background Evictions run: " + cache.getEvictionCount());

  // A single eviction run should have occurred
  assertEquals(cache.getEvictionCount(), 1);
}
 
开发者ID:daidong,项目名称:DominoHBase,代码行数:35,代码来源:TestLruBlockCache.java

示例3: testBackgroundEvictionThread

import org.apache.hadoop.hbase.io.hfile.LruBlockCache.EvictionThread; //导入依赖的package包/类
@Test
public void testBackgroundEvictionThread() throws Exception {
  long maxSize = 100000;
  int numBlocks = 9;
  long blockSize = calculateBlockSizeDefault(maxSize, numBlocks);
  assertTrue("calculateBlockSize appears broken.", blockSize * numBlocks <= maxSize);

  LruBlockCache cache = new LruBlockCache(maxSize,blockSize);
  EvictionThread evictionThread = cache.getEvictionThread();
  assertTrue(evictionThread != null);

  CachedItem[] blocks = generateFixedBlocks(numBlocks + 1, blockSize, "block");

  // Make sure eviction thread has entered run method
  while (!evictionThread.isEnteringRun()) {
    Thread.sleep(1);
  }

  // Add all the blocks
  for (CachedItem block : blocks) {
    cache.cacheBlock(block.cacheKey, block);
  }

  // wait until at least one eviction has run
  int n = 0;
  while(cache.getStats().getEvictionCount() == 0) {
    Thread.sleep(200);
    assertTrue("Eviction never happened.", n++ < 20);
  }

  // let cache stabilize
  // On some systems, the cache will run multiple evictions before it attains
  // steady-state. For instance, after populating the cache with 10 blocks,
  // the first eviction evicts a single block and then a second eviction
  // evicts another. I think this is due to the delta between minSize and
  // acceptableSize, combined with variance between object overhead on
  // different environments.
  n = 0;
  for (long prevCnt = 0 /* < number of blocks added */,
            curCnt = cache.getBlockCount();
      prevCnt != curCnt; prevCnt = curCnt, curCnt = cache.getBlockCount()) {
    Thread.sleep(200);
    assertTrue("Cache never stabilized.", n++ < 20);
  }

  long evictionCount = cache.getStats().getEvictionCount();
  assertTrue(evictionCount >= 1);
  System.out.println("Background Evictions run: " + evictionCount);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:50,代码来源:TestLruBlockCache.java

示例4: testBackgroundEvictionThread

import org.apache.hadoop.hbase.io.hfile.LruBlockCache.EvictionThread; //导入依赖的package包/类
@Test
public void testBackgroundEvictionThread() throws Exception {
  long maxSize = 100000;
  int numBlocks = 9;
  long blockSize = calculateBlockSizeDefault(maxSize, numBlocks);
  assertTrue("calculateBlockSize appears broken.", blockSize * numBlocks <= maxSize);

  LruBlockCache cache = new LruBlockCache(maxSize,blockSize);
  EvictionThread evictionThread = cache.getEvictionThread();
  assertTrue(evictionThread != null);

  CachedItem[] blocks = generateFixedBlocks(numBlocks + 1, blockSize, "block");

  // Make sure eviction thread has entered run method
  while (!evictionThread.isEnteringRun()) {
    Thread.sleep(1);
  }

  // Add all the blocks
  for (CachedItem block : blocks) {
    cache.cacheBlock(block.cacheKey, block);
  }

  // wait until at least one eviction has run
  int n = 0;
  while(cache.getEvictionCount() == 0) {
    Thread.sleep(200);
    assertTrue("Eviction never happened.", n++ < 20);
  }

  // let cache stabilize
  // On some systems, the cache will run multiple evictions before it attains
  // steady-state. For instance, after populating the cache with 10 blocks,
  // the first eviction evicts a single block and then a second eviction
  // evicts another. I think this is due to the delta between minSize and
  // acceptableSize, combined with variance between object overhead on
  // different environments.
  n = 0;
  for (long prevCnt = 0 /* < number of blocks added */,
            curCnt = cache.getBlockCount();
      prevCnt != curCnt; prevCnt = curCnt, curCnt = cache.getBlockCount()) {
    Thread.sleep(200);
    assertTrue("Cache never stabilized.", n++ < 20);
  }

  long evictionCount = cache.getEvictionCount();
  assertTrue(evictionCount >= 1);
  System.out.println("Background Evictions run: " + evictionCount);
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:50,代码来源:TestLruBlockCache.java

示例5: testCacheEvictionThreadSafe

import org.apache.hadoop.hbase.io.hfile.LruBlockCache.EvictionThread; //导入依赖的package包/类
@Test
public void testCacheEvictionThreadSafe() throws Exception {
  long maxSize = 100000;
  int numBlocks = 9;
  int testRuns = 10;
  final long blockSize = calculateBlockSizeDefault(maxSize, numBlocks);
  assertTrue("calculateBlockSize appears broken.", blockSize * numBlocks <= maxSize);

  final Configuration conf = HBaseConfiguration.create();
  final LruBlockCache cache = new LruBlockCache(maxSize, blockSize);
  EvictionThread evictionThread = cache.getEvictionThread();
  assertTrue(evictionThread != null);
  while (!evictionThread.isEnteringRun()) {
    Thread.sleep(1);
  }
  final String hfileName = "hfile";
  int threads = 10;
  final int blocksPerThread = 5 * numBlocks;
  for (int run = 0; run != testRuns; ++run) {
    final AtomicInteger blockCount = new AtomicInteger(0);
    ExecutorService service = Executors.newFixedThreadPool(threads);
    for (int i = 0; i != threads; ++i) {
      service.execute(new Runnable() {
        @Override
        public void run() {
          for (int blockIndex = 0; blockIndex < blocksPerThread || (!cache.isEvictionInProgress()); ++blockIndex) {
            CachedItem block = new CachedItem(hfileName, (int) blockSize, blockCount.getAndIncrement());
            boolean inMemory = Math.random() > 0.5;
            cache.cacheBlock(block.cacheKey, block, inMemory);
          }
          cache.evictBlocksByHfileName(hfileName);
        }
      });
    }
    service.shutdown();
    // The test may fail here if the evict thread frees the blocks too fast
    service.awaitTermination(10, TimeUnit.MINUTES);
    Waiter.waitFor(conf, 10000, 100, new ExplainingPredicate<Exception>() {
      @Override
      public boolean evaluate() throws Exception {
        return cache.getBlockCount() == 0;
      }

      @Override
      public String explainFailure() throws Exception {
        return "Cache block count failed to return to 0";
      }
    });
    assertEquals(0, cache.getBlockCount());
    assertEquals(cache.getOverhead(), cache.getCurrentSize());
  }
}
 
开发者ID:apache,项目名称:hbase,代码行数:53,代码来源:TestLruBlockCache.java


注:本文中的org.apache.hadoop.hbase.io.hfile.LruBlockCache.EvictionThread类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。