zhijiangW commented on a change in pull request #11155: 
[FLINK-14818][benchmark] Fix receiving InputGate setup of 
StreamNetworkBenchmarkEnvironment.
URL: https://github.com/apache/flink/pull/11155#discussion_r383090336
 
 

 ##########
 File path: 
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/io/benchmark/SingleInputGateBenchmarkFactory.java
 ##########
 @@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.runtime.io.benchmark;
+
+import org.apache.flink.core.memory.MemorySegmentProvider;
+import org.apache.flink.runtime.clusterframework.types.ResourceID;
+import org.apache.flink.runtime.io.network.ConnectionID;
+import org.apache.flink.runtime.io.network.ConnectionManager;
+import org.apache.flink.runtime.io.network.TaskEventPublisher;
+import org.apache.flink.runtime.io.network.buffer.NetworkBufferPool;
+import org.apache.flink.runtime.io.network.metrics.InputChannelMetrics;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionID;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionManager;
+import org.apache.flink.runtime.io.network.partition.consumer.InputChannel;
+import 
org.apache.flink.runtime.io.network.partition.consumer.LocalInputChannel;
+import 
org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel;
+import org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate;
+import 
org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateFactory;
+import org.apache.flink.runtime.shuffle.NettyShuffleDescriptor;
+import 
org.apache.flink.runtime.taskmanager.NettyShuffleEnvironmentConfiguration;
+
+import java.io.IOException;
+
+/**
+ * A benchmark-specific input gate factory which overrides the respective 
methods of creating
+ * {@link RemoteInputChannel} and {@link LocalInputChannel} for requesting 
specific subpartitions.
+ */
+public class SingleInputGateBenchmarkFactory extends SingleInputGateFactory {
+
+       public SingleInputGateBenchmarkFactory(
+                       ResourceID taskExecutorResourceId,
+                       NettyShuffleEnvironmentConfiguration networkConfig,
+                       ConnectionManager connectionManager,
+                       ResultPartitionManager partitionManager,
+                       TaskEventPublisher taskEventPublisher,
+                       NetworkBufferPool networkBufferPool) {
+               super(
+                       taskExecutorResourceId,
+                       networkConfig,
+                       connectionManager,
+                       partitionManager,
+                       taskEventPublisher,
+                       networkBufferPool);
+       }
+
+       @Override
+       protected InputChannel createKnownInputChannel(
+                       SingleInputGate inputGate,
+                       int index,
+                       NettyShuffleDescriptor inputChannelDescriptor,
+                       SingleInputGateFactory.ChannelStatistics 
channelStatistics,
+                       InputChannelMetrics metrics) {
+               ResultPartitionID partitionId = 
inputChannelDescriptor.getResultPartitionID();
+               if (inputChannelDescriptor.isLocalTo(taskExecutorResourceId)) {
+                       return new TestLocalInputChannel(
+                               inputGate,
+                               index,
+                               partitionId,
+                               partitionManager,
+                               taskEventPublisher,
+                               partitionRequestInitialBackoff,
+                               partitionRequestMaxBackoff,
+                               metrics);
+               } else {
+                       return new TestRemoteInputChannel(
+                               inputGate,
+                               index,
+                               partitionId,
+                               inputChannelDescriptor.getConnectionId(),
+                               connectionManager,
+                               partitionRequestInitialBackoff,
+                               partitionRequestMaxBackoff,
+                               metrics,
+                               networkBufferPool);
+               }
+       }
+
+       /**
+        * A {@link LocalInputChannel} which ignores the given subpartition 
index and uses channel index
+        * instead when requesting subpartition.
+        */
+       private static class TestLocalInputChannel extends LocalInputChannel {
+
+               private ResultPartitionID newPartitionID = new 
ResultPartitionID();
+
+               public TestLocalInputChannel(
+                               SingleInputGate inputGate,
+                               int channelIndex,
+                               ResultPartitionID partitionId,
+                               ResultPartitionManager partitionManager,
+                               TaskEventPublisher taskEventPublisher,
+                               int initialBackoff,
+                               int maxBackoff,
+                               InputChannelMetrics metrics) {
+                       super(
+                               inputGate,
+                               channelIndex,
+                               partitionId,
+                               partitionManager,
+                               taskEventPublisher,
+                               initialBackoff,
+                               maxBackoff,
+                               metrics);
+               }
+
+               @Override
+               public void requestSubpartition(int subpartitionIndex) throws 
IOException, InterruptedException {
+                       super.requestSubpartition(channelIndex);
+               }
+
+               @Override
+               public ResultPartitionID getPartitionId() {
+                       return newPartitionID;
+               }
+       }
+
+       /**
+        * A {@link RemoteInputChannel} which ignores the given subpartition 
index and uses channel index
+        * instead when requesting subpartition.
+        */
+       private static class TestRemoteInputChannel extends RemoteInputChannel {
+
+               private ResultPartitionID newPartitionID = new 
ResultPartitionID();
+
+               public TestRemoteInputChannel(
+                               SingleInputGate inputGate,
+                               int channelIndex,
+                               ResultPartitionID partitionId,
+                               ConnectionID connectionId,
+                               ConnectionManager connectionManager,
+                               int initialBackOff,
+                               int maxBackoff,
+                               InputChannelMetrics metrics,
+                               MemorySegmentProvider memorySegmentProvider) {
+                       super(
+                               inputGate,
+                               channelIndex,
+                               partitionId,
+                               connectionId,
+                               connectionManager,
+                               initialBackOff,
+                               maxBackoff,
+                               metrics,
+                               memorySegmentProvider);
+               }
+
+               @Override
+               public void requestSubpartition(int subpartitionIndex) throws 
IOException, InterruptedException {
+                       super.requestSubpartition(channelIndex);
+               }
+
+               @Override
+               public ResultPartitionID getPartitionId() {
 
 Review comment:
   Ignore this because of 
[comment](https://github.com/apache/flink/pull/11155#discussion_r383090260)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to