Search in sources :

Example 46 with MemorySize

use of org.apache.flink.configuration.MemorySize in project flink by apache.

the class BufferDebloatConfigurationTest method testMinGreaterThanMaxBufferSize.

@Test
public void testMinGreaterThanMaxBufferSize() {
    final Configuration config = new Configuration();
    config.set(TaskManagerOptions.MIN_MEMORY_SEGMENT_SIZE, new MemorySize(50));
    config.set(TaskManagerOptions.MEMORY_SEGMENT_SIZE, new MemorySize(49));
    assertThrows(IllegalArgumentException.class, () -> BufferDebloatConfiguration.fromConfiguration(config));
}
Also used : MemorySize(org.apache.flink.configuration.MemorySize) Configuration(org.apache.flink.configuration.Configuration) Test(org.junit.jupiter.api.Test)

Example 47 with MemorySize

use of org.apache.flink.configuration.MemorySize in project flink by apache.

the class BucketAssignerITCases method testAssembleBucketPath.

@Test
public void testAssembleBucketPath() throws Exception {
    final File outDir = TEMP_FOLDER.newFolder();
    final Path basePath = new Path(outDir.toURI());
    final long time = 1000L;
    final RollingPolicy<String, String> rollingPolicy = DefaultRollingPolicy.builder().withMaxPartSize(new MemorySize(7L)).build();
    final Buckets<String, String> buckets = new Buckets<>(basePath, new BasePathBucketAssigner<>(), new DefaultBucketFactoryImpl<>(), new RowWiseBucketWriter<>(FileSystem.get(basePath.toUri()).createRecoverableWriter(), new SimpleStringEncoder<>()), rollingPolicy, 0, OutputFileConfig.builder().build());
    Bucket<String, String> bucket = buckets.onElement("abc", new TestUtils.MockSinkContext(time, time, time));
    Assert.assertEquals(new Path(basePath.toUri()), bucket.getBucketPath());
}
Also used : Path(org.apache.flink.core.fs.Path) MemorySize(org.apache.flink.configuration.MemorySize) SimpleStringEncoder(org.apache.flink.api.common.serialization.SimpleStringEncoder) File(java.io.File) Test(org.junit.Test)

Example 48 with MemorySize

use of org.apache.flink.configuration.MemorySize in project flink by apache.

the class BucketsTest method testMergeAtScaleInAndMaxCounterAtRecovery.

@Test
public void testMergeAtScaleInAndMaxCounterAtRecovery() throws Exception {
    final File outDir = TEMP_FOLDER.newFolder();
    final Path path = new Path(outDir.toURI());
    final RollingPolicy<String, String> onCheckpointRP = DefaultRollingPolicy.builder().withMaxPartSize(// roll with 2 elements
    new MemorySize(7L)).build();
    final MockListState<byte[]> bucketStateContainerOne = new MockListState<>();
    final MockListState<byte[]> bucketStateContainerTwo = new MockListState<>();
    final MockListState<Long> partCounterContainerOne = new MockListState<>();
    final MockListState<Long> partCounterContainerTwo = new MockListState<>();
    final Buckets<String, String> bucketsOne = createBuckets(path, onCheckpointRP, 0);
    final Buckets<String, String> bucketsTwo = createBuckets(path, onCheckpointRP, 1);
    bucketsOne.onElement("test1", new TestUtils.MockSinkContext(null, 1L, 2L));
    bucketsOne.snapshotState(0L, bucketStateContainerOne, partCounterContainerOne);
    Assert.assertEquals(1L, bucketsOne.getMaxPartCounter());
    // make sure we have one in-progress file here
    Assert.assertNotNull(bucketsOne.getActiveBuckets().get("test1").getInProgressPart());
    // add a couple of in-progress files so that the part counter increases.
    bucketsTwo.onElement("test1", new TestUtils.MockSinkContext(null, 1L, 2L));
    bucketsTwo.onElement("test1", new TestUtils.MockSinkContext(null, 1L, 2L));
    bucketsTwo.onElement("test1", new TestUtils.MockSinkContext(null, 1L, 2L));
    bucketsTwo.snapshotState(0L, bucketStateContainerTwo, partCounterContainerTwo);
    Assert.assertEquals(2L, bucketsTwo.getMaxPartCounter());
    // make sure we have one in-progress file here and a pending
    Assert.assertEquals(1L, bucketsTwo.getActiveBuckets().get("test1").getPendingFileRecoverablesPerCheckpoint().size());
    Assert.assertNotNull(bucketsTwo.getActiveBuckets().get("test1").getInProgressPart());
    final ListState<byte[]> mergedBucketStateContainer = new MockListState<>();
    final ListState<Long> mergedPartCounterContainer = new MockListState<>();
    mergedBucketStateContainer.addAll(bucketStateContainerOne.getBackingList());
    mergedBucketStateContainer.addAll(bucketStateContainerTwo.getBackingList());
    mergedPartCounterContainer.addAll(partCounterContainerOne.getBackingList());
    mergedPartCounterContainer.addAll(partCounterContainerTwo.getBackingList());
    final Buckets<String, String> restoredBuckets = restoreBuckets(path, onCheckpointRP, 0, mergedBucketStateContainer, mergedPartCounterContainer);
    // we get the maximum of the previous tasks
    Assert.assertEquals(2L, restoredBuckets.getMaxPartCounter());
    final Map<String, Bucket<String, String>> activeBuckets = restoredBuckets.getActiveBuckets();
    Assert.assertEquals(1L, activeBuckets.size());
    Assert.assertTrue(activeBuckets.keySet().contains("test1"));
    final Bucket<String, String> bucket = activeBuckets.get("test1");
    Assert.assertEquals("test1", bucket.getBucketId());
    Assert.assertEquals(new Path(path, "test1"), bucket.getBucketPath());
    // the restored part file
    Assert.assertNotNull(bucket.getInProgressPart());
    // this is due to the Bucket#merge(). The in progress file of one
    // of the previous tasks is put in the list of pending files.
    Assert.assertEquals(1L, bucket.getPendingFileRecoverablesForCurrentCheckpoint().size());
    // we commit the pending for previous checkpoints
    Assert.assertTrue(bucket.getPendingFileRecoverablesPerCheckpoint().isEmpty());
}
Also used : Path(org.apache.flink.core.fs.Path) MemorySize(org.apache.flink.configuration.MemorySize) MockListState(org.apache.flink.streaming.api.functions.sink.filesystem.TestUtils.MockListState) File(java.io.File) Test(org.junit.Test)

