Search in sources :

Example 1 with CacheQuota

use of com.facebook.presto.hive.CacheQuota 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 2 with CacheQuota

use of com.facebook.presto.hive.CacheQuota in project presto by prestodb.

the class TestAlluxioCachingFileSystem method testStressWithQuota.

@Test(invocationCount = 10)
public void testStressWithQuota() throws ExecutionException, InterruptedException, URISyntaxException, IOException {
    CacheQuota cacheQuota = new CacheQuota("test.table", Optional.of(DataSize.succinctDataSize(5, KILOBYTE)));
    CacheConfig cacheConfig = new CacheConfig().setCacheType(ALLUXIO).setCachingEnabled(true).setValidationEnabled(false).setBaseDirectory(cacheDirectory).setCacheQuotaScope(TABLE);
    AlluxioCacheConfig alluxioCacheConfig = new AlluxioCacheConfig().setMaxCacheSize(new DataSize(10, KILOBYTE)).setCacheQuotaEnabled(true);
    Configuration configuration = getHdfsConfiguration(cacheConfig, alluxioCacheConfig);
    AlluxioCachingFileSystem cachingFileSystem = cachingFileSystem(configuration);
    stressTest(data, (position, buffer, offset, length) -> {
        try {
            readFully(cachingFileSystem, cacheQuota, position, buffer, offset, length);
        } catch (Exception e) {
            e.printStackTrace();
        }
    });
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) DataSize(io.airlift.units.DataSize) CacheConfig(com.facebook.presto.cache.CacheConfig) CacheQuota(com.facebook.presto.hive.CacheQuota) NotImplementedException(alluxio.shaded.client.org.apache.commons.lang3.NotImplementedException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.testng.annotations.Test) TestingCacheUtils.stressTest(com.facebook.presto.cache.TestingCacheUtils.stressTest)

Example 3 with CacheQuota

use of com.facebook.presto.hive.CacheQuota in project presto by prestodb.

the class TestAlluxioCachingFileSystem method testQuotaBasics.

@Test(timeOut = 30_000)
public void testQuotaBasics() throws Exception {
    DataSize quotaSize = DataSize.succinctDataSize(1, KILOBYTE);
    CacheQuota cacheQuota = new CacheQuota("test.table", Optional.of(quotaSize));
    CacheConfig cacheConfig = new CacheConfig().setCacheType(ALLUXIO).setCachingEnabled(true).setBaseDirectory(cacheDirectory).setValidationEnabled(false).setCacheQuotaScope(TABLE);
    AlluxioCacheConfig alluxioCacheConfig = new AlluxioCacheConfig().setCacheQuotaEnabled(true);
    Configuration configuration = getHdfsConfiguration(cacheConfig, alluxioCacheConfig);
    AlluxioCachingFileSystem fileSystem = cachingFileSystem(configuration);
    byte[] buffer = new byte[10240];
    // read within the cache quota
    resetBaseline();
    assertEquals(readFully(fileSystem, cacheQuota, 42, buffer, 0, 100), 100);
    checkMetrics(MetricKey.CLIENT_CACHE_BYTES_READ_CACHE, 0);
    checkMetrics(MetricKey.CLIENT_CACHE_BYTES_REQUESTED_EXTERNAL, 100);
    checkMetrics(MetricKey.CLIENT_CACHE_BYTES_READ_EXTERNAL, PAGE_SIZE);
    checkMetrics(MetricKey.CLIENT_CACHE_BYTES_EVICTED, 0);
    validateBuffer(data, 42, buffer, 0, 100);
    // read beyond cache quota
    resetBaseline();
    assertEquals(readFully(fileSystem, cacheQuota, 47, buffer, 0, 9000), 9000);
    checkMetrics(MetricKey.CLIENT_CACHE_BYTES_READ_CACHE, PAGE_SIZE - 47);
    checkMetrics(MetricKey.CLIENT_CACHE_BYTES_REQUESTED_EXTERNAL, 9000 - PAGE_SIZE + 47);
    checkMetrics(MetricKey.CLIENT_CACHE_BYTES_READ_EXTERNAL, (9000 / PAGE_SIZE) * PAGE_SIZE);
    checkMetrics(MetricKey.CLIENT_CACHE_BYTES_EVICTED, (9000 / PAGE_SIZE) * PAGE_SIZE);
    validateBuffer(data, 47, buffer, 0, 9000);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) DataSize(io.airlift.units.DataSize) CacheConfig(com.facebook.presto.cache.CacheConfig) CacheQuota(com.facebook.presto.hive.CacheQuota) Test(org.testng.annotations.Test) TestingCacheUtils.stressTest(com.facebook.presto.cache.TestingCacheUtils.stressTest)

