Search in sources :

Example 6 with SlotSharingGroup

use of org.apache.flink.api.common.operators.SlotSharingGroup in project flink by apache.

the class StreamGraphGeneratorTest method testConfigureSlotSharingGroupResource.

@Test
public void testConfigureSlotSharingGroupResource() {
    final SlotSharingGroup ssg1 = SlotSharingGroup.newBuilder("ssg1").setCpuCores(1).setTaskHeapMemoryMB(100).build();
    final SlotSharingGroup ssg2 = SlotSharingGroup.newBuilder("ssg2").setCpuCores(2).setTaskHeapMemoryMB(200).build();
    final SlotSharingGroup ssg3 = SlotSharingGroup.newBuilder(StreamGraphGenerator.DEFAULT_SLOT_SHARING_GROUP).setCpuCores(3).setTaskHeapMemoryMB(300).build();
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    final DataStream<Integer> source = env.fromElements(1).slotSharingGroup("ssg1");
    source.map(value -> value).slotSharingGroup(ssg2).map(value -> value * 2).map(value -> value * 3).slotSharingGroup(SlotSharingGroup.newBuilder("ssg4").build()).map(value -> value * 4).slotSharingGroup(ssg3).addSink(new DiscardingSink<>()).slotSharingGroup(ssg1);
    final StreamGraph streamGraph = env.getStreamGraph();
    assertThat(streamGraph.getSlotSharingGroupResource("ssg1").get(), is(ResourceProfile.fromResources(1, 100)));
    assertThat(streamGraph.getSlotSharingGroupResource("ssg2").get(), is(ResourceProfile.fromResources(2, 200)));
    assertThat(streamGraph.getSlotSharingGroupResource(StreamGraphGenerator.DEFAULT_SLOT_SHARING_GROUP).get(), is(ResourceProfile.fromResources(3, 300)));
}
Also used : Arrays(java.util.Arrays) Tuple2(org.apache.flink.api.java.tuple.Tuple2) BroadcastPartitioner(org.apache.flink.streaming.runtime.partitioner.BroadcastPartitioner) SlotSharingGroup(org.apache.flink.api.common.operators.SlotSharingGroup) KeyedBroadcastProcessFunction(org.apache.flink.streaming.api.functions.co.KeyedBroadcastProcessFunction) BasicTypeInfo(org.apache.flink.api.common.typeinfo.BasicTypeInfo) ShufflePartitioner(org.apache.flink.streaming.runtime.partitioner.ShufflePartitioner) ChainingStrategy(org.apache.flink.streaming.api.operators.ChainingStrategy) ResourceSpec(org.apache.flink.api.common.operators.ResourceSpec) ManagedMemoryUseCase(org.apache.flink.core.memory.ManagedMemoryUseCase) Map(java.util.Map) TestLogger(org.apache.flink.util.TestLogger) Function(org.apache.flink.api.common.functions.Function) Assertions(org.assertj.core.api.Assertions) TypeInformation(org.apache.flink.api.common.typeinfo.TypeInformation) CoMapFunction(org.apache.flink.streaming.api.functions.co.CoMapFunction) PartitionTransformation(org.apache.flink.streaming.api.transformations.PartitionTransformation) SinkFunction(org.apache.flink.streaming.api.functions.sink.SinkFunction) StreamTask(org.apache.flink.streaming.runtime.tasks.StreamTask) Collection(java.util.Collection) ConnectedStreams(org.apache.flink.streaming.api.datastream.ConnectedStreams) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) GlobalPartitioner(org.apache.flink.streaming.runtime.partitioner.GlobalPartitioner) List(java.util.List) NoOpIntMap(org.apache.flink.streaming.util.NoOpIntMap) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) CheckpointConfig(org.apache.flink.streaming.api.environment.CheckpointConfig) Matchers.is(org.hamcrest.Matchers.is) OneInputStreamOperator(org.apache.flink.streaming.api.operators.OneInputStreamOperator) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) MultipleInputTransformation(org.apache.flink.streaming.api.transformations.MultipleInputTransformation) IterativeStream(org.apache.flink.streaming.api.datastream.IterativeStream) BroadcastStream(org.apache.flink.streaming.api.datastream.BroadcastStream) AbstractUdfStreamOperator(org.apache.flink.streaming.api.operators.AbstractUdfStreamOperator) StreamOperatorFactory(org.apache.flink.streaming.api.operators.StreamOperatorFactory) Watermark(org.apache.flink.streaming.api.watermark.Watermark) SavepointConfigOptions(org.apache.flink.runtime.jobgraph.SavepointConfigOptions) HashMap(java.util.HashMap) MapStateDescriptor(org.apache.flink.api.common.state.MapStateDescriptor) ArrayList(java.util.ArrayList) StreamPartitioner(org.apache.flink.streaming.runtime.partitioner.StreamPartitioner) StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Collector(org.apache.flink.util.Collector) Matchers.iterableWithSize(org.hamcrest.Matchers.iterableWithSize) Output(org.apache.flink.streaming.api.operators.Output) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestExpandingSink(org.apache.flink.streaming.util.TestExpandingSink) RebalancePartitioner(org.apache.flink.streaming.runtime.partitioner.RebalancePartitioner) Description(org.hamcrest.Description) TwoInputStreamOperator(org.apache.flink.streaming.api.operators.TwoInputStreamOperator) DiscardingSink(org.apache.flink.streaming.api.functions.sink.DiscardingSink) Assert.assertNotNull(org.junit.Assert.assertNotNull) Configuration(org.apache.flink.configuration.Configuration) SingleOutputStreamOperator(org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator) Assert.assertTrue(org.junit.Assert.assertTrue) StreamOperatorParameters(org.apache.flink.streaming.api.operators.StreamOperatorParameters) Test(org.junit.Test) AbstractStreamOperator(org.apache.flink.streaming.api.operators.AbstractStreamOperator) DataStream(org.apache.flink.streaming.api.datastream.DataStream) StreamOperator(org.apache.flink.streaming.api.operators.StreamOperator) FeatureMatcher(org.hamcrest.FeatureMatcher) StreamExchangeMode(org.apache.flink.streaming.api.transformations.StreamExchangeMode) BroadcastProcessFunction(org.apache.flink.streaming.api.functions.co.BroadcastProcessFunction) Matcher(org.hamcrest.Matcher) Transformation(org.apache.flink.api.dag.Transformation) LatencyMarker(org.apache.flink.streaming.runtime.streamrecord.LatencyMarker) SavepointRestoreSettings(org.apache.flink.runtime.jobgraph.SavepointRestoreSettings) OutputTypeConfigurable(org.apache.flink.streaming.api.operators.OutputTypeConfigurable) StreamSource(org.apache.flink.streaming.api.operators.StreamSource) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) DiscardingSink(org.apache.flink.streaming.api.functions.sink.DiscardingSink) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) SlotSharingGroup(org.apache.flink.api.common.operators.SlotSharingGroup) Test(org.junit.Test)

