Search in sources :

Example 1 with BlockCacheConfiguration

use of org.apache.accumulo.core.file.blockfile.cache.impl.BlockCacheConfiguration in project accumulo by apache.

the class BlockCacheFactoryTest method testStartWithDefault.

@Test
public void testStartWithDefault() throws Exception {
    DefaultConfiguration dc = DefaultConfiguration.getInstance();
    BlockCacheManager manager = BlockCacheManagerFactory.getInstance(dc);
    manager.start(new BlockCacheConfiguration(dc));
    Assert.assertNotNull(manager.getBlockCache(CacheType.INDEX));
}
Also used : DefaultConfiguration(org.apache.accumulo.core.conf.DefaultConfiguration) LruBlockCacheManager(org.apache.accumulo.core.file.blockfile.cache.lru.LruBlockCacheManager) TinyLfuBlockCacheManager(org.apache.accumulo.core.file.blockfile.cache.tinylfu.TinyLfuBlockCacheManager) BlockCacheConfiguration(org.apache.accumulo.core.file.blockfile.cache.impl.BlockCacheConfiguration) Test(org.junit.Test)

Example 2 with BlockCacheConfiguration

use of org.apache.accumulo.core.file.blockfile.cache.impl.BlockCacheConfiguration in project accumulo by apache.

the class TestLruBlockCache method testCacheSimple.

public void testCacheSimple() throws Exception {
    long maxSize = 1000000;
    long blockSize = calculateBlockSizeDefault(maxSize, 101);
    DefaultConfiguration dc = DefaultConfiguration.getInstance();
    ConfigurationCopy cc = new ConfigurationCopy(dc);
    cc.set(Property.TSERV_CACHE_MANAGER_IMPL, LruBlockCacheManager.class.getName());
    BlockCacheManager manager = BlockCacheManagerFactory.getInstance(cc);
    cc.set(Property.TSERV_DEFAULT_BLOCKSIZE, Long.toString(blockSize));
    cc.set(Property.TSERV_INDEXCACHE_SIZE, Long.toString(maxSize));
    manager.start(new BlockCacheConfiguration(cc));
    LruBlockCache cache = (LruBlockCache) manager.getBlockCache(CacheType.INDEX);
    Block[] blocks = generateRandomBlocks(100, blockSize);
    long expectedCacheSize = cache.heapSize();
    // Confirm empty
    for (Block block : blocks) {
        assertTrue(cache.getBlock(block.blockName) == null);
    }
    // Add blocks
    for (Block block : blocks) {
        cache.cacheBlock(block.blockName, block.buf);
        expectedCacheSize += block.heapSize();
    }
    // Verify correctly calculated cache heap size
    assertEquals(expectedCacheSize, cache.heapSize());
    // Check if all blocks are properly cached and retrieved
    for (Block block : blocks) {
        CacheEntry ce = cache.getBlock(block.blockName);
        assertTrue(ce != null);
        assertEquals(ce.getBuffer().length, block.buf.length);
    }
    // Verify correctly calculated cache heap size
    assertEquals(expectedCacheSize, cache.heapSize());
    // Check if all blocks are properly cached and retrieved
    for (Block block : blocks) {
        CacheEntry ce = cache.getBlock(block.blockName);
        assertTrue(ce != null);
        assertEquals(ce.getBuffer().length, block.buf.length);
    }
    // Expect no evictions
    assertEquals(0, cache.getEvictionCount());
    // Thread t = new LruBlockCache.StatisticsThread(cache);
    // t.start();
    // t.join();
    manager.stop();
}
Also used : LruBlockCache(org.apache.accumulo.core.file.blockfile.cache.lru.LruBlockCache) ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) LruBlockCacheManager(org.apache.accumulo.core.file.blockfile.cache.lru.LruBlockCacheManager) CachedBlock(org.apache.accumulo.core.file.blockfile.cache.lru.CachedBlock) DefaultConfiguration(org.apache.accumulo.core.conf.DefaultConfiguration) LruBlockCacheManager(org.apache.accumulo.core.file.blockfile.cache.lru.LruBlockCacheManager) BlockCacheConfiguration(org.apache.accumulo.core.file.blockfile.cache.impl.BlockCacheConfiguration) LruBlockCacheConfiguration(org.apache.accumulo.core.file.blockfile.cache.lru.LruBlockCacheConfiguration)

Example 3 with BlockCacheConfiguration

use of org.apache.accumulo.core.file.blockfile.cache.impl.BlockCacheConfiguration in project accumulo by apache.

the class TestLruBlockCache method testCacheEvictionSimple.

