Search in sources :

Example 1 with FetchedInput

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());
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) TezRuntimeConfiguration(org.apache.tez.runtime.library.api.TezRuntimeConfiguration) FetchedInput(org.apache.tez.runtime.library.common.shuffle.FetchedInput) InputAttemptIdentifier(org.apache.tez.runtime.library.common.InputAttemptIdentifier) Test(org.junit.Test)

Example 2 with FetchedInput

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;
}
Also used : FetchedInput(org.apache.tez.runtime.library.common.shuffle.FetchedInput)

Example 3 with 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));
}
Also used : LocalDiskFetchedInput(org.apache.tez.runtime.library.common.shuffle.LocalDiskFetchedInput) FetchedInput(org.apache.tez.runtime.library.common.shuffle.FetchedInput) Text(org.apache.hadoop.io.Text) InputAttemptIdentifier(org.apache.tez.runtime.library.common.InputAttemptIdentifier) TezCounter(org.apache.tez.common.counters.TezCounter) LinkedList(java.util.LinkedList) TezCounters(org.apache.tez.common.counters.TezCounters) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) FetchedInputCallback(org.apache.tez.runtime.library.common.shuffle.FetchedInputCallback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ShuffleManager(org.apache.tez.runtime.library.common.shuffle.impl.ShuffleManager) LocalDiskFetchedInput(org.apache.tez.runtime.library.common.shuffle.LocalDiskFetchedInput)

Aggregations

FetchedInput (org.apache.tez.runtime.library.common.shuffle.FetchedInput)3 InputAttemptIdentifier (org.apache.tez.runtime.library.common.InputAttemptIdentifier)2 LinkedList (java.util.LinkedList)1 Configuration (org.apache.hadoop.conf.Configuration)1 Text (org.apache.hadoop.io.Text)1 TezCounter (org.apache.tez.common.counters.TezCounter)1 TezCounters (org.apache.tez.common.counters.TezCounters)1 TezRuntimeConfiguration (org.apache.tez.runtime.library.api.TezRuntimeConfiguration)1 FetchedInputCallback (org.apache.tez.runtime.library.common.shuffle.FetchedInputCallback)1 LocalDiskFetchedInput (org.apache.tez.runtime.library.common.shuffle.LocalDiskFetchedInput)1 ShuffleManager (org.apache.tez.runtime.library.common.shuffle.impl.ShuffleManager)1 Test (org.junit.Test)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1