Example 4 with CacheQuota

use of com.facebook.presto.hive.CacheQuota in project presto by prestodb.

the class TestAlluxioCachingFileSystem method testQuotaUpdated.

@Test(timeOut = 30_000)
public void testQuotaUpdated() throws Exception {
    CacheQuota smallCacheQuota = new CacheQuota("test.table", Optional.of(DataSize.succinctDataSize(1, KILOBYTE)));
    CacheConfig cacheConfig = new CacheConfig().setCacheType(ALLUXIO).setCachingEnabled(true).setBaseDirectory(cacheDirectory).setValidationEnabled(false).setCacheQuotaScope(TABLE);
    AlluxioCacheConfig alluxioCacheConfig = new AlluxioCacheConfig().setCacheQuotaEnabled(true);
    Configuration configuration = getHdfsConfiguration(cacheConfig, alluxioCacheConfig);
    AlluxioCachingFileSystem fileSystem = cachingFileSystem(configuration);
    byte[] buffer = new byte[10240];
    // read beyond the small cache quota
    resetBaseline();
    assertEquals(readFully(fileSystem, smallCacheQuota, 0, buffer, 0, 9000), 9000);
    checkMetrics(MetricKey.CLIENT_CACHE_BYTES_READ_CACHE, 0);
    checkMetrics(MetricKey.CLIENT_CACHE_BYTES_REQUESTED_EXTERNAL, 9000);
    checkMetrics(MetricKey.CLIENT_CACHE_BYTES_READ_EXTERNAL, (9000 / PAGE_SIZE + 1) * PAGE_SIZE);
    checkMetrics(MetricKey.CLIENT_CACHE_BYTES_EVICTED, (9000 / PAGE_SIZE) * PAGE_SIZE);
    validateBuffer(data, 0, buffer, 0, 9000);
    // read again within an updated larger cache quota
    CacheQuota largeCacheQuota = new CacheQuota("test.table", Optional.of(DataSize.succinctDataSize(10, KILOBYTE)));
    resetBaseline();
    assertEquals(readFully(fileSystem, largeCacheQuota, 0, buffer, 0, 9000), 9000);
    checkMetrics(MetricKey.CLIENT_CACHE_BYTES_READ_CACHE, 9000 - (9000 / PAGE_SIZE) * PAGE_SIZE);
    checkMetrics(MetricKey.CLIENT_CACHE_BYTES_REQUESTED_EXTERNAL, (9000 / PAGE_SIZE) * PAGE_SIZE);
    checkMetrics(MetricKey.CLIENT_CACHE_BYTES_READ_EXTERNAL, (9000 / PAGE_SIZE) * PAGE_SIZE);
    checkMetrics(MetricKey.CLIENT_CACHE_BYTES_EVICTED, 0);
    validateBuffer(data, 0, buffer, 0, 9000);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) CacheConfig(com.facebook.presto.cache.CacheConfig) CacheQuota(com.facebook.presto.hive.CacheQuota) Test(org.testng.annotations.Test) TestingCacheUtils.stressTest(com.facebook.presto.cache.TestingCacheUtils.stressTest)

Aggregations

TestingCacheUtils.stressTest (com.facebook.presto.cache.TestingCacheUtils.stressTest)4 CacheQuota (com.facebook.presto.hive.CacheQuota)4 Test (org.testng.annotations.Test)4 CacheConfig (com.facebook.presto.cache.CacheConfig)3 Configuration (org.apache.hadoop.conf.Configuration)3 DataSize (io.airlift.units.DataSize)2 NotImplementedException (alluxio.shaded.client.org.apache.commons.lang3.NotImplementedException)1 CacheManager (com.facebook.presto.cache.CacheManager)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 ExecutionException (java.util.concurrent.ExecutionException)1