public void testCacheEvictionSimple() throws Exception {
    long maxSize = 100000;
    long blockSize = calculateBlockSizeDefault(maxSize, 10);
    DefaultConfiguration dc = DefaultConfiguration.getInstance();
    ConfigurationCopy cc = new ConfigurationCopy(dc);
    cc.set(Property.TSERV_CACHE_MANAGER_IMPL, LruBlockCacheManager.class.getName());
    BlockCacheManager manager = BlockCacheManagerFactory.getInstance(cc);
    cc.set(Property.TSERV_DEFAULT_BLOCKSIZE, Long.toString(blockSize));
    cc.set(Property.TSERV_INDEXCACHE_SIZE, Long.toString(maxSize));
    LruBlockCacheConfiguration.builder(CacheType.INDEX).useEvictionThread(false).buildMap().forEach(cc::set);
    manager.start(new BlockCacheConfiguration(cc));
    LruBlockCache cache = (LruBlockCache) manager.getBlockCache(CacheType.INDEX);
    Block[] blocks = generateFixedBlocks(10, blockSize, "block");
    long expectedCacheSize = cache.heapSize();
    // Add all the blocks
    for (Block block : blocks) {
        cache.cacheBlock(block.blockName, block.buf);
        expectedCacheSize += block.heapSize();
    }
    // A single eviction run should have occurred
    assertEquals(1, cache.getEvictionCount());
    // Our expected size overruns acceptable limit
    assertTrue(expectedCacheSize > (maxSize * LruBlockCacheConfiguration.DEFAULT_ACCEPTABLE_FACTOR));
    // But the cache did not grow beyond max
    assertTrue(cache.heapSize() < maxSize);
    // And is still below the acceptable limit
    assertTrue(cache.heapSize() < (maxSize * LruBlockCacheConfiguration.DEFAULT_ACCEPTABLE_FACTOR));
    // All blocks except block 0 and 1 should be in the cache
    assertTrue(cache.getBlock(blocks[0].blockName) == null);
    assertTrue(cache.getBlock(blocks[1].blockName) == null);
    for (int i = 2; i < blocks.length; i++) {
        assertTrue(Arrays.equals(cache.getBlock(blocks[i].blockName).getBuffer(), blocks[i].buf));
    }
    manager.stop();
}
Also used : LruBlockCache(org.apache.accumulo.core.file.blockfile.cache.lru.LruBlockCache) ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) LruBlockCacheManager(org.apache.accumulo.core.file.blockfile.cache.lru.LruBlockCacheManager) CachedBlock(org.apache.accumulo.core.file.blockfile.cache.lru.CachedBlock) DefaultConfiguration(org.apache.accumulo.core.conf.DefaultConfiguration) LruBlockCacheManager(org.apache.accumulo.core.file.blockfile.cache.lru.LruBlockCacheManager) BlockCacheConfiguration(org.apache.accumulo.core.file.blockfile.cache.impl.BlockCacheConfiguration) LruBlockCacheConfiguration(org.apache.accumulo.core.file.blockfile.cache.lru.LruBlockCacheConfiguration)

Example 4 with BlockCacheConfiguration

use of org.apache.accumulo.core.file.blockfile.cache.impl.BlockCacheConfiguration in project accumulo by apache.

the class TestLruBlockCache method testScanResistance.

// test scan resistance
public void testScanResistance() throws Exception {
    long maxSize = 100000;
    long blockSize = calculateBlockSize(maxSize, 10);
    DefaultConfiguration dc = DefaultConfiguration.getInstance();
    ConfigurationCopy cc = new ConfigurationCopy(dc);
    cc.set(Property.TSERV_CACHE_MANAGER_IMPL, LruBlockCacheManager.class.getName());
    BlockCacheManager manager = BlockCacheManagerFactory.getInstance(cc);
    cc.set(Property.TSERV_DEFAULT_BLOCKSIZE, Long.toString(blockSize));
    cc.set(Property.TSERV_INDEXCACHE_SIZE, Long.toString(maxSize));
    LruBlockCacheConfiguration.builder(CacheType.INDEX).useEvictionThread(false).minFactor(0.66f).acceptableFactor(0.99f).singleFactor(0.33f).multiFactor(0.33f).memoryFactor(0.34f).buildMap().forEach(cc::set);
    manager.start(new BlockCacheConfiguration(cc));
    LruBlockCache cache = (LruBlockCache) manager.getBlockCache(CacheType.INDEX);
    Block[] singleBlocks = generateFixedBlocks(20, blockSize, "single");
    Block[] multiBlocks = generateFixedBlocks(5, blockSize, "multi");
    // Add 5 multi blocks
    for (Block block : multiBlocks) {
        cache.cacheBlock(block.blockName, block.buf);
        cache.getBlock(block.blockName);
    }
    // Add 5 single blocks
    for (int i = 0; i < 5; i++) {
        cache.cacheBlock(singleBlocks[i].blockName, singleBlocks[i].buf);
    }
    // An eviction ran
    assertEquals(1, cache.getEvictionCount());
    // To drop down to 2/3 capacity, we'll need to evict 4 blocks
    assertEquals(4, cache.getEvictedCount());
    // Should have been taken off equally from single and multi
    assertEquals(null, cache.getBlock(singleBlocks[0].blockName));
    assertEquals(null, cache.getBlock(singleBlocks[1].blockName));
    assertEquals(null, cache.getBlock(multiBlocks[0].blockName));
    assertEquals(null, cache.getBlock(multiBlocks[1].blockName));
    for (int i = 5; i < 18; i++) {
        cache.cacheBlock(singleBlocks[i].blockName, singleBlocks[i].buf);
    }
    // 4 total evictions, 16 total evicted
    assertEquals(4, cache.getEvictionCount());
    assertEquals(16, cache.getEvictedCount());
    // Should now have 7 total blocks
    assertEquals(7, cache.size());
    manager.stop();
}
Also used : LruBlockCache(org.apache.accumulo.core.file.blockfile.cache.lru.LruBlockCache) ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) LruBlockCacheManager(org.apache.accumulo.core.file.blockfile.cache.lru.LruBlockCacheManager) CachedBlock(org.apache.accumulo.core.file.blockfile.cache.lru.CachedBlock) DefaultConfiguration(org.apache.accumulo.core.conf.DefaultConfiguration) LruBlockCacheManager(org.apache.accumulo.core.file.blockfile.cache.lru.LruBlockCacheManager) BlockCacheConfiguration(org.apache.accumulo.core.file.blockfile.cache.impl.BlockCacheConfiguration) LruBlockCacheConfiguration(org.apache.accumulo.core.file.blockfile.cache.lru.LruBlockCacheConfiguration)

