use of alluxio.client.file.cache.PageId in project alluxio by Alluxio.
the class PageStoreTest method thousandGetTest.
void thousandGetTest(PageStore store) throws Exception {
int numPages = 1000;
int numTrials = 3;
// Fill the cache
List<Integer> pages = new ArrayList<>(numPages);
byte[] b = new byte[Constants.MB];
Arrays.fill(b, (byte) 0x7a);
Random r = new Random();
for (int i = 0; i < numPages; i++) {
int pind = r.nextInt();
store.put(new PageId("0", pind), b);
pages.add(pind);
}
ByteArrayOutputStream bos = new ByteArrayOutputStream(Constants.MB);
ArrayList<Long> times = new ArrayList<>();
byte[] buf = new byte[Constants.MB];
for (int i = 0; i < numTrials; i++) {
Collections.shuffle(pages);
long start = System.nanoTime();
bos.reset();
for (Integer pageIndex : pages) {
store.get(new PageId("0", pageIndex), buf);
}
long end = System.nanoTime();
times.add(end - start);
}
double avg = (double) times.stream().mapToLong(Long::longValue).sum() / numTrials;
System.out.println(String.format("Finished thousand get for %7s : %.2fns", mOptions, avg));
}
use of alluxio.client.file.cache.PageId in project alluxio by Alluxio.
the class PageStoreTest method getSmallBuffer.
@Test
public void getSmallBuffer() throws Exception {
int len = 32;
PageId id = new PageId("0", 0);
mPageStore.put(id, BufferUtils.getIncreasingByteArray(len));
for (int b = 1; b < len; b++) {
byte[] buf = new byte[b];
int bytesRead = mPageStore.get(id, 0, len, buf, 0);
assertEquals(b, bytesRead);
assertArrayEquals(BufferUtils.getIncreasingByteArray(b), Arrays.copyOfRange(buf, 0, bytesRead));
}
}
use of alluxio.client.file.cache.PageId in project alluxio by Alluxio.
the class LocalCacheManagerIntegrationTest method loadCacheAndEvict.
@Test
public void loadCacheAndEvict() throws Exception {
loadFullCache();
mCacheManager.close();
// creates with same configuration
mCacheManager = LocalCacheManager.create(mConf);
// evicts half of the pages
for (int i = 0; i < PAGE_COUNT / 2; i++) {
mCacheManager.put(new PageId("1", i), PAGE);
}
int evicted = 0;
for (int i = 0; i < PAGE_COUNT; i++) {
PageId pageId = new PageId("0", i);
int ret = mCacheManager.get(pageId, PAGE_SIZE_BYTES, mBuffer, 0);
assertArrayEquals(PAGE, mBuffer);
if (ret <= 0) {
evicted++;
continue;
}
assertEquals(PAGE_SIZE_BYTES, mCacheManager.get(pageId, PAGE_SIZE_BYTES, mBuffer, 0));
}
// verifies half of the loaded pages are evicted
assertEquals(PAGE_COUNT / 2, evicted);
// verifies the newly added pages are cached
for (int i = 0; i < PAGE_COUNT / 2; i++) {
testPageCached(new PageId("1", i));
}
}
use of alluxio.client.file.cache.PageId in project alluxio by Alluxio.
the class NondeterministicLRUCacheEvictor method evict.
@Nullable
@Override
public PageId evict() {
synchronized (mLRUCache) {
if (mLRUCache.isEmpty()) {
return null;
}
Iterator<PageId> it = mLRUCache.keySet().iterator();
PageId evictionCandidate = it.next();
int numMoveFromTail = ThreadLocalRandom.current().nextInt(mNumOfCandidate);
for (int i = 0; it.hasNext() && i < numMoveFromTail; ++i) {
evictionCandidate = it.next();
}
return evictionCandidate;
}
}
use of alluxio.client.file.cache.PageId in project alluxio by Alluxio.
the class LocalPageStore method getPageInfo.
/**
* @param path path of a file
* @return the corresponding page info for the file otherwise null
*/
@Nullable
private PageInfo getPageInfo(Path path) {
PageId pageId = getPageId(path);
long pageSize;
if (pageId == null) {
LOG.error("Unrecognized page file" + path);
return null;
}
try {
pageSize = Files.size(path);
} catch (IOException e) {
LOG.error("Failed to get file size for " + path, e);
return null;
}
return new PageInfo(pageId, pageSize);
}
Aggregations