Search in sources :

Example 6 with ManagedMemoryUseCase

use of org.apache.flink.core.memory.ManagedMemoryUseCase in project flink by apache.

the class ManagedMemoryUtilsTest method testConvertToFractionOfSlot.

@Test
public void testConvertToFractionOfSlot() {
    final ManagedMemoryUseCase useCase = ManagedMemoryUseCase.OPERATOR;
    final double fractionOfUseCase = 0.3;
    final double fractionOfSlot = ManagedMemoryUtils.convertToFractionOfSlot(useCase, fractionOfUseCase, new HashSet<ManagedMemoryUseCase>() {

        {
            add(ManagedMemoryUseCase.OPERATOR);
            add(ManagedMemoryUseCase.STATE_BACKEND);
            add(ManagedMemoryUseCase.PYTHON);
        }
    }, CONFIG_WITH_ALL_USE_CASES, Optional.of(true), ClassLoader.getSystemClassLoader());
    assertEquals(fractionOfUseCase * OPERATOR_WEIGHT / TOTAL_WEIGHT, fractionOfSlot, DELTA);
}
Also used : ManagedMemoryUseCase(org.apache.flink.core.memory.ManagedMemoryUseCase) Test(org.junit.Test)

Example 7 with ManagedMemoryUseCase

use of org.apache.flink.core.memory.ManagedMemoryUseCase in project flink by apache.

the class ManagedMemoryUtilsTest method testConvertToFractionOfSlotWeightNotConfigured.

@Test
public void testConvertToFractionOfSlotWeightNotConfigured() {
    final ManagedMemoryUseCase useCase = ManagedMemoryUseCase.OPERATOR;
    final double fractionOfUseCase = 0.3;
    final Configuration config = new Configuration() {

        {
            set(TaskManagerOptions.MANAGED_MEMORY_CONSUMER_WEIGHTS, Collections.emptyMap());
        }
    };
    final double fractionOfSlot = ManagedMemoryUtils.convertToFractionOfSlot(useCase, fractionOfUseCase, new HashSet<ManagedMemoryUseCase>() {

        {
            add(ManagedMemoryUseCase.OPERATOR);
            add(ManagedMemoryUseCase.STATE_BACKEND);
            add(ManagedMemoryUseCase.PYTHON);
        }
    }, config, Optional.of(true), ClassLoader.getSystemClassLoader());
    assertEquals(0.0, fractionOfSlot, DELTA);
}
Also used : Configuration(org.apache.flink.configuration.Configuration) UnmodifiableConfiguration(org.apache.flink.configuration.UnmodifiableConfiguration) ManagedMemoryUseCase(org.apache.flink.core.memory.ManagedMemoryUseCase) Test(org.junit.Test)

Example 8 with ManagedMemoryUseCase

use of org.apache.flink.core.memory.ManagedMemoryUseCase in project flink by apache.

the class StreamingJobGraphGenerator method setManagedMemoryFractionForSlotSharingGroup.

