Search in sources :

Example 31 with MemoryManager

use of org.apache.flink.runtime.memory.MemoryManager in project flink by apache.

the class BinaryHashTableTest method testSpillingHashJoinOneRecursionPerformance.

@Test
public void testSpillingHashJoinOneRecursionPerformance() throws IOException {
    final int numKeys = 1000000;
    final int buildValsPerKey = 3;
    final int probeValsPerKey = 10;
    // create a build input that gives 3 million pairs with 3 values sharing the same key
    MutableObjectIterator<BinaryRowData> buildInput = new UniformBinaryRowGenerator(numKeys, buildValsPerKey, false);
    // create a probe input that gives 10 million pairs with 10 values sharing a key
    MutableObjectIterator<BinaryRowData> probeInput = new UniformBinaryRowGenerator(numKeys, probeValsPerKey, true);
    // allocate the memory for the HashTable
    MemoryManager memManager = MemoryManagerBuilder.newBuilder().setMemorySize(200 * PAGE_SIZE).setPageSize(PAGE_SIZE).build();
    final BinaryHashTable table = newBinaryHashTable(this.buildSideSerializer, this.probeSideSerializer, new MyProjection(), new MyProjection(), memManager, 100 * PAGE_SIZE, ioManager);
    // ----------------------------------------------------------------------------------------
    int numRecordsInJoinResult = join(table, buildInput, probeInput);
    Assert.assertEquals("Wrong number of records in join result.", numKeys * buildValsPerKey * probeValsPerKey, numRecordsInJoinResult);
    table.close();
    // ----------------------------------------------------------------------------------------
    table.free();
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) MemoryManager(org.apache.flink.runtime.memory.MemoryManager) UniformBinaryRowGenerator(org.apache.flink.table.runtime.util.UniformBinaryRowGenerator) Test(org.junit.Test)

Example 32 with MemoryManager

use of org.apache.flink.runtime.memory.MemoryManager in project flink by apache.

the class BinaryHashTableTest method testHashWithBuildSideOuterJoin2.

@Test
public void testHashWithBuildSideOuterJoin2() throws Exception {
    final int numKeys = 40000;
    final int buildValsPerKey = 2;
    final int probeValsPerKey = 1;
    // The keys of probe and build sides are overlapped, so there would be none unmatched build
    // elements
    // after probe phase, make sure build side outer join works well in this case.
    // create a build input that gives 80000 pairs with 2 values sharing the same key
    MutableObjectIterator<BinaryRowData> buildInput = new UniformBinaryRowGenerator(numKeys, buildValsPerKey, false);
    // create a probe input that gives 40000 pairs with 1 values sharing a key
    MutableObjectIterator<BinaryRowData> probeInput = new UniformBinaryRowGenerator(numKeys, probeValsPerKey, true);
    // allocate the memory for the HashTable
    MemoryManager memManager = MemoryManagerBuilder.newBuilder().setMemorySize(35 * PAGE_SIZE).build();
    final BinaryHashTable table = newBinaryHashTable(this.buildSideSerializer, this.probeSideSerializer, new MyProjection(), new MyProjection(), memManager, 33 * PAGE_SIZE, ioManager);
    // ----------------------------------------------------------------------------------------
    int numRecordsInJoinResult = join(table, buildInput, probeInput, true);
    Assert.assertEquals("Wrong number of records in join result.", numKeys * buildValsPerKey * probeValsPerKey, numRecordsInJoinResult);
    table.close();
    table.free();
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) MemoryManager(org.apache.flink.runtime.memory.MemoryManager) UniformBinaryRowGenerator(org.apache.flink.table.runtime.util.UniformBinaryRowGenerator) Test(org.junit.Test)

Example 33 with MemoryManager

use of org.apache.flink.runtime.memory.MemoryManager in project flink by apache.

the class HashAggTest method before.