Example 7 with SlotSharingGroup

use of org.apache.flink.api.common.operators.SlotSharingGroup in project flink by apache.

the class AdaptiveBatchSchedulerITCase method executeJob.

private void executeJob(Boolean isFineGrained) throws Exception {
    final Configuration configuration = new Configuration();
    configuration.setString(RestOptions.BIND_PORT, "0");
    configuration.setLong(JobManagerOptions.SLOT_REQUEST_TIMEOUT, 5000L);
    configuration.set(JobManagerOptions.SCHEDULER, JobManagerOptions.SchedulerType.AdaptiveBatch);
    configuration.setInteger(JobManagerOptions.ADAPTIVE_BATCH_SCHEDULER_MAX_PARALLELISM, DEFAULT_MAX_PARALLELISM);
    configuration.set(TaskManagerOptions.MEMORY_SEGMENT_SIZE, MemorySize.parse("4kb"));
    configuration.set(TaskManagerOptions.NUM_TASK_SLOTS, 1);
    if (isFineGrained) {
        configuration.set(ClusterOptions.ENABLE_FINE_GRAINED_RESOURCE_MANAGEMENT, true);
        configuration.set(ClusterOptions.FINE_GRAINED_SHUFFLE_MODE_ALL_BLOCKING, true);
    }
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironment(configuration);
    env.setParallelism(-1);
    env.setRuntimeMode(RuntimeExecutionMode.BATCH);
    List<SlotSharingGroup> slotSharingGroups = new ArrayList<>();
    for (int i = 0; i < 3; ++i) {
        SlotSharingGroup group;
        if (isFineGrained) {
            group = SlotSharingGroup.newBuilder("group" + i).setCpuCores(1.0).setTaskHeapMemory(MemorySize.parse("100m")).build();
        } else {
            group = SlotSharingGroup.newBuilder("group" + i).build();
        }
        slotSharingGroups.add(group);
    }
    final DataStream<Long> source1 = env.fromSequence(0, NUMBERS_TO_PRODUCE - 1).setParallelism(SOURCE_PARALLELISM_1).name("source1").slotSharingGroup(slotSharingGroups.get(0));
    final DataStream<Long> source2 = env.fromSequence(0, NUMBERS_TO_PRODUCE - 1).setParallelism(SOURCE_PARALLELISM_2).name("source2").slotSharingGroup(slotSharingGroups.get(1));
    source1.union(source2).rescale().map(new NumberCounter()).name("map").slotSharingGroup(slotSharingGroups.get(2));
    env.execute();
}
Also used : Configuration(org.apache.flink.configuration.Configuration) ArrayList(java.util.ArrayList) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) SlotSharingGroup(org.apache.flink.api.common.operators.SlotSharingGroup)

Aggregations

SlotSharingGroup (org.apache.flink.api.common.operators.SlotSharingGroup)7 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)6 ArrayList (java.util.ArrayList)4 ResourceSpec (org.apache.flink.api.common.operators.ResourceSpec)4 Configuration (org.apache.flink.configuration.Configuration)4 Test (org.junit.Test)4 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 Collections (java.util.Collections)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)3 Function (org.apache.flink.api.common.functions.Function)3 MapStateDescriptor (org.apache.flink.api.common.state.MapStateDescriptor)3 BasicTypeInfo (org.apache.flink.api.common.typeinfo.BasicTypeInfo)3 TypeInformation (org.apache.flink.api.common.typeinfo.TypeInformation)3 Transformation (org.apache.flink.api.dag.Transformation)3 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)3 ManagedMemoryUseCase (org.apache.flink.core.memory.ManagedMemoryUseCase)3