private static void setManagedMemoryFractionForSlotSharingGroup(final SlotSharingGroup slotSharingGroup, final Map<JobVertexID, Integer> vertexHeadOperators, final Map<JobVertexID, Set<Integer>> vertexOperators, final Map<Integer, StreamConfig> operatorConfigs, final Map<Integer, Map<Integer, StreamConfig>> vertexChainedConfigs, final java.util.function.Function<Integer, Map<ManagedMemoryUseCase, Integer>> operatorScopeManagedMemoryUseCaseWeightsRetriever, final java.util.function.Function<Integer, Set<ManagedMemoryUseCase>> slotScopeManagedMemoryUseCasesRetriever) {
    final Set<Integer> groupOperatorIds = slotSharingGroup.getJobVertexIds().stream().flatMap((vid) -> vertexOperators.get(vid).stream()).collect(Collectors.toSet());
    final Map<ManagedMemoryUseCase, Integer> groupOperatorScopeUseCaseWeights = groupOperatorIds.stream().flatMap((oid) -> operatorScopeManagedMemoryUseCaseWeightsRetriever.apply(oid).entrySet().stream()).collect(Collectors.groupingBy(Map.Entry::getKey, Collectors.summingInt(Map.Entry::getValue)));
    final Set<ManagedMemoryUseCase> groupSlotScopeUseCases = groupOperatorIds.stream().flatMap((oid) -> slotScopeManagedMemoryUseCasesRetriever.apply(oid).stream()).collect(Collectors.toSet());
    for (JobVertexID jobVertexID : slotSharingGroup.getJobVertexIds()) {
        for (int operatorNodeId : vertexOperators.get(jobVertexID)) {
            final StreamConfig operatorConfig = operatorConfigs.get(operatorNodeId);
            final Map<ManagedMemoryUseCase, Integer> operatorScopeUseCaseWeights = operatorScopeManagedMemoryUseCaseWeightsRetriever.apply(operatorNodeId);
            final Set<ManagedMemoryUseCase> slotScopeUseCases = slotScopeManagedMemoryUseCasesRetriever.apply(operatorNodeId);
            setManagedMemoryFractionForOperator(operatorScopeUseCaseWeights, slotScopeUseCases, groupOperatorScopeUseCaseWeights, groupSlotScopeUseCases, operatorConfig);
        }
        // need to refresh the chained task configs because they are serialized
        final int headOperatorNodeId = vertexHeadOperators.get(jobVertexID);
        final StreamConfig vertexConfig = operatorConfigs.get(headOperatorNodeId);
        vertexConfig.setTransitiveChainedTaskConfigs(vertexChainedConfigs.get(headOperatorNodeId));
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays(java.util.Arrays) DefaultLogicalPipelinedRegion(org.apache.flink.runtime.jobgraph.topology.DefaultLogicalPipelinedRegion) InputSelectable(org.apache.flink.streaming.api.operators.InputSelectable) Tuple2(org.apache.flink.api.java.tuple.Tuple2) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) CheckpointingMode(org.apache.flink.streaming.api.CheckpointingMode) YieldingOperatorFactory(org.apache.flink.streaming.api.operators.YieldingOperatorFactory) LoggerFactory(org.slf4j.LoggerFactory) CheckpointCoordinatorConfiguration(org.apache.flink.runtime.jobgraph.tasks.CheckpointCoordinatorConfiguration) CheckpointStorage(org.apache.flink.runtime.state.CheckpointStorage) CoLocationGroupImpl(org.apache.flink.runtime.jobmanager.scheduler.CoLocationGroupImpl) StringUtils(org.apache.commons.lang3.StringUtils) StateBackend(org.apache.flink.runtime.state.StateBackend) ChainingStrategy(org.apache.flink.streaming.api.operators.ChainingStrategy) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ResourceSpec(org.apache.flink.api.common.operators.ResourceSpec) ManagedMemoryUseCase(org.apache.flink.core.memory.ManagedMemoryUseCase) CustomPartitionerWrapper(org.apache.flink.streaming.runtime.partitioner.CustomPartitionerWrapper) Map(java.util.Map) Function(org.apache.flink.api.common.functions.Function) WithMasterCheckpointHook(org.apache.flink.streaming.api.checkpoint.WithMasterCheckpointHook) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) ExecutionOptions(org.apache.flink.configuration.ExecutionOptions) JobCheckpointingSettings(org.apache.flink.runtime.jobgraph.tasks.JobCheckpointingSettings) MINIMAL_CHECKPOINT_TIME(org.apache.flink.runtime.jobgraph.tasks.CheckpointCoordinatorConfiguration.MINIMAL_CHECKPOINT_TIME) TypeSerializer(org.apache.flink.api.common.typeutils.TypeSerializer) ForwardPartitioner(org.apache.flink.streaming.runtime.partitioner.ForwardPartitioner) IdentityHashMap(java.util.IdentityHashMap) TaskConfig(org.apache.flink.runtime.operators.util.TaskConfig) Collection(java.util.Collection) Set(java.util.Set) DistributedCache(org.apache.flink.api.common.cache.DistributedCache) Collectors(java.util.stream.Collectors) List(java.util.List) SerializedValue(org.apache.flink.util.SerializedValue) Preconditions.checkArgument(org.apache.flink.util.Preconditions.checkArgument) UdfStreamOperatorFactory(org.apache.flink.streaming.api.operators.UdfStreamOperatorFactory) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) Optional(java.util.Optional) CheckpointConfig(org.apache.flink.streaming.api.environment.CheckpointConfig) StreamIterationTail(org.apache.flink.streaming.runtime.tasks.StreamIterationTail) IllegalConfigurationException(org.apache.flink.configuration.IllegalConfigurationException) JobEdge(org.apache.flink.runtime.jobgraph.JobEdge) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) TaskInvokable(org.apache.flink.runtime.jobgraph.tasks.TaskInvokable) SlotSharingGroup(org.apache.flink.runtime.jobmanager.scheduler.SlotSharingGroup) LogicalVertex(org.apache.flink.runtime.jobgraph.topology.LogicalVertex) ForwardForConsecutiveHashPartitioner(org.apache.flink.streaming.runtime.partitioner.ForwardForConsecutiveHashPartitioner) ManagedMemoryUtils(org.apache.flink.runtime.util.config.memory.ManagedMemoryUtils) StreamOperatorFactory(org.apache.flink.streaming.api.operators.StreamOperatorFactory) InputOutputFormatVertex(org.apache.flink.runtime.jobgraph.InputOutputFormatVertex) ResultPartitionType(org.apache.flink.runtime.io.network.partition.ResultPartitionType) HashMap(java.util.HashMap) SourceOperatorFactory(org.apache.flink.streaming.api.operators.SourceOperatorFactory) ArrayList(java.util.ArrayList) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) HashSet(java.util.HashSet) StreamPartitioner(org.apache.flink.streaming.runtime.partitioner.StreamPartitioner) JobGraphUtils(org.apache.flink.runtime.jobgraph.JobGraphUtils) ExecutionCheckpointingOptions(org.apache.flink.streaming.api.environment.ExecutionCheckpointingOptions) StreamIterationHead(org.apache.flink.streaming.runtime.tasks.StreamIterationHead) LinkedList(java.util.LinkedList) DistributionPattern(org.apache.flink.runtime.jobgraph.DistributionPattern) Nullable(javax.annotation.Nullable) Preconditions.checkState(org.apache.flink.util.Preconditions.checkState) Logger(org.slf4j.Logger) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) Configuration(org.apache.flink.configuration.Configuration) IOException(java.io.IOException) OperatorIDPair(org.apache.flink.runtime.OperatorIDPair) ForwardForUnspecifiedPartitioner(org.apache.flink.streaming.runtime.partitioner.ForwardForUnspecifiedPartitioner) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting) MasterTriggerRestoreHook(org.apache.flink.runtime.checkpoint.MasterTriggerRestoreHook) RescalePartitioner(org.apache.flink.streaming.runtime.partitioner.RescalePartitioner) StreamExchangeMode(org.apache.flink.streaming.api.transformations.StreamExchangeMode) JobID(org.apache.flink.api.common.JobID) DefaultLogicalTopology(org.apache.flink.runtime.jobgraph.topology.DefaultLogicalTopology) OperatorCoordinator(org.apache.flink.runtime.operators.coordination.OperatorCoordinator) InputOutputFormatContainer(org.apache.flink.runtime.jobgraph.InputOutputFormatContainer) Internal(org.apache.flink.annotation.Internal) Comparator(java.util.Comparator) Collections(java.util.Collections) CheckpointRetentionPolicy(org.apache.flink.runtime.checkpoint.CheckpointRetentionPolicy) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) ManagedMemoryUseCase(org.apache.flink.core.memory.ManagedMemoryUseCase)