@Before
public void before() throws Exception {
    ioManager = new IOManagerAsync();
    operator = new SumHashAggTestOperator(40 * 32 * 1024) {

        @Override
        Object getOwner() {
            return HashAggTest.this;
        }

        @Override
        MemoryManager getMemoryManager() {
            return memoryManager;
        }

        @Override
        Collector<StreamRecord<RowData>> getOutput() {
            return new Collector<StreamRecord<RowData>>() {

                @Override
                public void collect(StreamRecord<RowData> record) {
                    RowData row = record.getValue();
                    outputMap.put(row.isNullAt(0) ? null : row.getInt(0), row.isNullAt(1) ? null : row.getLong(1));
                }

                @Override
                public void close() {
                }
            };
        }

        @Override
        Configuration getConf() {
            return new Configuration();
        }

        @Override
        public IOManager getIOManager() {
            return ioManager;
        }
    };
    operator.open();
}
Also used : RowData(org.apache.flink.table.data.RowData) GenericRowData(org.apache.flink.table.data.GenericRowData) StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) IOManagerAsync(org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync) Configuration(org.apache.flink.configuration.Configuration) IOManager(org.apache.flink.runtime.io.disk.iomanager.IOManager) Collector(org.apache.flink.util.Collector) MemoryManager(org.apache.flink.runtime.memory.MemoryManager) Before(org.junit.Before)

Example 34 with MemoryManager

use of org.apache.flink.runtime.memory.MemoryManager in project flink by apache.

the class BinaryHashTableTest method testSpillingHashJoinWithTwoRecursions.

/*
     * This test is basically identical to the "testSpillingHashJoinWithMassiveCollisions" test, only that the number
     * of repeated values (causing bucket collisions) are large enough to make sure that their target partition no longer
     * fits into memory by itself and needs to be repartitioned in the recursion again.
     */
@Test
public void testSpillingHashJoinWithTwoRecursions() throws IOException {
    // the following two values are known to have a hash-code collision on the first recursion
    // level.
    // we use them to make sure one partition grows over-proportionally large
    final int repeatedValue1 = 40559;
    final int repeatedValue2 = 92882;
    final int repeatedValueCountBuild = 200000;
    final int repeatedValueCountProbe = 5;
    final int numKeys = 1000000;
    final int buildValsPerKey = 3;
    final int probeValsPerKey = 10;
    // create a build input that gives 3 million pairs with 3 values sharing the same key, plus
    // 400k pairs with two colliding keys
    MutableObjectIterator<BinaryRowData> build1 = new UniformBinaryRowGenerator(numKeys, buildValsPerKey, false);
    MutableObjectIterator<BinaryRowData> build2 = new ConstantsKeyValuePairsIterator(repeatedValue1, 17, repeatedValueCountBuild);
    MutableObjectIterator<BinaryRowData> build3 = new ConstantsKeyValuePairsIterator(repeatedValue2, 23, repeatedValueCountBuild);
    List<MutableObjectIterator<BinaryRowData>> builds = new ArrayList<>();
    builds.add(build1);
    builds.add(build2);
    builds.add(build3);
    MutableObjectIterator<BinaryRowData> buildInput = new UnionIterator<>(builds);
    // create a probe input that gives 10 million pairs with 10 values sharing a key
    MutableObjectIterator<BinaryRowData> probe1 = new UniformBinaryRowGenerator(numKeys, probeValsPerKey, true);
    MutableObjectIterator<BinaryRowData> probe2 = new ConstantsKeyValuePairsIterator(repeatedValue1, 17, 5);
    MutableObjectIterator<BinaryRowData> probe3 = new ConstantsKeyValuePairsIterator(repeatedValue2, 23, 5);
    List<MutableObjectIterator<BinaryRowData>> probes = new ArrayList<>();
    probes.add(probe1);
    probes.add(probe2);
    probes.add(probe3);
    MutableObjectIterator<BinaryRowData> probeInput = new UnionIterator<>(probes);
    // create the map for validating the results
    HashMap<Integer, Long> map = new HashMap<>(numKeys);
    // ----------------------------------------------------------------------------------------
    MemoryManager memManager = MemoryManagerBuilder.newBuilder().setMemorySize(896 * PAGE_SIZE).build();
    final BinaryHashTable table = newBinaryHashTable(this.buildSideSerializer, this.probeSideSerializer, new MyProjection(), new MyProjection(), memManager, 896 * PAGE_SIZE, ioManager);
    final BinaryRowData recordReuse = new BinaryRowData(2);
    BinaryRowData buildRow = buildSideSerializer.createInstance();
    while ((buildRow = buildInput.next(buildRow)) != null) {
        table.putBuildRow(buildRow);
    }
    table.endBuild();
    BinaryRowData probeRow = probeSideSerializer.createInstance();
    while ((probeRow = probeInput.next(probeRow)) != null) {
        if (table.tryProbe(probeRow)) {
            testJoin(table, map);
        }
    }
    while (table.nextMatching()) {
        testJoin(table, map);
    }
    table.close();
    Assert.assertEquals("Wrong number of keys", numKeys, map.size());
    for (Map.Entry<Integer, Long> entry : map.entrySet()) {
        long val = entry.getValue();
        int key = entry.getKey();
        Assert.assertEquals("Wrong number of values in per-key cross product for key " + key, (key == repeatedValue1 || key == repeatedValue2) ? (probeValsPerKey + repeatedValueCountProbe) * (buildValsPerKey + repeatedValueCountBuild) : probeValsPerKey * buildValsPerKey, val);
    }
    // ----------------------------------------------------------------------------------------
    table.free();
}
Also used : MutableObjectIterator(org.apache.flink.util.MutableObjectIterator) UnionIterator(org.apache.flink.runtime.operators.testutils.UnionIterator) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MemoryManager(org.apache.flink.runtime.memory.MemoryManager) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) HashMap(java.util.HashMap) Map(java.util.Map) UniformBinaryRowGenerator(org.apache.flink.table.runtime.util.UniformBinaryRowGenerator) Test(org.junit.Test)