Example 49 with MemorySize

use of org.apache.flink.configuration.MemorySize in project flink by apache.

the class JobManagerFlinkMemoryUtils method deriveFromRequiredFineGrainedOptions.

@Override
public JobManagerFlinkMemory deriveFromRequiredFineGrainedOptions(Configuration config) {
    MemorySize jvmHeapMemorySize = ProcessMemoryUtils.getMemorySizeFromConfig(config, JobManagerOptions.JVM_HEAP_MEMORY);
    MemorySize offHeapMemorySize = ProcessMemoryUtils.getMemorySizeFromConfig(config, JobManagerOptions.OFF_HEAP_MEMORY);
    if (config.contains(JobManagerOptions.TOTAL_FLINK_MEMORY)) {
        // derive network memory from total flink memory, and check against network min/max
        MemorySize totalFlinkMemorySize = ProcessMemoryUtils.getMemorySizeFromConfig(config, JobManagerOptions.TOTAL_FLINK_MEMORY);
        if (config.contains(JobManagerOptions.OFF_HEAP_MEMORY)) {
            // off-heap memory is explicitly set by user
            sanityCheckTotalFlinkMemory(totalFlinkMemorySize, jvmHeapMemorySize, offHeapMemorySize);
        } else {
            // off-heap memory is not explicitly set by user, derive it from Total Flink Memory
            // and JVM Heap
            offHeapMemorySize = deriveOffHeapMemory(jvmHeapMemorySize, totalFlinkMemorySize, offHeapMemorySize);
        }
    }
    return createJobManagerFlinkMemory(jvmHeapMemorySize, offHeapMemorySize);
}
Also used : MemorySize(org.apache.flink.configuration.MemorySize)

Example 50 with MemorySize

use of org.apache.flink.configuration.MemorySize in project flink by apache.

the class TaskExecutorFlinkMemoryUtils method deriveFromTotalFlinkMemory.

