Search in sources :

Example 1 with CacheManager

use of com.facebook.presto.cache.CacheManager in project presto by prestodb.

the class TestFileMergeCacheManager method testBasic.

@Test(timeOut = 30_000)
public void testBasic() throws InterruptedException, ExecutionException, IOException {
    TestingCacheStats stats = new TestingCacheStats();
    CacheManager cacheManager = fileMergeCacheManager(stats);
    byte[] buffer = new byte[1024];
    // new read
    assertFalse(readFully(cacheManager, NO_CACHE_CONSTRAINTS, 42, buffer, 0, 100));
    assertEquals(stats.getCacheMiss(), 1);
    assertEquals(stats.getCacheHit(), 0);
    stats.trigger();
    assertEquals(stats.getInMemoryRetainedBytes(), 0);
    validateBuffer(data, 42, buffer, 0, 100);
    // within the range of the cache
    assertTrue(readFully(cacheManager, NO_CACHE_CONSTRAINTS, 47, buffer, 0, 90));
    assertEquals(stats.getCacheMiss(), 1);
    assertEquals(stats.getCacheHit(), 1);
    assertEquals(stats.getInMemoryRetainedBytes(), 0);
    validateBuffer(data, 47, buffer, 0, 90);
    // partially within the range of the cache
    assertFalse(readFully(cacheManager, NO_CACHE_CONSTRAINTS, 52, buffer, 0, 100));
    assertEquals(stats.getCacheMiss(), 2);
    assertEquals(stats.getCacheHit(), 1);
    stats.trigger();
    assertEquals(stats.getInMemoryRetainedBytes(), 0);
    validateBuffer(data, 52, buffer, 0, 100);
    // partially within the range of the cache
    assertFalse(readFully(cacheManager, NO_CACHE_CONSTRAINTS, 32, buffer, 10, 50));
    assertEquals(stats.getCacheMiss(), 3);
    assertEquals(stats.getCacheHit(), 1);
    stats.trigger();
    assertEquals(stats.getInMemoryRetainedBytes(), 0);
    validateBuffer(data, 32, buffer, 10, 50);
    // create a hole within two caches
    assertFalse(readFully(cacheManager, NO_CACHE_CONSTRAINTS, 200, buffer, 40, 50));
    assertEquals(stats.getCacheMiss(), 4);
    assertEquals(stats.getCacheHit(), 1);
    stats.trigger();
    assertEquals(stats.getInMemoryRetainedBytes(), 0);
    validateBuffer(data, 200, buffer, 40, 50);
    // use a range to cover the hole
    assertFalse(readFully(cacheManager, NO_CACHE_CONSTRAINTS, 40, buffer, 400, 200));
    assertEquals(stats.getCacheMiss(), 5);
    assertEquals(stats.getCacheHit(), 1);
    stats.trigger();
    assertEquals(stats.getInMemoryRetainedBytes(), 0);
    validateBuffer(data, 40, buffer, 400, 200);
}
Also used : CacheManager(com.facebook.presto.cache.CacheManager) Test(org.testng.annotations.Test) TestingCacheUtils.stressTest(com.facebook.presto.cache.TestingCacheUtils.stressTest)

Example 2 with CacheManager

use of com.facebook.presto.cache.CacheManager in project presto by prestodb.

the class TestFileMergeCacheManager method testQuota.

@Test(timeOut = 30_000)
public void testQuota() throws InterruptedException, ExecutionException, IOException {
    TestingCacheStats stats = new TestingCacheStats();
    CacheManager cacheManager = fileMergeCacheManager(stats);
    byte[] buffer = new byte[10240];
    CacheQuota cacheQuota = new CacheQuota("test.table", Optional.of(DataSize.succinctDataSize(1, KILOBYTE)));
    // read within the cache quota
    assertFalse(readFully(cacheManager, cacheQuota, 42, buffer, 0, 100));
    assertEquals(stats.getCacheMiss(), 1);
    assertEquals(stats.getCacheHit(), 0);
    assertEquals(stats.getQuotaExceed(), 0);
    stats.trigger();
    assertEquals(stats.getInMemoryRetainedBytes(), 0);
    validateBuffer(data, 42, buffer, 0, 100);
    // read beyond cache quota
    assertFalse(readFully(cacheManager, cacheQuota, 47, buffer, 0, 9000));
    assertEquals(stats.getCacheMiss(), 1);
    assertEquals(stats.getCacheHit(), 0);
    assertEquals(stats.getQuotaExceed(), 1);
    assertEquals(stats.getInMemoryRetainedBytes(), 0);
    validateBuffer(data, 47, buffer, 0, 90);
    // previous data won't be evicted if last read exceed quota
    assertTrue(readFully(cacheManager, cacheQuota, 47, buffer, 0, 90));
    assertEquals(stats.getCacheMiss(), 1);
    assertEquals(stats.getCacheHit(), 1);
    assertEquals(stats.getQuotaExceed(), 1);
    assertEquals(stats.getInMemoryRetainedBytes(), 0);
    validateBuffer(data, 47, buffer, 0, 90);
}
Also used : CacheManager(com.facebook.presto.cache.CacheManager) CacheQuota(com.facebook.presto.hive.CacheQuota) Test(org.testng.annotations.Test) TestingCacheUtils.stressTest(com.facebook.presto.cache.TestingCacheUtils.stressTest)

Example 3 with CacheManager

use of com.facebook.presto.cache.CacheManager in project presto by prestodb.

the class TestFileMergeCacheManager method testStress.

@Test(invocationCount = 10)
public void testStress() throws ExecutionException, InterruptedException {
    CacheConfig cacheConfig = new CacheConfig().setBaseDirectory(cacheDirectory);
    FileMergeCacheConfig fileMergeCacheConfig = new FileMergeCacheConfig().setCacheTtl(new Duration(10, MILLISECONDS));
    CacheManager cacheManager = fileMergeCacheManager(cacheConfig, fileMergeCacheConfig);
    stressTest(data, (position, buffer, offset, length) -> readFully(cacheManager, NO_CACHE_CONSTRAINTS, position, buffer, offset, length));
}
Also used : CacheManager(com.facebook.presto.cache.CacheManager) Duration(io.airlift.units.Duration) CacheConfig(com.facebook.presto.cache.CacheConfig) Test(org.testng.annotations.Test) TestingCacheUtils.stressTest(com.facebook.presto.cache.TestingCacheUtils.stressTest)

Aggregations

CacheManager (com.facebook.presto.cache.CacheManager)3 TestingCacheUtils.stressTest (com.facebook.presto.cache.TestingCacheUtils.stressTest)3 Test (org.testng.annotations.Test)3 CacheConfig (com.facebook.presto.cache.CacheConfig)1 CacheQuota (com.facebook.presto.hive.CacheQuota)1 Duration (io.airlift.units.Duration)1