Example 5 with BlockCacheConfiguration

use of org.apache.accumulo.core.file.blockfile.cache.impl.BlockCacheConfiguration in project accumulo by apache.

the class TestLruBlockCache method testBackgroundEvictionThread.

public void testBackgroundEvictionThread() throws Exception {
    long maxSize = 100000;
    // room for 9, will evict
    long blockSize = calculateBlockSizeDefault(maxSize, 9);
    DefaultConfiguration dc = DefaultConfiguration.getInstance();
    ConfigurationCopy cc = new ConfigurationCopy(dc);
    cc.set(Property.TSERV_CACHE_MANAGER_IMPL, LruBlockCacheManager.class.getName());
    BlockCacheManager manager = BlockCacheManagerFactory.getInstance(cc);
    cc.set(Property.TSERV_DEFAULT_BLOCKSIZE, Long.toString(blockSize));
    cc.set(Property.TSERV_INDEXCACHE_SIZE, Long.toString(maxSize));
    manager.start(new BlockCacheConfiguration(cc));
    LruBlockCache cache = (LruBlockCache) manager.getBlockCache(CacheType.INDEX);
    Block[] blocks = generateFixedBlocks(10, blockSize, "block");
    // Add all the blocks
    for (Block block : blocks) {
        cache.cacheBlock(block.blockName, block.buf);
    }
    // Let the eviction run
    int n = 0;
    while (cache.getEvictionCount() == 0) {
        Thread.sleep(1000);
        assertTrue(n++ < 1);
    }
    // A single eviction run should have occurred
    assertEquals(cache.getEvictionCount(), 1);
    manager.stop();
}
Also used : LruBlockCache(org.apache.accumulo.core.file.blockfile.cache.lru.LruBlockCache) ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) LruBlockCacheManager(org.apache.accumulo.core.file.blockfile.cache.lru.LruBlockCacheManager) CachedBlock(org.apache.accumulo.core.file.blockfile.cache.lru.CachedBlock) DefaultConfiguration(org.apache.accumulo.core.conf.DefaultConfiguration) LruBlockCacheManager(org.apache.accumulo.core.file.blockfile.cache.lru.LruBlockCacheManager) BlockCacheConfiguration(org.apache.accumulo.core.file.blockfile.cache.impl.BlockCacheConfiguration) LruBlockCacheConfiguration(org.apache.accumulo.core.file.blockfile.cache.lru.LruBlockCacheConfiguration)

Aggregations

BlockCacheConfiguration (org.apache.accumulo.core.file.blockfile.cache.impl.BlockCacheConfiguration)8 LruBlockCacheManager (org.apache.accumulo.core.file.blockfile.cache.lru.LruBlockCacheManager)8 ConfigurationCopy (org.apache.accumulo.core.conf.ConfigurationCopy)7 DefaultConfiguration (org.apache.accumulo.core.conf.DefaultConfiguration)7 LruBlockCacheConfiguration (org.apache.accumulo.core.file.blockfile.cache.lru.LruBlockCacheConfiguration)7 CachedBlock (org.apache.accumulo.core.file.blockfile.cache.lru.CachedBlock)6 LruBlockCache (org.apache.accumulo.core.file.blockfile.cache.lru.LruBlockCache)6 TinyLfuBlockCacheManager (org.apache.accumulo.core.file.blockfile.cache.tinylfu.TinyLfuBlockCacheManager)1 Test (org.junit.Test)1