Example 9 with ManagedMemoryUseCase

use of org.apache.flink.core.memory.ManagedMemoryUseCase in project flink by apache.

the class StreamingJobGraphGenerator method setManagedMemoryFractionForOperator.

private static void setManagedMemoryFractionForOperator(final Map<ManagedMemoryUseCase, Integer> operatorScopeUseCaseWeights, final Set<ManagedMemoryUseCase> slotScopeUseCases, final Map<ManagedMemoryUseCase, Integer> groupManagedMemoryWeights, final Set<ManagedMemoryUseCase> groupSlotScopeUseCases, final StreamConfig operatorConfig) {
    // learn which use cases exist in the group from either one of the stream configs.
    for (Map.Entry<ManagedMemoryUseCase, Integer> entry : groupManagedMemoryWeights.entrySet()) {
        final ManagedMemoryUseCase useCase = entry.getKey();
        final int groupWeight = entry.getValue();
        final int operatorWeight = operatorScopeUseCaseWeights.getOrDefault(useCase, 0);
        operatorConfig.setManagedMemoryFractionOperatorOfUseCase(useCase, operatorWeight > 0 ? ManagedMemoryUtils.getFractionRoundedDown(operatorWeight, groupWeight) : 0.0);
    }
    for (ManagedMemoryUseCase useCase : groupSlotScopeUseCases) {
        operatorConfig.setManagedMemoryFractionOperatorOfUseCase(useCase, slotScopeUseCases.contains(useCase) ? 1.0 : 0.0);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) ManagedMemoryUseCase(org.apache.flink.core.memory.ManagedMemoryUseCase)

Aggregations

ManagedMemoryUseCase (org.apache.flink.core.memory.ManagedMemoryUseCase)9 HashMap (java.util.HashMap)7 Test (org.junit.Test)5 Map (java.util.Map)4 Configuration (org.apache.flink.configuration.Configuration)4 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 IdentityHashMap (java.util.IdentityHashMap)2 List (java.util.List)2 Set (java.util.Set)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Collectors (java.util.stream.Collectors)2 ResourceSpec (org.apache.flink.api.common.operators.ResourceSpec)2 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)2 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)2 OneInputTransformation (org.apache.flink.streaming.api.transformations.OneInputTransformation)2 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1