use of org.apache.tez.runtime.library.common.shuffle.FetchedInput in project tez by apache.
the class TestSimpleFetchedInputAllocator method testInMemAllocation.
@Test(timeout = 5000)
public void testInMemAllocation() throws IOException {
String localDirs = "/tmp/" + this.getClass().getName();
Configuration conf = new Configuration();
long jvmMax = Runtime.getRuntime().maxMemory();
LOG.info("jvmMax: " + jvmMax);
float bufferPercent = 0.1f;
conf.setFloat(TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_FETCH_BUFFER_PERCENT, bufferPercent);
conf.setFloat(TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_MEMORY_LIMIT_PERCENT, 1.0f);
conf.setStrings(TezRuntimeFrameworkConfigs.LOCAL_DIRS, localDirs);
long inMemThreshold = (long) (bufferPercent * jvmMax);
LOG.info("InMemThreshold: " + inMemThreshold);
SimpleFetchedInputAllocator inputManager = new SimpleFetchedInputAllocator("srcName", UUID.randomUUID().toString(), 123, conf, Runtime.getRuntime().maxMemory(), inMemThreshold);
long requestSize = (long) (0.4f * inMemThreshold);
long compressedSize = 1l;
LOG.info("RequestSize: " + requestSize);
FetchedInput fi1 = inputManager.allocate(requestSize, compressedSize, new InputAttemptIdentifier(1, 1));
assertEquals(FetchedInput.Type.MEMORY, fi1.getType());
FetchedInput fi2 = inputManager.allocate(requestSize, compressedSize, new InputAttemptIdentifier(2, 1));
assertEquals(FetchedInput.Type.MEMORY, fi2.getType());
// Over limit by this point. Next reserve should give back a DISK allocation
FetchedInput fi3 = inputManager.allocate(requestSize, compressedSize, new InputAttemptIdentifier(3, 1));
assertEquals(FetchedInput.Type.DISK, fi3.getType());
// Freed one memory allocation. Next should be mem again.
fi1.abort();
fi1.free();
FetchedInput fi4 = inputManager.allocate(requestSize, compressedSize, new InputAttemptIdentifier(4, 1));
assertEquals(FetchedInput.Type.MEMORY, fi4.getType());
// Freed one disk allocation. Next sould be disk again (no mem freed)
fi3.abort();
fi3.free();
FetchedInput fi5 = inputManager.allocate(requestSize, compressedSize, new InputAttemptIdentifier(4, 1));
assertEquals(FetchedInput.Type.DISK, fi5.getType());
}
use of org.apache.tez.runtime.library.common.shuffle.FetchedInput in project tez by apache.
the class ShuffleManager method getNextInput.
/**
* @return the next available input, or null if there are no available inputs.
* This method will block if there are currently no available inputs,
* but more may become available.
*/
public FetchedInput getNextInput() throws InterruptedException {
// Check for no additional inputs
lock.lock();
try {
if (completedInputs.peek() == null && allInputsFetched()) {
return null;
}
} finally {
lock.unlock();
}
// Block until next input or End of Input message
FetchedInput fetchedInput = completedInputs.take();
if (fetchedInput instanceof NullFetchedInput) {
fetchedInput = null;
}
return fetchedInput;
}
use of org.apache.tez.runtime.library.common.shuffle.FetchedInput in project tez by apache.
the class TestUnorderedKVReader method setupReader.
private void setupReader() throws IOException, InterruptedException {
defaultConf.set(TezRuntimeConfiguration.TEZ_RUNTIME_KEY_CLASS, Text.class.getName());
defaultConf.set(TezRuntimeConfiguration.TEZ_RUNTIME_VALUE_CLASS, Text.class.getName());
createIFile(outputPath, 1);
final LinkedList<LocalDiskFetchedInput> inputs = new LinkedList<LocalDiskFetchedInput>();
LocalDiskFetchedInput realFetchedInput = new LocalDiskFetchedInput(0, compLen, new InputAttemptIdentifier(0, 0), outputPath, defaultConf, new FetchedInputCallback() {
@Override
public void fetchComplete(FetchedInput fetchedInput) {
}
@Override
public void fetchFailed(FetchedInput fetchedInput) {
}
@Override
public void freeResources(FetchedInput fetchedInput) {
}
});
LocalDiskFetchedInput fetchedInput = spy(realFetchedInput);
doNothing().when(fetchedInput).free();
inputs.add(fetchedInput);
TezCounters counters = new TezCounters();
TezCounter inputRecords = counters.findCounter(TaskCounter.INPUT_RECORDS_PROCESSED);
ShuffleManager manager = mock(ShuffleManager.class);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
return (inputs.isEmpty()) ? null : inputs.remove();
}
}).when(manager).getNextInput();
unorderedKVReader = new UnorderedKVReader<Text, Text>(manager, defaultConf, null, false, -1, -1, inputRecords, mock(InputContext.class));
}
Aggregations