@Override
public TaskExecutorFlinkMemory deriveFromTotalFlinkMemory(final Configuration config, final MemorySize totalFlinkMemorySize) {
    final MemorySize frameworkHeapMemorySize = getFrameworkHeapMemorySize(config);
    final MemorySize frameworkOffHeapMemorySize = getFrameworkOffHeapMemorySize(config);
    final MemorySize taskOffHeapMemorySize = getTaskOffHeapMemorySize(config);
    final MemorySize taskHeapMemorySize;
    final MemorySize networkMemorySize;
    final MemorySize managedMemorySize;
    if (isTaskHeapMemorySizeExplicitlyConfigured(config)) {
        // task heap memory is configured,
        // derive managed memory first, leave the remaining to network memory and check against
        // network min/max
        taskHeapMemorySize = getTaskHeapMemorySize(config);
        managedMemorySize = deriveManagedMemoryAbsoluteOrWithFraction(config, totalFlinkMemorySize);
        final MemorySize totalFlinkExcludeNetworkMemorySize = frameworkHeapMemorySize.add(frameworkOffHeapMemorySize).add(taskHeapMemorySize).add(taskOffHeapMemorySize).add(managedMemorySize);
        if (totalFlinkExcludeNetworkMemorySize.getBytes() > totalFlinkMemorySize.getBytes()) {
            throw new IllegalConfigurationException("Sum of configured Framework Heap Memory (" + frameworkHeapMemorySize.toHumanReadableString() + "), Framework Off-Heap Memory (" + frameworkOffHeapMemorySize.toHumanReadableString() + "), Task Heap Memory (" + taskHeapMemorySize.toHumanReadableString() + "), Task Off-Heap Memory (" + taskOffHeapMemorySize.toHumanReadableString() + ") and Managed Memory (" + managedMemorySize.toHumanReadableString() + ") exceed configured Total Flink Memory (" + totalFlinkMemorySize.toHumanReadableString() + ").");
        }
        networkMemorySize = totalFlinkMemorySize.subtract(totalFlinkExcludeNetworkMemorySize);
        sanityCheckNetworkMemoryWithExplicitlySetTotalFlinkAndHeapMemory(config, networkMemorySize, totalFlinkMemorySize);
    } else {
        // task heap memory is not configured
        // derive managed memory and network memory, leave the remaining to task heap memory
        managedMemorySize = deriveManagedMemoryAbsoluteOrWithFraction(config, totalFlinkMemorySize);
        networkMemorySize = isUsingLegacyNetworkConfigs(config) ? getNetworkMemorySizeWithLegacyConfig(config) : deriveNetworkMemoryWithFraction(config, totalFlinkMemorySize);
        final MemorySize totalFlinkExcludeTaskHeapMemorySize = frameworkHeapMemorySize.add(frameworkOffHeapMemorySize).add(taskOffHeapMemorySize).add(managedMemorySize).add(networkMemorySize);
        if (totalFlinkExcludeTaskHeapMemorySize.getBytes() > totalFlinkMemorySize.getBytes()) {
            throw new IllegalConfigurationException("Sum of configured Framework Heap Memory (" + frameworkHeapMemorySize.toHumanReadableString() + "), Framework Off-Heap Memory (" + frameworkOffHeapMemorySize.toHumanReadableString() + "), Task Off-Heap Memory (" + taskOffHeapMemorySize.toHumanReadableString() + "), Managed Memory (" + managedMemorySize.toHumanReadableString() + ") and Network Memory (" + networkMemorySize.toHumanReadableString() + ") exceed configured Total Flink Memory (" + totalFlinkMemorySize.toHumanReadableString() + ").");
        }
        taskHeapMemorySize = totalFlinkMemorySize.subtract(totalFlinkExcludeTaskHeapMemorySize);
    }
    final TaskExecutorFlinkMemory flinkInternalMemory = new TaskExecutorFlinkMemory(frameworkHeapMemorySize, frameworkOffHeapMemorySize, taskHeapMemorySize, taskOffHeapMemorySize, networkMemorySize, managedMemorySize);
    sanityCheckTotalFlinkMemory(config, flinkInternalMemory);
    return flinkInternalMemory;
}
Also used : MemorySize(org.apache.flink.configuration.MemorySize) IllegalConfigurationException(org.apache.flink.configuration.IllegalConfigurationException)

Aggregations

MemorySize (org.apache.flink.configuration.MemorySize)81 Test (org.junit.Test)56 Configuration (org.apache.flink.configuration.Configuration)51 IllegalConfigurationException (org.apache.flink.configuration.IllegalConfigurationException)6 Path (org.apache.flink.core.fs.Path)5 File (java.io.File)4 ArrayList (java.util.ArrayList)3 CPUResource (org.apache.flink.api.common.resources.CPUResource)3 FileSourceSplit (org.apache.flink.connector.file.src.FileSourceSplit)2 BulkFormat (org.apache.flink.connector.file.src.reader.BulkFormat)2 ExecutionJobVertex (org.apache.flink.runtime.executiongraph.ExecutionJobVertex)2 IntermediateResultPartitionTest (org.apache.flink.runtime.executiongraph.IntermediateResultPartitionTest)2 SlotSharingGroup (org.apache.flink.runtime.jobmanager.scheduler.SlotSharingGroup)2 TaskExecutorFlinkMemory (org.apache.flink.runtime.util.config.memory.taskmanager.TaskExecutorFlinkMemory)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1 ResourceSpec (org.apache.flink.api.common.operators.ResourceSpec)1