Search in sources :

Example 76 with MemorySize

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

the class TaskExecutorResourceUtilsTest method testCalculateTotalFlinkMemoryWithMissingFactors.

@Test(expected = IllegalArgumentException.class)
public void testCalculateTotalFlinkMemoryWithMissingFactors() {
    Configuration config = new Configuration();
    config.set(TaskManagerOptions.FRAMEWORK_HEAP_MEMORY, new MemorySize(1));
    config.set(TaskManagerOptions.FRAMEWORK_OFF_HEAP_MEMORY, new MemorySize(3));
    config.set(TaskManagerOptions.TASK_OFF_HEAP_MEMORY, new MemorySize(4));
    config.set(TaskManagerOptions.MANAGED_MEMORY_SIZE, new MemorySize(7));
    TaskExecutorResourceUtils.calculateTotalFlinkMemoryFromComponents(config);
}
Also used : MemorySize(org.apache.flink.configuration.MemorySize) Configuration(org.apache.flink.configuration.Configuration) Test(org.junit.Test)

Example 77 with MemorySize

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

the class ProcessMemoryUtils method deriveJvmMetaspaceAndOverheadFromTotalFlinkMemory.

public JvmMetaspaceAndOverhead deriveJvmMetaspaceAndOverheadFromTotalFlinkMemory(Configuration config, MemorySize totalFlinkMemorySize) {
    MemorySize jvmMetaspaceSize = getMemorySizeFromConfig(config, options.getJvmOptions().getJvmMetaspaceOption());
    MemorySize totalFlinkAndJvmMetaspaceSize = totalFlinkMemorySize.add(jvmMetaspaceSize);
    JvmMetaspaceAndOverhead jvmMetaspaceAndOverhead;
    if (config.contains(options.getTotalProcessMemoryOption())) {
        MemorySize jvmOverheadSize = deriveJvmOverheadFromTotalFlinkMemoryAndOtherComponents(config, totalFlinkMemorySize);
        jvmMetaspaceAndOverhead = new JvmMetaspaceAndOverhead(jvmMetaspaceSize, jvmOverheadSize);
    } else {
        MemorySize jvmOverheadSize = deriveWithInverseFraction("jvm overhead memory", totalFlinkAndJvmMetaspaceSize, getJvmOverheadRangeFraction(config));
        jvmMetaspaceAndOverhead = new JvmMetaspaceAndOverhead(jvmMetaspaceSize, jvmOverheadSize);
        sanityCheckTotalProcessMemory(config, totalFlinkMemorySize, jvmMetaspaceAndOverhead);
    }
    return jvmMetaspaceAndOverhead;
}
Also used : MemorySize(org.apache.flink.configuration.MemorySize)

Example 78 with MemorySize

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

the class ProcessMemoryUtils method deriveJvmOverheadFromTotalFlinkMemoryAndOtherComponents.

private MemorySize deriveJvmOverheadFromTotalFlinkMemoryAndOtherComponents(Configuration config, MemorySize totalFlinkMemorySize) {
    MemorySize totalProcessMemorySize = getMemorySizeFromConfig(config, options.getTotalProcessMemoryOption());
    MemorySize jvmMetaspaceSize = getMemorySizeFromConfig(config, options.getJvmOptions().getJvmMetaspaceOption());
    MemorySize totalFlinkAndJvmMetaspaceSize = totalFlinkMemorySize.add(jvmMetaspaceSize);
    if (totalProcessMemorySize.getBytes() < totalFlinkAndJvmMetaspaceSize.getBytes()) {
        throw new IllegalConfigurationException("The configured Total Process Memory size (%s) is less than the sum of the derived " + "Total Flink Memory size (%s) and the configured or default JVM Metaspace size  (%s).", totalProcessMemorySize.toHumanReadableString(), totalFlinkMemorySize.toHumanReadableString(), jvmMetaspaceSize.toHumanReadableString());
    }
    MemorySize jvmOverheadSize = totalProcessMemorySize.subtract(totalFlinkAndJvmMetaspaceSize);
    sanityCheckJvmOverhead(config, jvmOverheadSize, totalProcessMemorySize);
    return jvmOverheadSize;
}
Also used : MemorySize(org.apache.flink.configuration.MemorySize) IllegalConfigurationException(org.apache.flink.configuration.IllegalConfigurationException)

Example 79 with MemorySize

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

the class CheckpointStorageLoaderTest method testLoadFileSystemCheckpointStorage.

// ------------------------------------------------------------------------
// File System Checkpoint Storage
// ------------------------------------------------------------------------
/**
 * Validates loading a file system checkpoint storage with additional parameters from the
 * cluster configuration.
 */