Example 35 with MemoryManager

use of org.apache.flink.runtime.memory.MemoryManager in project flink by apache.

the class TaskSlotTest method testTaskSlotClosedOnlyWhenAddedTasksTerminated.

@Test
public void testTaskSlotClosedOnlyWhenAddedTasksTerminated() throws Exception {
    try (TaskSlot<TaskSlotPayload> taskSlot = createTaskSlot()) {
        taskSlot.markActive();
        TestingTaskSlotPayload task = new TestingTaskSlotPayload(JOB_ID, new ExecutionAttemptID(), ALLOCATION_ID);
        taskSlot.add(task);
        CompletableFuture<Void> closingFuture = taskSlot.closeAsync();
        task.waitForFailure();
        MemoryManager memoryManager = taskSlot.getMemoryManager();
        assertThat(closingFuture.isDone(), is(false));
        assertThat(memoryManager.isShutdown(), is(false));
        task.terminate();
        closingFuture.get();
        assertThat(memoryManager.isShutdown(), is(true));
    }
}
Also used : ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) MemoryManager(org.apache.flink.runtime.memory.MemoryManager) Test(org.junit.Test)

Aggregations

MemoryManager (org.apache.flink.runtime.memory.MemoryManager)69 Test (org.junit.Test)37 IOManager (org.apache.flink.runtime.io.disk.iomanager.IOManager)22 BinaryRowData (org.apache.flink.table.data.binary.BinaryRowData)21 IOManagerAsync (org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync)18 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)14 DummyInvokable (org.apache.flink.runtime.operators.testutils.DummyInvokable)14 UniformBinaryRowGenerator (org.apache.flink.table.runtime.util.UniformBinaryRowGenerator)14 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)13 MemorySegment (org.apache.flink.core.memory.MemorySegment)12 Configuration (org.apache.flink.configuration.Configuration)9 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)8 TypeHint (org.apache.flink.api.common.typeinfo.TypeHint)7 TupleTypeInfo (org.apache.flink.api.java.typeutils.TupleTypeInfo)7 File (java.io.File)6 MutableObjectIterator (org.apache.flink.util.MutableObjectIterator)6 Map (java.util.Map)5 AbstractInvokable (org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable)5 BufferedReader (java.io.BufferedReader)4