@Test
public void testLoadFileSystemCheckpointStorage() throws Exception {
    final String checkpointDir = new Path(tmp.newFolder().toURI()).toString();
    final String savepointDir = new Path(tmp.newFolder().toURI()).toString();
    final Path expectedCheckpointsPath = new Path(checkpointDir);
    final Path expectedSavepointsPath = new Path(savepointDir);
    final MemorySize threshold = MemorySize.parse("900kb");
    final int minWriteBufferSize = 1024;
    // we configure with the explicit string (rather than
    // AbstractStateBackend#X_STATE_BACKEND_NAME)
    // to guard against config-breaking changes of the name
    final Configuration config1 = new Configuration();
    config1.set(CheckpointingOptions.CHECKPOINT_STORAGE, "filesystem");
    config1.set(CheckpointingOptions.CHECKPOINTS_DIRECTORY, checkpointDir);
    config1.set(CheckpointingOptions.SAVEPOINT_DIRECTORY, savepointDir);
    config1.set(CheckpointingOptions.FS_SMALL_FILE_THRESHOLD, threshold);
    config1.setInteger(CheckpointingOptions.FS_WRITE_BUFFER_SIZE, minWriteBufferSize);
    CheckpointStorage storage1 = CheckpointStorageLoader.fromConfig(config1, cl, null).get();
    Assert.assertThat(storage1, Matchers.instanceOf(FileSystemCheckpointStorage.class));
    FileSystemCheckpointStorage fs1 = (FileSystemCheckpointStorage) storage1;
    Assert.assertThat(fs1.getCheckpointPath(), normalizedPath(expectedCheckpointsPath));
    Assert.assertThat(fs1.getSavepointPath(), normalizedPath(expectedSavepointsPath));
    Assert.assertEquals(threshold.getBytes(), fs1.getMinFileSizeThreshold());
    Assert.assertEquals(Math.max(threshold.getBytes(), minWriteBufferSize), fs1.getWriteBufferSize());
}
Also used : Path(org.apache.flink.core.fs.Path) MemorySize(org.apache.flink.configuration.MemorySize) Configuration(org.apache.flink.configuration.Configuration) FileSystemCheckpointStorage(org.apache.flink.runtime.state.storage.FileSystemCheckpointStorage) JobManagerCheckpointStorage(org.apache.flink.runtime.state.storage.JobManagerCheckpointStorage) FileSystemCheckpointStorage(org.apache.flink.runtime.state.storage.FileSystemCheckpointStorage) Test(org.junit.Test)

Example 80 with MemorySize

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

the class StateBackendLoadingTest method testLoadFileSystemStateBackend.

// ------------------------------------------------------------------------
// File System State Backend
// ------------------------------------------------------------------------
/**
 * Validates loading a file system state backend with additional parameters from the cluster
 * configuration.
 */
@Test
public void testLoadFileSystemStateBackend() throws Exception {
    final String checkpointDir = new Path(tmp.newFolder().toURI()).toString();
    final String savepointDir = new Path(tmp.newFolder().toURI()).toString();
    final Path expectedCheckpointsPath = new Path(checkpointDir);
    final Path expectedSavepointsPath = new Path(savepointDir);
    final MemorySize threshold = MemorySize.parse("900kb");
    final int minWriteBufferSize = 1024;
    // we configure with the explicit string (rather than
    // AbstractStateBackend#X_STATE_BACKEND_NAME)
    // to guard against config-breaking changes of the name
    final Configuration config1 = new Configuration();
    config1.setString(backendKey, "filesystem");
    config1.setString(CheckpointingOptions.CHECKPOINTS_DIRECTORY, checkpointDir);
    config1.setString(CheckpointingOptions.SAVEPOINT_DIRECTORY, savepointDir);
    config1.set(CheckpointingOptions.FS_SMALL_FILE_THRESHOLD, threshold);
    config1.setInteger(CheckpointingOptions.FS_WRITE_BUFFER_SIZE, minWriteBufferSize);
    final Configuration config2 = new Configuration();
    config2.setString(backendKey, FsStateBackendFactory.class.getName());
    config2.setString(CheckpointingOptions.CHECKPOINTS_DIRECTORY, checkpointDir);
    config2.setString(CheckpointingOptions.SAVEPOINT_DIRECTORY, savepointDir);
    config2.set(CheckpointingOptions.FS_SMALL_FILE_THRESHOLD, threshold);
    config1.setInteger(CheckpointingOptions.FS_WRITE_BUFFER_SIZE, minWriteBufferSize);
    StateBackend backend1 = StateBackendLoader.loadStateBackendFromConfig(config1, cl, null);
    StateBackend backend2 = StateBackendLoader.loadStateBackendFromConfig(config2, cl, null);
    assertTrue(backend1 instanceof HashMapStateBackend);
    assertTrue(backend2 instanceof FsStateBackend);
    HashMapStateBackend fs1 = (HashMapStateBackend) backend1;
    FsStateBackend fs2 = (FsStateBackend) backend2;
    assertEquals(expectedCheckpointsPath, fs2.getCheckpointPath());
    assertEquals(expectedSavepointsPath, fs2.getSavepointPath());
    assertEquals(threshold.getBytes(), fs2.getMinFileSizeThreshold());
    assertEquals(Math.max(threshold.getBytes(), minWriteBufferSize), fs2.getWriteBufferSize());
}
Also used : Path(org.apache.flink.core.fs.Path) MemorySize(org.apache.flink.configuration.MemorySize) Configuration(org.apache.flink.configuration.Configuration) FsStateBackendFactory(org.apache.flink.runtime.state.filesystem.FsStateBackendFactory) HashMapStateBackend(org.apache.flink.runtime.state.hashmap.HashMapStateBackend) FsStateBackend(org.apache.flink.runtime.state.filesystem.FsStateBackend) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) HashMapStateBackend(org.apache.flink.runtime.state.hashmap.HashMapStateBackend) FsStateBackend(org.apache.flink.runtime.state.filesystem.FsStateBackend) Test(org.junit.Test)

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