[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-07-02 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r299759623
 
 

 ##
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/consumer/InputBuffersMetricsTest.java
 ##
 @@ -0,0 +1,293 @@
+/*
+ * 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.runtime.io.network.partition.consumer;
+
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironment;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder;
+import org.apache.flink.runtime.io.network.TestingConnectionManager;
+import org.apache.flink.runtime.io.network.buffer.Buffer;
+import 
org.apache.flink.runtime.io.network.metrics.CreditBasedInputBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.ExclusiveBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.FloatingBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionType;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests the metrics for input buffers usage.
+ */
+public class InputBuffersMetricsTest extends TestLogger {
+
+   @Test
+   public void testCalculateTotalBuffersSize() throws IOException {
+   int numberOfRemoteChannels = 2;
+   int numberOfLocalChannels = 0;
+
+   int numberOfBufferPerChannel = 2;
+   int numberOfBuffersPerGate = 8;
+
+   NettyShuffleEnvironment network = new 
NettyShuffleEnvironmentBuilder()
+   .setNetworkBuffersPerChannel(numberOfBufferPerChannel)
+   
.setFloatingNetworkBuffersPerGate(numberOfBuffersPerGate)
+   .build();
+
+   SingleInputGate inputGate1 = buildInputGate(
+   network,
+   numberOfRemoteChannels,
+   numberOfLocalChannels).f0;
+
+   SingleInputGate[] inputGates = new 
SingleInputGate[]{inputGate1};
+   FloatingBuffersUsageGauge floatingBuffersUsageGauge = new 
FloatingBuffersUsageGauge(inputGates);
+   ExclusiveBuffersUsageGauge exclusiveBuffersUsageGauge = new 
ExclusiveBuffersUsageGauge(inputGates);
+   CreditBasedInputBuffersUsageGauge inputBufferPoolUsageGauge = 
new CreditBasedInputBuffersUsageGauge(
+   floatingBuffersUsageGauge,
+   exclusiveBuffersUsageGauge,
+   inputGates);
+
+   try (CloseableRegistry closeableRegistry = new 
CloseableRegistry()) {
+
+   closeableRegistry.registerCloseable(network::close);
+   closeableRegistry.registerCloseable(inputGate1::close);
+
+   assertEquals(numberOfBuffersPerGate, 
floatingBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel, 
exclusiveBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel + numberOfBuffersPerGate, 
inputBufferPoolUsageGauge.calculateTotalBuffers(inputGate1));
+   }
+   }
+
+   @Test
+   public void testExclusiveBuffersUsage() throws IOException {
+   int numberOfRemoteChannelsGate1 = 2;
+   int numberOfLocalChannelsGate1 = 0;
+   int numberOfRemoteChannelsGate2 = 1;
+   int numberOfLocalChannelsGate2 = 1;
+
+   int totalNumberOfRemoteChannels = numberOfRemoteChannelsGate1 + 
numberOfRemoteChannelsGate2;
+
+   int buffersPerChannel = 2;
+   int extraNetworkBuffersPerGate = 8;
+
+   NettyShuffleEnvironment network = new 
NettyShuffleEnvironmentBuilder()
+   

[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-07-02 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r299758674
 
 

 ##
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/consumer/InputBuffersMetricsTest.java
 ##
 @@ -0,0 +1,293 @@
+/*
+ * 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.runtime.io.network.partition.consumer;
+
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironment;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder;
+import org.apache.flink.runtime.io.network.TestingConnectionManager;
+import org.apache.flink.runtime.io.network.buffer.Buffer;
+import 
org.apache.flink.runtime.io.network.metrics.CreditBasedInputBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.ExclusiveBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.FloatingBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionType;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests the metrics for input buffers usage.
+ */
+public class InputBuffersMetricsTest extends TestLogger {
+
+   @Test
+   public void testCalculateTotalBuffersSize() throws IOException {
+   int numberOfRemoteChannels = 2;
+   int numberOfLocalChannels = 0;
+
+   int numberOfBufferPerChannel = 2;
+   int numberOfBuffersPerGate = 8;
+
+   NettyShuffleEnvironment network = new 
NettyShuffleEnvironmentBuilder()
+   .setNetworkBuffersPerChannel(numberOfBufferPerChannel)
+   
.setFloatingNetworkBuffersPerGate(numberOfBuffersPerGate)
+   .build();
+
+   SingleInputGate inputGate1 = buildInputGate(
+   network,
+   numberOfRemoteChannels,
+   numberOfLocalChannels).f0;
+
+   SingleInputGate[] inputGates = new 
SingleInputGate[]{inputGate1};
+   FloatingBuffersUsageGauge floatingBuffersUsageGauge = new 
FloatingBuffersUsageGauge(inputGates);
+   ExclusiveBuffersUsageGauge exclusiveBuffersUsageGauge = new 
ExclusiveBuffersUsageGauge(inputGates);
+   CreditBasedInputBuffersUsageGauge inputBufferPoolUsageGauge = 
new CreditBasedInputBuffersUsageGauge(
+   floatingBuffersUsageGauge,
+   exclusiveBuffersUsageGauge,
+   inputGates);
+
+   try (CloseableRegistry closeableRegistry = new 
CloseableRegistry()) {
+
+   closeableRegistry.registerCloseable(network::close);
+   closeableRegistry.registerCloseable(inputGate1::close);
+
+   assertEquals(numberOfBuffersPerGate, 
floatingBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel, 
exclusiveBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel + numberOfBuffersPerGate, 
inputBufferPoolUsageGauge.calculateTotalBuffers(inputGate1));
+   }
+   }
+
+   @Test
+   public void testExclusiveBuffersUsage() throws IOException {
+   int numberOfRemoteChannelsGate1 = 2;
+   int numberOfLocalChannelsGate1 = 0;
+   int numberOfRemoteChannelsGate2 = 1;
+   int numberOfLocalChannelsGate2 = 1;
+
+   int totalNumberOfRemoteChannels = numberOfRemoteChannelsGate1 + 
numberOfRemoteChannelsGate2;
+
+   int buffersPerChannel = 2;
+   int extraNetworkBuffersPerGate = 8;
+
+   NettyShuffleEnvironment network = new 
NettyShuffleEnvironmentBuilder()
+   

[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-07-01 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r299290395
 
 

 ##
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/consumer/InputBuffersMetricsTest.java
 ##
 @@ -0,0 +1,316 @@
+/*
+ * 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.runtime.io.network.partition.consumer;
+
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironment;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder;
+import org.apache.flink.runtime.io.network.TestingConnectionManager;
+import org.apache.flink.runtime.io.network.buffer.Buffer;
+import 
org.apache.flink.runtime.io.network.metrics.CreditBasedInputBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.ExclusiveBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.FloatingBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionType;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests the metrics for input buffers usage.
+ */
+public class InputBuffersMetricsTest extends TestLogger {
+
+   @Test
+   public void testCalculateTotalBuffersSize() throws IOException {
+   int numberOfRemoteChannels = 2;
+   int numberOfLocalChannels = 0;
+
+   int numberOfBufferPerChannel = 2;
+   int numberOfBuffersPerGate = 8;
+
+   NettyShuffleEnvironment network = new 
NettyShuffleEnvironmentBuilder()
+   .setNetworkBuffersPerChannel(numberOfBufferPerChannel)
+   
.setFloatingNetworkBuffersPerGate(numberOfBuffersPerGate)
+   .build();
+
+   Tuple3, 
List> tuple1 = buildInputGate(
+   network,
+   numberOfRemoteChannels,
+   numberOfLocalChannels);
+
+   SingleInputGate inputGate1 = tuple1.f0;
+
+   SingleInputGate[] inputGates = new 
SingleInputGate[]{inputGate1};
+   FloatingBuffersUsageGauge floatingBuffersUsageGauge = new 
FloatingBuffersUsageGauge(inputGates);
+   ExclusiveBuffersUsageGauge exclusiveBuffersUsageGauge = new 
ExclusiveBuffersUsageGauge(inputGates);
+   CreditBasedInputBuffersUsageGauge inputBufferPoolUsageGauge = 
new CreditBasedInputBuffersUsageGauge(
+   floatingBuffersUsageGauge,
+   exclusiveBuffersUsageGauge,
+   inputGates);
+
+   try (CloseableRegistry closeableRegistry = new 
CloseableRegistry()) {
+
+   closeableRegistry.registerCloseable(network::close);
+   closeableRegistry.registerCloseable(inputGate1::close);
+
+   assertEquals(numberOfBuffersPerGate, 
floatingBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel, 
exclusiveBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel + numberOfBuffersPerGate, 
inputBufferPoolUsageGauge.calculateTotalBuffers(inputGate1));
+   }
+   }
+
+   @Test
+   public void testExclusiveBuffersUsage() throws IOException {
+   int numberOfRemoteChannelsGate1 = 2;
+   int numberOfLocalChannelsGate1 = 0;
+   int numberOfRemoteChannelsGate2 = 1;
+   int numberOfLocalChannelsGate2 = 1;
+
+   int numberOfRemoteChannelsTotal = numberOfRemoteChannelsGate1 + 
numberOfRemoteChannelsGate2;
+   int numberOfInputGates = 2;
+
+   int buffersPerChannel = 2;
+   int extraNetworkBuffersPerGate = 8;
+
+   

[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-07-01 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r299293975
 
 

 ##
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/consumer/InputBuffersMetricsTest.java
 ##
 @@ -0,0 +1,316 @@
+/*
+ * 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.runtime.io.network.partition.consumer;
+
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironment;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder;
+import org.apache.flink.runtime.io.network.TestingConnectionManager;
+import org.apache.flink.runtime.io.network.buffer.Buffer;
+import 
org.apache.flink.runtime.io.network.metrics.CreditBasedInputBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.ExclusiveBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.FloatingBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionType;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests the metrics for input buffers usage.
+ */
+public class InputBuffersMetricsTest extends TestLogger {
+
+   @Test
+   public void testCalculateTotalBuffersSize() throws IOException {
+   int numberOfRemoteChannels = 2;
+   int numberOfLocalChannels = 0;
+
+   int numberOfBufferPerChannel = 2;
+   int numberOfBuffersPerGate = 8;
+
+   NettyShuffleEnvironment network = new 
NettyShuffleEnvironmentBuilder()
+   .setNetworkBuffersPerChannel(numberOfBufferPerChannel)
+   
.setFloatingNetworkBuffersPerGate(numberOfBuffersPerGate)
+   .build();
+
+   Tuple3, 
List> tuple1 = buildInputGate(
+   network,
+   numberOfRemoteChannels,
+   numberOfLocalChannels);
+
+   SingleInputGate inputGate1 = tuple1.f0;
+
+   SingleInputGate[] inputGates = new 
SingleInputGate[]{inputGate1};
+   FloatingBuffersUsageGauge floatingBuffersUsageGauge = new 
FloatingBuffersUsageGauge(inputGates);
+   ExclusiveBuffersUsageGauge exclusiveBuffersUsageGauge = new 
ExclusiveBuffersUsageGauge(inputGates);
+   CreditBasedInputBuffersUsageGauge inputBufferPoolUsageGauge = 
new CreditBasedInputBuffersUsageGauge(
+   floatingBuffersUsageGauge,
+   exclusiveBuffersUsageGauge,
+   inputGates);
+
+   try (CloseableRegistry closeableRegistry = new 
CloseableRegistry()) {
+
+   closeableRegistry.registerCloseable(network::close);
+   closeableRegistry.registerCloseable(inputGate1::close);
+
+   assertEquals(numberOfBuffersPerGate, 
floatingBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel, 
exclusiveBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel + numberOfBuffersPerGate, 
inputBufferPoolUsageGauge.calculateTotalBuffers(inputGate1));
+   }
+   }
+
+   @Test
+   public void testExclusiveBuffersUsage() throws IOException {
+   int numberOfRemoteChannelsGate1 = 2;
+   int numberOfLocalChannelsGate1 = 0;
+   int numberOfRemoteChannelsGate2 = 1;
+   int numberOfLocalChannelsGate2 = 1;
+
+   int numberOfRemoteChannelsTotal = numberOfRemoteChannelsGate1 + 
numberOfRemoteChannelsGate2;
+   int numberOfInputGates = 2;
+
+   int buffersPerChannel = 2;
+   int extraNetworkBuffersPerGate = 8;
+
+   

[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-07-01 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r299293436
 
 

 ##
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/consumer/InputBuffersMetricsTest.java
 ##
 @@ -0,0 +1,316 @@
+/*
+ * 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.runtime.io.network.partition.consumer;
+
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironment;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder;
+import org.apache.flink.runtime.io.network.TestingConnectionManager;
+import org.apache.flink.runtime.io.network.buffer.Buffer;
+import 
org.apache.flink.runtime.io.network.metrics.CreditBasedInputBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.ExclusiveBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.FloatingBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionType;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests the metrics for input buffers usage.
+ */
+public class InputBuffersMetricsTest extends TestLogger {
+
+   @Test
+   public void testCalculateTotalBuffersSize() throws IOException {
+   int numberOfRemoteChannels = 2;
+   int numberOfLocalChannels = 0;
+
+   int numberOfBufferPerChannel = 2;
+   int numberOfBuffersPerGate = 8;
+
+   NettyShuffleEnvironment network = new 
NettyShuffleEnvironmentBuilder()
+   .setNetworkBuffersPerChannel(numberOfBufferPerChannel)
+   
.setFloatingNetworkBuffersPerGate(numberOfBuffersPerGate)
+   .build();
+
+   Tuple3, 
List> tuple1 = buildInputGate(
+   network,
+   numberOfRemoteChannels,
+   numberOfLocalChannels);
+
+   SingleInputGate inputGate1 = tuple1.f0;
+
+   SingleInputGate[] inputGates = new 
SingleInputGate[]{inputGate1};
+   FloatingBuffersUsageGauge floatingBuffersUsageGauge = new 
FloatingBuffersUsageGauge(inputGates);
+   ExclusiveBuffersUsageGauge exclusiveBuffersUsageGauge = new 
ExclusiveBuffersUsageGauge(inputGates);
+   CreditBasedInputBuffersUsageGauge inputBufferPoolUsageGauge = 
new CreditBasedInputBuffersUsageGauge(
+   floatingBuffersUsageGauge,
+   exclusiveBuffersUsageGauge,
+   inputGates);
+
+   try (CloseableRegistry closeableRegistry = new 
CloseableRegistry()) {
+
+   closeableRegistry.registerCloseable(network::close);
+   closeableRegistry.registerCloseable(inputGate1::close);
+
+   assertEquals(numberOfBuffersPerGate, 
floatingBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel, 
exclusiveBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel + numberOfBuffersPerGate, 
inputBufferPoolUsageGauge.calculateTotalBuffers(inputGate1));
+   }
+   }
+
+   @Test
+   public void testExclusiveBuffersUsage() throws IOException {
+   int numberOfRemoteChannelsGate1 = 2;
+   int numberOfLocalChannelsGate1 = 0;
+   int numberOfRemoteChannelsGate2 = 1;
+   int numberOfLocalChannelsGate2 = 1;
+
+   int numberOfRemoteChannelsTotal = numberOfRemoteChannelsGate1 + 
numberOfRemoteChannelsGate2;
+   int numberOfInputGates = 2;
+
+   int buffersPerChannel = 2;
+   int extraNetworkBuffersPerGate = 8;
+
+   

[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-07-01 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r299292724
 
 

 ##
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/consumer/InputBuffersMetricsTest.java
 ##
 @@ -0,0 +1,316 @@
+/*
+ * 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.runtime.io.network.partition.consumer;
+
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironment;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder;
+import org.apache.flink.runtime.io.network.TestingConnectionManager;
+import org.apache.flink.runtime.io.network.buffer.Buffer;
+import 
org.apache.flink.runtime.io.network.metrics.CreditBasedInputBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.ExclusiveBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.FloatingBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionType;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests the metrics for input buffers usage.
+ */
+public class InputBuffersMetricsTest extends TestLogger {
+
+   @Test
+   public void testCalculateTotalBuffersSize() throws IOException {
+   int numberOfRemoteChannels = 2;
+   int numberOfLocalChannels = 0;
+
+   int numberOfBufferPerChannel = 2;
+   int numberOfBuffersPerGate = 8;
+
+   NettyShuffleEnvironment network = new 
NettyShuffleEnvironmentBuilder()
+   .setNetworkBuffersPerChannel(numberOfBufferPerChannel)
+   
.setFloatingNetworkBuffersPerGate(numberOfBuffersPerGate)
+   .build();
+
+   Tuple3, 
List> tuple1 = buildInputGate(
+   network,
+   numberOfRemoteChannels,
+   numberOfLocalChannels);
+
+   SingleInputGate inputGate1 = tuple1.f0;
+
+   SingleInputGate[] inputGates = new 
SingleInputGate[]{inputGate1};
+   FloatingBuffersUsageGauge floatingBuffersUsageGauge = new 
FloatingBuffersUsageGauge(inputGates);
+   ExclusiveBuffersUsageGauge exclusiveBuffersUsageGauge = new 
ExclusiveBuffersUsageGauge(inputGates);
+   CreditBasedInputBuffersUsageGauge inputBufferPoolUsageGauge = 
new CreditBasedInputBuffersUsageGauge(
+   floatingBuffersUsageGauge,
+   exclusiveBuffersUsageGauge,
+   inputGates);
+
+   try (CloseableRegistry closeableRegistry = new 
CloseableRegistry()) {
+
+   closeableRegistry.registerCloseable(network::close);
+   closeableRegistry.registerCloseable(inputGate1::close);
+
+   assertEquals(numberOfBuffersPerGate, 
floatingBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel, 
exclusiveBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel + numberOfBuffersPerGate, 
inputBufferPoolUsageGauge.calculateTotalBuffers(inputGate1));
+   }
+   }
+
+   @Test
+   public void testExclusiveBuffersUsage() throws IOException {
+   int numberOfRemoteChannelsGate1 = 2;
+   int numberOfLocalChannelsGate1 = 0;
+   int numberOfRemoteChannelsGate2 = 1;
+   int numberOfLocalChannelsGate2 = 1;
+
+   int numberOfRemoteChannelsTotal = numberOfRemoteChannelsGate1 + 
numberOfRemoteChannelsGate2;
+   int numberOfInputGates = 2;
+
+   int buffersPerChannel = 2;
+   int extraNetworkBuffersPerGate = 8;
+
+   

[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-07-01 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r299292571
 
 

 ##
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/consumer/InputBuffersMetricsTest.java
 ##
 @@ -0,0 +1,316 @@
+/*
+ * 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.runtime.io.network.partition.consumer;
+
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironment;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder;
+import org.apache.flink.runtime.io.network.TestingConnectionManager;
+import org.apache.flink.runtime.io.network.buffer.Buffer;
+import 
org.apache.flink.runtime.io.network.metrics.CreditBasedInputBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.ExclusiveBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.FloatingBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionType;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests the metrics for input buffers usage.
+ */
+public class InputBuffersMetricsTest extends TestLogger {
+
+   @Test
+   public void testCalculateTotalBuffersSize() throws IOException {
+   int numberOfRemoteChannels = 2;
+   int numberOfLocalChannels = 0;
+
+   int numberOfBufferPerChannel = 2;
+   int numberOfBuffersPerGate = 8;
+
+   NettyShuffleEnvironment network = new 
NettyShuffleEnvironmentBuilder()
+   .setNetworkBuffersPerChannel(numberOfBufferPerChannel)
+   
.setFloatingNetworkBuffersPerGate(numberOfBuffersPerGate)
+   .build();
+
+   Tuple3, 
List> tuple1 = buildInputGate(
+   network,
+   numberOfRemoteChannels,
+   numberOfLocalChannels);
+
+   SingleInputGate inputGate1 = tuple1.f0;
+
+   SingleInputGate[] inputGates = new 
SingleInputGate[]{inputGate1};
+   FloatingBuffersUsageGauge floatingBuffersUsageGauge = new 
FloatingBuffersUsageGauge(inputGates);
+   ExclusiveBuffersUsageGauge exclusiveBuffersUsageGauge = new 
ExclusiveBuffersUsageGauge(inputGates);
+   CreditBasedInputBuffersUsageGauge inputBufferPoolUsageGauge = 
new CreditBasedInputBuffersUsageGauge(
+   floatingBuffersUsageGauge,
+   exclusiveBuffersUsageGauge,
+   inputGates);
+
+   try (CloseableRegistry closeableRegistry = new 
CloseableRegistry()) {
+
+   closeableRegistry.registerCloseable(network::close);
+   closeableRegistry.registerCloseable(inputGate1::close);
+
+   assertEquals(numberOfBuffersPerGate, 
floatingBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel, 
exclusiveBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel + numberOfBuffersPerGate, 
inputBufferPoolUsageGauge.calculateTotalBuffers(inputGate1));
+   }
+   }
+
+   @Test
+   public void testExclusiveBuffersUsage() throws IOException {
+   int numberOfRemoteChannelsGate1 = 2;
+   int numberOfLocalChannelsGate1 = 0;
+   int numberOfRemoteChannelsGate2 = 1;
+   int numberOfLocalChannelsGate2 = 1;
+
+   int numberOfRemoteChannelsTotal = numberOfRemoteChannelsGate1 + 
numberOfRemoteChannelsGate2;
+   int numberOfInputGates = 2;
+
+   int buffersPerChannel = 2;
+   int extraNetworkBuffersPerGate = 8;
+
+   

[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-07-01 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r299292261
 
 

 ##
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/consumer/InputBuffersMetricsTest.java
 ##
 @@ -0,0 +1,316 @@
+/*
+ * 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.runtime.io.network.partition.consumer;
+
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironment;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder;
+import org.apache.flink.runtime.io.network.TestingConnectionManager;
+import org.apache.flink.runtime.io.network.buffer.Buffer;
+import 
org.apache.flink.runtime.io.network.metrics.CreditBasedInputBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.ExclusiveBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.FloatingBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionType;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests the metrics for input buffers usage.
+ */
+public class InputBuffersMetricsTest extends TestLogger {
+
+   @Test
+   public void testCalculateTotalBuffersSize() throws IOException {
+   int numberOfRemoteChannels = 2;
+   int numberOfLocalChannels = 0;
+
+   int numberOfBufferPerChannel = 2;
+   int numberOfBuffersPerGate = 8;
+
+   NettyShuffleEnvironment network = new 
NettyShuffleEnvironmentBuilder()
+   .setNetworkBuffersPerChannel(numberOfBufferPerChannel)
+   
.setFloatingNetworkBuffersPerGate(numberOfBuffersPerGate)
+   .build();
+
+   Tuple3, 
List> tuple1 = buildInputGate(
+   network,
+   numberOfRemoteChannels,
+   numberOfLocalChannels);
+
+   SingleInputGate inputGate1 = tuple1.f0;
+
+   SingleInputGate[] inputGates = new 
SingleInputGate[]{inputGate1};
+   FloatingBuffersUsageGauge floatingBuffersUsageGauge = new 
FloatingBuffersUsageGauge(inputGates);
+   ExclusiveBuffersUsageGauge exclusiveBuffersUsageGauge = new 
ExclusiveBuffersUsageGauge(inputGates);
+   CreditBasedInputBuffersUsageGauge inputBufferPoolUsageGauge = 
new CreditBasedInputBuffersUsageGauge(
+   floatingBuffersUsageGauge,
+   exclusiveBuffersUsageGauge,
+   inputGates);
+
+   try (CloseableRegistry closeableRegistry = new 
CloseableRegistry()) {
+
+   closeableRegistry.registerCloseable(network::close);
+   closeableRegistry.registerCloseable(inputGate1::close);
+
+   assertEquals(numberOfBuffersPerGate, 
floatingBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel, 
exclusiveBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel + numberOfBuffersPerGate, 
inputBufferPoolUsageGauge.calculateTotalBuffers(inputGate1));
+   }
+   }
+
+   @Test
+   public void testExclusiveBuffersUsage() throws IOException {
+   int numberOfRemoteChannelsGate1 = 2;
+   int numberOfLocalChannelsGate1 = 0;
+   int numberOfRemoteChannelsGate2 = 1;
+   int numberOfLocalChannelsGate2 = 1;
+
+   int numberOfRemoteChannelsTotal = numberOfRemoteChannelsGate1 + 
numberOfRemoteChannelsGate2;
+   int numberOfInputGates = 2;
+
+   int buffersPerChannel = 2;
+   int extraNetworkBuffersPerGate = 8;
+
+   

[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-07-01 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r299290827
 
 

 ##
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/consumer/InputBuffersMetricsTest.java
 ##
 @@ -0,0 +1,316 @@
+/*
+ * 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.runtime.io.network.partition.consumer;
+
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironment;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder;
+import org.apache.flink.runtime.io.network.TestingConnectionManager;
+import org.apache.flink.runtime.io.network.buffer.Buffer;
+import 
org.apache.flink.runtime.io.network.metrics.CreditBasedInputBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.ExclusiveBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.FloatingBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionType;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests the metrics for input buffers usage.
+ */
+public class InputBuffersMetricsTest extends TestLogger {
+
+   @Test
+   public void testCalculateTotalBuffersSize() throws IOException {
+   int numberOfRemoteChannels = 2;
+   int numberOfLocalChannels = 0;
+
+   int numberOfBufferPerChannel = 2;
+   int numberOfBuffersPerGate = 8;
+
+   NettyShuffleEnvironment network = new 
NettyShuffleEnvironmentBuilder()
+   .setNetworkBuffersPerChannel(numberOfBufferPerChannel)
+   
.setFloatingNetworkBuffersPerGate(numberOfBuffersPerGate)
+   .build();
+
+   Tuple3, 
List> tuple1 = buildInputGate(
+   network,
+   numberOfRemoteChannels,
+   numberOfLocalChannels);
+
+   SingleInputGate inputGate1 = tuple1.f0;
+
+   SingleInputGate[] inputGates = new 
SingleInputGate[]{inputGate1};
+   FloatingBuffersUsageGauge floatingBuffersUsageGauge = new 
FloatingBuffersUsageGauge(inputGates);
+   ExclusiveBuffersUsageGauge exclusiveBuffersUsageGauge = new 
ExclusiveBuffersUsageGauge(inputGates);
+   CreditBasedInputBuffersUsageGauge inputBufferPoolUsageGauge = 
new CreditBasedInputBuffersUsageGauge(
+   floatingBuffersUsageGauge,
+   exclusiveBuffersUsageGauge,
+   inputGates);
+
+   try (CloseableRegistry closeableRegistry = new 
CloseableRegistry()) {
+
+   closeableRegistry.registerCloseable(network::close);
+   closeableRegistry.registerCloseable(inputGate1::close);
+
+   assertEquals(numberOfBuffersPerGate, 
floatingBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel, 
exclusiveBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel + numberOfBuffersPerGate, 
inputBufferPoolUsageGauge.calculateTotalBuffers(inputGate1));
+   }
+   }
+
+   @Test
+   public void testExclusiveBuffersUsage() throws IOException {
+   int numberOfRemoteChannelsGate1 = 2;
+   int numberOfLocalChannelsGate1 = 0;
+   int numberOfRemoteChannelsGate2 = 1;
+   int numberOfLocalChannelsGate2 = 1;
+
+   int numberOfRemoteChannelsTotal = numberOfRemoteChannelsGate1 + 
numberOfRemoteChannelsGate2;
+   int numberOfInputGates = 2;
+
+   int buffersPerChannel = 2;
+   int extraNetworkBuffersPerGate = 8;
+
+   

[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-07-01 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r299290642
 
 

 ##
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/consumer/InputBuffersMetricsTest.java
 ##
 @@ -0,0 +1,316 @@
+/*
+ * 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.runtime.io.network.partition.consumer;
+
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironment;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder;
+import org.apache.flink.runtime.io.network.TestingConnectionManager;
+import org.apache.flink.runtime.io.network.buffer.Buffer;
+import 
org.apache.flink.runtime.io.network.metrics.CreditBasedInputBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.ExclusiveBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.FloatingBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionType;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests the metrics for input buffers usage.
+ */
+public class InputBuffersMetricsTest extends TestLogger {
+
+   @Test
+   public void testCalculateTotalBuffersSize() throws IOException {
+   int numberOfRemoteChannels = 2;
+   int numberOfLocalChannels = 0;
+
+   int numberOfBufferPerChannel = 2;
+   int numberOfBuffersPerGate = 8;
+
+   NettyShuffleEnvironment network = new 
NettyShuffleEnvironmentBuilder()
+   .setNetworkBuffersPerChannel(numberOfBufferPerChannel)
+   
.setFloatingNetworkBuffersPerGate(numberOfBuffersPerGate)
+   .build();
+
+   Tuple3, 
List> tuple1 = buildInputGate(
+   network,
+   numberOfRemoteChannels,
+   numberOfLocalChannels);
+
+   SingleInputGate inputGate1 = tuple1.f0;
+
+   SingleInputGate[] inputGates = new 
SingleInputGate[]{inputGate1};
+   FloatingBuffersUsageGauge floatingBuffersUsageGauge = new 
FloatingBuffersUsageGauge(inputGates);
+   ExclusiveBuffersUsageGauge exclusiveBuffersUsageGauge = new 
ExclusiveBuffersUsageGauge(inputGates);
+   CreditBasedInputBuffersUsageGauge inputBufferPoolUsageGauge = 
new CreditBasedInputBuffersUsageGauge(
+   floatingBuffersUsageGauge,
+   exclusiveBuffersUsageGauge,
+   inputGates);
+
+   try (CloseableRegistry closeableRegistry = new 
CloseableRegistry()) {
+
+   closeableRegistry.registerCloseable(network::close);
+   closeableRegistry.registerCloseable(inputGate1::close);
+
+   assertEquals(numberOfBuffersPerGate, 
floatingBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel, 
exclusiveBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel + numberOfBuffersPerGate, 
inputBufferPoolUsageGauge.calculateTotalBuffers(inputGate1));
+   }
+   }
+
+   @Test
+   public void testExclusiveBuffersUsage() throws IOException {
+   int numberOfRemoteChannelsGate1 = 2;
+   int numberOfLocalChannelsGate1 = 0;
+   int numberOfRemoteChannelsGate2 = 1;
+   int numberOfLocalChannelsGate2 = 1;
+
+   int numberOfRemoteChannelsTotal = numberOfRemoteChannelsGate1 + 
numberOfRemoteChannelsGate2;
+   int numberOfInputGates = 2;
+
+   int buffersPerChannel = 2;
+   int extraNetworkBuffersPerGate = 8;
+
+   

[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-07-01 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r299290478
 
 

 ##
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/consumer/InputBuffersMetricsTest.java
 ##
 @@ -0,0 +1,316 @@
+/*
+ * 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.runtime.io.network.partition.consumer;
+
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironment;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder;
+import org.apache.flink.runtime.io.network.TestingConnectionManager;
+import org.apache.flink.runtime.io.network.buffer.Buffer;
+import 
org.apache.flink.runtime.io.network.metrics.CreditBasedInputBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.ExclusiveBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.FloatingBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionType;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests the metrics for input buffers usage.
+ */
+public class InputBuffersMetricsTest extends TestLogger {
+
+   @Test
+   public void testCalculateTotalBuffersSize() throws IOException {
+   int numberOfRemoteChannels = 2;
+   int numberOfLocalChannels = 0;
+
+   int numberOfBufferPerChannel = 2;
+   int numberOfBuffersPerGate = 8;
+
+   NettyShuffleEnvironment network = new 
NettyShuffleEnvironmentBuilder()
+   .setNetworkBuffersPerChannel(numberOfBufferPerChannel)
+   
.setFloatingNetworkBuffersPerGate(numberOfBuffersPerGate)
+   .build();
+
+   Tuple3, 
List> tuple1 = buildInputGate(
+   network,
+   numberOfRemoteChannels,
+   numberOfLocalChannels);
+
+   SingleInputGate inputGate1 = tuple1.f0;
+
+   SingleInputGate[] inputGates = new 
SingleInputGate[]{inputGate1};
+   FloatingBuffersUsageGauge floatingBuffersUsageGauge = new 
FloatingBuffersUsageGauge(inputGates);
+   ExclusiveBuffersUsageGauge exclusiveBuffersUsageGauge = new 
ExclusiveBuffersUsageGauge(inputGates);
+   CreditBasedInputBuffersUsageGauge inputBufferPoolUsageGauge = 
new CreditBasedInputBuffersUsageGauge(
+   floatingBuffersUsageGauge,
+   exclusiveBuffersUsageGauge,
+   inputGates);
+
+   try (CloseableRegistry closeableRegistry = new 
CloseableRegistry()) {
+
+   closeableRegistry.registerCloseable(network::close);
+   closeableRegistry.registerCloseable(inputGate1::close);
+
+   assertEquals(numberOfBuffersPerGate, 
floatingBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel, 
exclusiveBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel + numberOfBuffersPerGate, 
inputBufferPoolUsageGauge.calculateTotalBuffers(inputGate1));
+   }
+   }
+
+   @Test
+   public void testExclusiveBuffersUsage() throws IOException {
+   int numberOfRemoteChannelsGate1 = 2;
+   int numberOfLocalChannelsGate1 = 0;
+   int numberOfRemoteChannelsGate2 = 1;
+   int numberOfLocalChannelsGate2 = 1;
+
+   int numberOfRemoteChannelsTotal = numberOfRemoteChannelsGate1 + 
numberOfRemoteChannelsGate2;
+   int numberOfInputGates = 2;
+
+   int buffersPerChannel = 2;
+   int extraNetworkBuffersPerGate = 8;
+
+   

[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-07-01 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r299290395
 
 

 ##
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/consumer/InputBuffersMetricsTest.java
 ##
 @@ -0,0 +1,316 @@
+/*
+ * 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.runtime.io.network.partition.consumer;
+
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironment;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder;
+import org.apache.flink.runtime.io.network.TestingConnectionManager;
+import org.apache.flink.runtime.io.network.buffer.Buffer;
+import 
org.apache.flink.runtime.io.network.metrics.CreditBasedInputBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.ExclusiveBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.FloatingBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionType;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests the metrics for input buffers usage.
+ */
+public class InputBuffersMetricsTest extends TestLogger {
+
+   @Test
+   public void testCalculateTotalBuffersSize() throws IOException {
+   int numberOfRemoteChannels = 2;
+   int numberOfLocalChannels = 0;
+
+   int numberOfBufferPerChannel = 2;
+   int numberOfBuffersPerGate = 8;
+
+   NettyShuffleEnvironment network = new 
NettyShuffleEnvironmentBuilder()
+   .setNetworkBuffersPerChannel(numberOfBufferPerChannel)
+   
.setFloatingNetworkBuffersPerGate(numberOfBuffersPerGate)
+   .build();
+
+   Tuple3, 
List> tuple1 = buildInputGate(
+   network,
+   numberOfRemoteChannels,
+   numberOfLocalChannels);
+
+   SingleInputGate inputGate1 = tuple1.f0;
+
+   SingleInputGate[] inputGates = new 
SingleInputGate[]{inputGate1};
+   FloatingBuffersUsageGauge floatingBuffersUsageGauge = new 
FloatingBuffersUsageGauge(inputGates);
+   ExclusiveBuffersUsageGauge exclusiveBuffersUsageGauge = new 
ExclusiveBuffersUsageGauge(inputGates);
+   CreditBasedInputBuffersUsageGauge inputBufferPoolUsageGauge = 
new CreditBasedInputBuffersUsageGauge(
+   floatingBuffersUsageGauge,
+   exclusiveBuffersUsageGauge,
+   inputGates);
+
+   try (CloseableRegistry closeableRegistry = new 
CloseableRegistry()) {
+
+   closeableRegistry.registerCloseable(network::close);
+   closeableRegistry.registerCloseable(inputGate1::close);
+
+   assertEquals(numberOfBuffersPerGate, 
floatingBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel, 
exclusiveBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel + numberOfBuffersPerGate, 
inputBufferPoolUsageGauge.calculateTotalBuffers(inputGate1));
+   }
+   }
+
+   @Test
+   public void testExclusiveBuffersUsage() throws IOException {
+   int numberOfRemoteChannelsGate1 = 2;
+   int numberOfLocalChannelsGate1 = 0;
+   int numberOfRemoteChannelsGate2 = 1;
+   int numberOfLocalChannelsGate2 = 1;
+
+   int numberOfRemoteChannelsTotal = numberOfRemoteChannelsGate1 + 
numberOfRemoteChannelsGate2;
+   int numberOfInputGates = 2;
+
+   int buffersPerChannel = 2;
+   int extraNetworkBuffersPerGate = 8;
+
+   

[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-07-01 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r299290244
 
 

 ##
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/consumer/InputBuffersMetricsTest.java
 ##
 @@ -0,0 +1,316 @@
+/*
+ * 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.runtime.io.network.partition.consumer;
+
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironment;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder;
+import org.apache.flink.runtime.io.network.TestingConnectionManager;
+import org.apache.flink.runtime.io.network.buffer.Buffer;
+import 
org.apache.flink.runtime.io.network.metrics.CreditBasedInputBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.ExclusiveBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.FloatingBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionType;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests the metrics for input buffers usage.
+ */
+public class InputBuffersMetricsTest extends TestLogger {
+
+   @Test
+   public void testCalculateTotalBuffersSize() throws IOException {
+   int numberOfRemoteChannels = 2;
+   int numberOfLocalChannels = 0;
+
+   int numberOfBufferPerChannel = 2;
+   int numberOfBuffersPerGate = 8;
+
+   NettyShuffleEnvironment network = new 
NettyShuffleEnvironmentBuilder()
+   .setNetworkBuffersPerChannel(numberOfBufferPerChannel)
+   
.setFloatingNetworkBuffersPerGate(numberOfBuffersPerGate)
+   .build();
+
+   Tuple3, 
List> tuple1 = buildInputGate(
+   network,
+   numberOfRemoteChannels,
+   numberOfLocalChannels);
+
+   SingleInputGate inputGate1 = tuple1.f0;
+
+   SingleInputGate[] inputGates = new 
SingleInputGate[]{inputGate1};
+   FloatingBuffersUsageGauge floatingBuffersUsageGauge = new 
FloatingBuffersUsageGauge(inputGates);
+   ExclusiveBuffersUsageGauge exclusiveBuffersUsageGauge = new 
ExclusiveBuffersUsageGauge(inputGates);
+   CreditBasedInputBuffersUsageGauge inputBufferPoolUsageGauge = 
new CreditBasedInputBuffersUsageGauge(
+   floatingBuffersUsageGauge,
+   exclusiveBuffersUsageGauge,
+   inputGates);
+
+   try (CloseableRegistry closeableRegistry = new 
CloseableRegistry()) {
+
+   closeableRegistry.registerCloseable(network::close);
+   closeableRegistry.registerCloseable(inputGate1::close);
+
+   assertEquals(numberOfBuffersPerGate, 
floatingBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel, 
exclusiveBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel + numberOfBuffersPerGate, 
inputBufferPoolUsageGauge.calculateTotalBuffers(inputGate1));
+   }
+   }
+
+   @Test
+   public void testExclusiveBuffersUsage() throws IOException {
+   int numberOfRemoteChannelsGate1 = 2;
+   int numberOfLocalChannelsGate1 = 0;
+   int numberOfRemoteChannelsGate2 = 1;
+   int numberOfLocalChannelsGate2 = 1;
+
+   int numberOfRemoteChannelsTotal = numberOfRemoteChannelsGate1 + 
numberOfRemoteChannelsGate2;
+   int numberOfInputGates = 2;
+
+   int buffersPerChannel = 2;
+   int extraNetworkBuffersPerGate = 8;
+
+   

[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-07-01 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r299290244
 
 

 ##
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/consumer/InputBuffersMetricsTest.java
 ##
 @@ -0,0 +1,316 @@
+/*
+ * 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.runtime.io.network.partition.consumer;
+
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironment;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder;
+import org.apache.flink.runtime.io.network.TestingConnectionManager;
+import org.apache.flink.runtime.io.network.buffer.Buffer;
+import 
org.apache.flink.runtime.io.network.metrics.CreditBasedInputBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.ExclusiveBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.FloatingBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionType;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests the metrics for input buffers usage.
+ */
+public class InputBuffersMetricsTest extends TestLogger {
+
+   @Test
+   public void testCalculateTotalBuffersSize() throws IOException {
+   int numberOfRemoteChannels = 2;
+   int numberOfLocalChannels = 0;
+
+   int numberOfBufferPerChannel = 2;
+   int numberOfBuffersPerGate = 8;
+
+   NettyShuffleEnvironment network = new 
NettyShuffleEnvironmentBuilder()
+   .setNetworkBuffersPerChannel(numberOfBufferPerChannel)
+   
.setFloatingNetworkBuffersPerGate(numberOfBuffersPerGate)
+   .build();
+
+   Tuple3, 
List> tuple1 = buildInputGate(
+   network,
+   numberOfRemoteChannels,
+   numberOfLocalChannels);
+
+   SingleInputGate inputGate1 = tuple1.f0;
+
+   SingleInputGate[] inputGates = new 
SingleInputGate[]{inputGate1};
+   FloatingBuffersUsageGauge floatingBuffersUsageGauge = new 
FloatingBuffersUsageGauge(inputGates);
+   ExclusiveBuffersUsageGauge exclusiveBuffersUsageGauge = new 
ExclusiveBuffersUsageGauge(inputGates);
+   CreditBasedInputBuffersUsageGauge inputBufferPoolUsageGauge = 
new CreditBasedInputBuffersUsageGauge(
+   floatingBuffersUsageGauge,
+   exclusiveBuffersUsageGauge,
+   inputGates);
+
+   try (CloseableRegistry closeableRegistry = new 
CloseableRegistry()) {
+
+   closeableRegistry.registerCloseable(network::close);
+   closeableRegistry.registerCloseable(inputGate1::close);
+
+   assertEquals(numberOfBuffersPerGate, 
floatingBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel, 
exclusiveBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel + numberOfBuffersPerGate, 
inputBufferPoolUsageGauge.calculateTotalBuffers(inputGate1));
+   }
+   }
+
+   @Test
+   public void testExclusiveBuffersUsage() throws IOException {
+   int numberOfRemoteChannelsGate1 = 2;
+   int numberOfLocalChannelsGate1 = 0;
+   int numberOfRemoteChannelsGate2 = 1;
+   int numberOfLocalChannelsGate2 = 1;
+
+   int numberOfRemoteChannelsTotal = numberOfRemoteChannelsGate1 + 
numberOfRemoteChannelsGate2;
+   int numberOfInputGates = 2;
+
+   int buffersPerChannel = 2;
+   int extraNetworkBuffersPerGate = 8;
+
+   

[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-07-01 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r299289710
 
 

 ##
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/consumer/InputBuffersMetricsTest.java
 ##
 @@ -0,0 +1,316 @@
+/*
+ * 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.runtime.io.network.partition.consumer;
+
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironment;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder;
+import org.apache.flink.runtime.io.network.TestingConnectionManager;
+import org.apache.flink.runtime.io.network.buffer.Buffer;
+import 
org.apache.flink.runtime.io.network.metrics.CreditBasedInputBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.ExclusiveBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.FloatingBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionType;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests the metrics for input buffers usage.
+ */
+public class InputBuffersMetricsTest extends TestLogger {
+
+   @Test
+   public void testCalculateTotalBuffersSize() throws IOException {
+   int numberOfRemoteChannels = 2;
+   int numberOfLocalChannels = 0;
+
+   int numberOfBufferPerChannel = 2;
+   int numberOfBuffersPerGate = 8;
+
+   NettyShuffleEnvironment network = new 
NettyShuffleEnvironmentBuilder()
+   .setNetworkBuffersPerChannel(numberOfBufferPerChannel)
+   
.setFloatingNetworkBuffersPerGate(numberOfBuffersPerGate)
+   .build();
+
+   Tuple3, 
List> tuple1 = buildInputGate(
+   network,
+   numberOfRemoteChannels,
+   numberOfLocalChannels);
+
+   SingleInputGate inputGate1 = tuple1.f0;
+
+   SingleInputGate[] inputGates = new 
SingleInputGate[]{inputGate1};
+   FloatingBuffersUsageGauge floatingBuffersUsageGauge = new 
FloatingBuffersUsageGauge(inputGates);
+   ExclusiveBuffersUsageGauge exclusiveBuffersUsageGauge = new 
ExclusiveBuffersUsageGauge(inputGates);
+   CreditBasedInputBuffersUsageGauge inputBufferPoolUsageGauge = 
new CreditBasedInputBuffersUsageGauge(
+   floatingBuffersUsageGauge,
+   exclusiveBuffersUsageGauge,
+   inputGates);
+
+   try (CloseableRegistry closeableRegistry = new 
CloseableRegistry()) {
+
+   closeableRegistry.registerCloseable(network::close);
+   closeableRegistry.registerCloseable(inputGate1::close);
+
+   assertEquals(numberOfBuffersPerGate, 
floatingBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel, 
exclusiveBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel + numberOfBuffersPerGate, 
inputBufferPoolUsageGauge.calculateTotalBuffers(inputGate1));
+   }
+   }
+
+   @Test
+   public void testExclusiveBuffersUsage() throws IOException {
+   int numberOfRemoteChannelsGate1 = 2;
+   int numberOfLocalChannelsGate1 = 0;
+   int numberOfRemoteChannelsGate2 = 1;
+   int numberOfLocalChannelsGate2 = 1;
+
+   int numberOfRemoteChannelsTotal = numberOfRemoteChannelsGate1 + 
numberOfRemoteChannelsGate2;
+   int numberOfInputGates = 2;
+
+   int buffersPerChannel = 2;
+   int extraNetworkBuffersPerGate = 8;
+
+   

[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-07-01 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r299289630
 
 

 ##
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/consumer/InputBuffersMetricsTest.java
 ##
 @@ -0,0 +1,316 @@
+/*
+ * 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.runtime.io.network.partition.consumer;
+
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironment;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder;
+import org.apache.flink.runtime.io.network.TestingConnectionManager;
+import org.apache.flink.runtime.io.network.buffer.Buffer;
+import 
org.apache.flink.runtime.io.network.metrics.CreditBasedInputBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.ExclusiveBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.FloatingBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionType;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests the metrics for input buffers usage.
+ */
+public class InputBuffersMetricsTest extends TestLogger {
+
+   @Test
+   public void testCalculateTotalBuffersSize() throws IOException {
+   int numberOfRemoteChannels = 2;
+   int numberOfLocalChannels = 0;
+
+   int numberOfBufferPerChannel = 2;
+   int numberOfBuffersPerGate = 8;
+
+   NettyShuffleEnvironment network = new 
NettyShuffleEnvironmentBuilder()
+   .setNetworkBuffersPerChannel(numberOfBufferPerChannel)
+   
.setFloatingNetworkBuffersPerGate(numberOfBuffersPerGate)
+   .build();
+
+   Tuple3, 
List> tuple1 = buildInputGate(
+   network,
+   numberOfRemoteChannels,
+   numberOfLocalChannels);
+
+   SingleInputGate inputGate1 = tuple1.f0;
+
+   SingleInputGate[] inputGates = new 
SingleInputGate[]{inputGate1};
+   FloatingBuffersUsageGauge floatingBuffersUsageGauge = new 
FloatingBuffersUsageGauge(inputGates);
+   ExclusiveBuffersUsageGauge exclusiveBuffersUsageGauge = new 
ExclusiveBuffersUsageGauge(inputGates);
+   CreditBasedInputBuffersUsageGauge inputBufferPoolUsageGauge = 
new CreditBasedInputBuffersUsageGauge(
+   floatingBuffersUsageGauge,
+   exclusiveBuffersUsageGauge,
+   inputGates);
+
+   try (CloseableRegistry closeableRegistry = new 
CloseableRegistry()) {
+
+   closeableRegistry.registerCloseable(network::close);
+   closeableRegistry.registerCloseable(inputGate1::close);
+
+   assertEquals(numberOfBuffersPerGate, 
floatingBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel, 
exclusiveBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel + numberOfBuffersPerGate, 
inputBufferPoolUsageGauge.calculateTotalBuffers(inputGate1));
+   }
+   }
+
+   @Test
+   public void testExclusiveBuffersUsage() throws IOException {
+   int numberOfRemoteChannelsGate1 = 2;
+   int numberOfLocalChannelsGate1 = 0;
+   int numberOfRemoteChannelsGate2 = 1;
+   int numberOfLocalChannelsGate2 = 1;
+
+   int numberOfRemoteChannelsTotal = numberOfRemoteChannelsGate1 + 
numberOfRemoteChannelsGate2;
+   int numberOfInputGates = 2;
+
+   int buffersPerChannel = 2;
+   int extraNetworkBuffersPerGate = 8;
+
+   

[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-07-01 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r299288165
 
 

 ##
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/consumer/InputBuffersMetricsTest.java
 ##
 @@ -0,0 +1,316 @@
+/*
+ * 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.runtime.io.network.partition.consumer;
+
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironment;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder;
+import org.apache.flink.runtime.io.network.TestingConnectionManager;
+import org.apache.flink.runtime.io.network.buffer.Buffer;
+import 
org.apache.flink.runtime.io.network.metrics.CreditBasedInputBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.ExclusiveBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.FloatingBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionType;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests the metrics for input buffers usage.
+ */
+public class InputBuffersMetricsTest extends TestLogger {
+
+   @Test
+   public void testCalculateTotalBuffersSize() throws IOException {
+   int numberOfRemoteChannels = 2;
+   int numberOfLocalChannels = 0;
+
+   int numberOfBufferPerChannel = 2;
+   int numberOfBuffersPerGate = 8;
+
+   NettyShuffleEnvironment network = new 
NettyShuffleEnvironmentBuilder()
+   .setNetworkBuffersPerChannel(numberOfBufferPerChannel)
+   
.setFloatingNetworkBuffersPerGate(numberOfBuffersPerGate)
+   .build();
+
+   Tuple3, 
List> tuple1 = buildInputGate(
+   network,
+   numberOfRemoteChannels,
+   numberOfLocalChannels);
+
+   SingleInputGate inputGate1 = tuple1.f0;
 
 Review comment:
   We only need `SingleInputGate` from tuple here, so it is simple 
`SinglerInputGate inputGate = buildInputGate(network, numberOfRemoteChannels, 
numberOfLocalChannels).f0` directly.


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


[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-07-01 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r299287676
 
 

 ##
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/consumer/InputBuffersMetricsTest.java
 ##
 @@ -0,0 +1,301 @@
+/*
+ * 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.runtime.io.network.partition.consumer;
+
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironment;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder;
+import org.apache.flink.runtime.io.network.TestingConnectionManager;
+import org.apache.flink.runtime.io.network.buffer.Buffer;
+import 
org.apache.flink.runtime.io.network.metrics.CreditBasedInputBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.ExclusiveBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.FloatingBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionID;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionType;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests the metrics for input buffers usage.
+ */
+public class InputBuffersMetricsTest extends TestLogger {
+
+   @Test
+   public void testCalculateTotalBuffersSize() throws IOException {
+   int numberOfRemoteChannels = 2;
+   int numberOfLocalChannels = 0;
+
+   int buffersPerChannel = 2;
+   int extraNetworkBuffersPerGate = 8;
+
+   CloseableRegistry closeableRegistry = new CloseableRegistry();
+
+   NettyShuffleEnvironment network = new 
NettyShuffleEnvironmentBuilder()
+   .setNetworkBuffersPerChannel(buffersPerChannel)
+   
.setFloatingNetworkBuffersPerGate(extraNetworkBuffersPerGate)
+   .build();
+
+   Tuple3, 
List> tuple1 = buildInputGate(
+   network,
+   numberOfRemoteChannels,
+   numberOfLocalChannels);
+
+   SingleInputGate inputGate1 = tuple1.f0;
+
+   closeableRegistry.registerCloseable(network::close);
+   closeableRegistry.registerCloseable(inputGate1::close);
+
+   try {
+   SingleInputGate[] inputGates = new 
SingleInputGate[]{inputGate1};
+   FloatingBuffersUsageGauge floatingBuffersUsageGauge = 
new FloatingBuffersUsageGauge(inputGates);
+   ExclusiveBuffersUsageGauge exclusiveBuffersUsageGauge = 
new ExclusiveBuffersUsageGauge(inputGates);
+   CreditBasedInputBuffersUsageGauge 
inputBufferPoolUsageGauge = new CreditBasedInputBuffersUsageGauge(
+   floatingBuffersUsageGauge,
+   exclusiveBuffersUsageGauge,
+   inputGates);
+
+   assertEquals(extraNetworkBuffersPerGate, 
floatingBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
buffersPerChannel, 
exclusiveBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * buffersPerChannel 
+ extraNetworkBuffersPerGate, 
inputBufferPoolUsageGauge.calculateTotalBuffers(inputGate1));
+   } finally {
+   closeableRegistry.close();
+   }
+   }
+
+   @Test
+   public void testExclusiveBuffersUsage() throws IOException {
+   int numberOfRemoteChannelsGate1 = 2;
+   int numberOfLocalChannelsGate1 = 0;
+   int numberOfRemoteChannelsGate2 = 1;
+   int numberOfLocalChannelsGate2 = 1;
+
+   int numberOfRemoteChannelsTotal = numberOfRemoteChannelsGate1 + 

[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-07-01 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r299287578
 
 

 ##
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/consumer/InputBuffersMetricsTest.java
 ##
 @@ -0,0 +1,316 @@
+/*
+ * 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.runtime.io.network.partition.consumer;
+
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironment;
+import org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder;
+import org.apache.flink.runtime.io.network.TestingConnectionManager;
+import org.apache.flink.runtime.io.network.buffer.Buffer;
+import 
org.apache.flink.runtime.io.network.metrics.CreditBasedInputBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.ExclusiveBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.metrics.FloatingBuffersUsageGauge;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionType;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests the metrics for input buffers usage.
+ */
+public class InputBuffersMetricsTest extends TestLogger {
+
+   @Test
+   public void testCalculateTotalBuffersSize() throws IOException {
+   int numberOfRemoteChannels = 2;
+   int numberOfLocalChannels = 0;
+
+   int numberOfBufferPerChannel = 2;
+   int numberOfBuffersPerGate = 8;
+
+   NettyShuffleEnvironment network = new 
NettyShuffleEnvironmentBuilder()
+   .setNetworkBuffersPerChannel(numberOfBufferPerChannel)
+   
.setFloatingNetworkBuffersPerGate(numberOfBuffersPerGate)
+   .build();
+
+   Tuple3, 
List> tuple1 = buildInputGate(
+   network,
+   numberOfRemoteChannels,
+   numberOfLocalChannels);
+
+   SingleInputGate inputGate1 = tuple1.f0;
+
+   SingleInputGate[] inputGates = new 
SingleInputGate[]{inputGate1};
+   FloatingBuffersUsageGauge floatingBuffersUsageGauge = new 
FloatingBuffersUsageGauge(inputGates);
+   ExclusiveBuffersUsageGauge exclusiveBuffersUsageGauge = new 
ExclusiveBuffersUsageGauge(inputGates);
+   CreditBasedInputBuffersUsageGauge inputBufferPoolUsageGauge = 
new CreditBasedInputBuffersUsageGauge(
+   floatingBuffersUsageGauge,
+   exclusiveBuffersUsageGauge,
+   inputGates);
+
+   try (CloseableRegistry closeableRegistry = new 
CloseableRegistry()) {
+
+   closeableRegistry.registerCloseable(network::close);
+   closeableRegistry.registerCloseable(inputGate1::close);
+
+   assertEquals(numberOfBuffersPerGate, 
floatingBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel, 
exclusiveBuffersUsageGauge.calculateTotalBuffers(inputGate1));
+   assertEquals(numberOfRemoteChannels * 
numberOfBufferPerChannel + numberOfBuffersPerGate, 
inputBufferPoolUsageGauge.calculateTotalBuffers(inputGate1));
+   }
+   }
+
+   @Test
+   public void testExclusiveBuffersUsage() throws IOException {
+   int numberOfRemoteChannelsGate1 = 2;
+   int numberOfLocalChannelsGate1 = 0;
+   int numberOfRemoteChannelsGate2 = 1;
+   int numberOfLocalChannelsGate2 = 1;
+
+   int numberOfRemoteChannelsTotal = numberOfRemoteChannelsGate1 + 
numberOfRemoteChannelsGate2;
+   int numberOfInputGates = 2;
+
+   int buffersPerChannel = 2;
+   int extraNetworkBuffersPerGate = 8;
+
+   

[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-05-29 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r288852908
 
 

 ##
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/NetworkEnvironment.java
 ##
 @@ -328,7 +332,17 @@ private void registerInputMetrics(MetricGroup inputGroup, 
MetricGroup buffersGro
InputGateMetrics.registerQueueLengthMetrics(inputGroup, 
inputGates);
}
buffersGroup.gauge(METRIC_INPUT_QUEUE_LENGTH, new 
InputBuffersGauge(inputGates));
-   buffersGroup.gauge(METRIC_INPUT_POOL_USAGE, new 
InputBufferPoolUsageGauge(inputGates));
+
+   if (config.isCreditBased()) {
 
 Review comment:
   For exclusive case there is no buffer pool actually. So maybe we could break 
down the new class names into `ExclusiveBuffersUsageGauge`, 
`FloatingBuffersUsageGauge`, `InputBuffersUsageGauge` instead?
   
   But considering the metric name compatibility with before, we might still 
use `METRIC_INPUT_POOL_USAGE` in credit-based mode to correspond with 
`InputBuffersUsageGauge`.


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


[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-05-29 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r288852908
 
 

 ##
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/NetworkEnvironment.java
 ##
 @@ -328,7 +332,17 @@ private void registerInputMetrics(MetricGroup inputGroup, 
MetricGroup buffersGro
InputGateMetrics.registerQueueLengthMetrics(inputGroup, 
inputGates);
}
buffersGroup.gauge(METRIC_INPUT_QUEUE_LENGTH, new 
InputBuffersGauge(inputGates));
-   buffersGroup.gauge(METRIC_INPUT_POOL_USAGE, new 
InputBufferPoolUsageGauge(inputGates));
+
+   if (config.isCreditBased()) {
 
 Review comment:
   For exclusive case there is no buffer pool actually. So maybe we could break 
down into `ExclusiveBuffersUsageGauge`, `FloatingBuffersUsageGauge`, 
`InputBuffersUsageGauge` instead?
   
   But considering the metric name compatibility with before, we might still 
use `METRIC_INPUT_POOL_USAGE` in credit-based mode to correspond with 
`InputBuffersUsageGauge`.


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


[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-05-29 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r288853879
 
 

 ##
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/NetworkEnvironment.java
 ##
 @@ -75,6 +76,9 @@
private static final String METRIC_OUTPUT_POOL_USAGE = "outPoolUsage";
private static final String METRIC_INPUT_QUEUE_LENGTH = 
"inputQueueLength";
private static final String METRIC_INPUT_POOL_USAGE = "inPoolUsage";
+   private static final String 
METRIC_CREDIT_BASED_FLOATING_BUFFER_POOL_USAGE = "floatingBufferUsage";
 
 Review comment:
   I think it is better to not add the keywords `CREDIT-BASED` here, because 
after we remove the deprecated network codes finally, it is no need to 
emphasize this term any more. The terms of exclusive/floating already indicate 
that.
   Also it should be consistent between variable name and value, like 
`METRIC_FLOATING_BUFFERS_USAGE = "floatingBuffersUsage"`. ditto for the below 
case of exclusive.


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


[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-05-29 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r288853879
 
 

 ##
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/NetworkEnvironment.java
 ##
 @@ -75,6 +76,9 @@
private static final String METRIC_OUTPUT_POOL_USAGE = "outPoolUsage";
private static final String METRIC_INPUT_QUEUE_LENGTH = 
"inputQueueLength";
private static final String METRIC_INPUT_POOL_USAGE = "inPoolUsage";
+   private static final String 
METRIC_CREDIT_BASED_FLOATING_BUFFER_POOL_USAGE = "floatingBufferUsage";
 
 Review comment:
   I think it is better to not add the keywords `CREDIT-BASED` here, because 
after we remove the deprecated network codes finally, it is no need to 
emphasize this term any more. The terms of exclusive/floating already indicate 
that.
   Also it should be consistent between variable name and value, like 
`METRIC_FLOATING_BUFFERS_USAGE = "floatingBuffersUsage"`


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


[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-05-29 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r288852908
 
 

 ##
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/NetworkEnvironment.java
 ##
 @@ -328,7 +332,17 @@ private void registerInputMetrics(MetricGroup inputGroup, 
MetricGroup buffersGro
InputGateMetrics.registerQueueLengthMetrics(inputGroup, 
inputGates);
}
buffersGroup.gauge(METRIC_INPUT_QUEUE_LENGTH, new 
InputBuffersGauge(inputGates));
-   buffersGroup.gauge(METRIC_INPUT_POOL_USAGE, new 
InputBufferPoolUsageGauge(inputGates));
+
+   if (config.isCreditBased()) {
 
 Review comment:
   For exclusive case there is no buffer pool actually. So maybe we could break 
down into `ExclusiveBuffersUsageGauge`, `FloatingBuffersUsageGauge`, 
`InputBuffersUsageGauge` instead?


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


[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-05-29 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r288852908
 
 

 ##
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/NetworkEnvironment.java
 ##
 @@ -328,7 +332,17 @@ private void registerInputMetrics(MetricGroup inputGroup, 
MetricGroup buffersGro
InputGateMetrics.registerQueueLengthMetrics(inputGroup, 
inputGates);
}
buffersGroup.gauge(METRIC_INPUT_QUEUE_LENGTH, new 
InputBuffersGauge(inputGates));
-   buffersGroup.gauge(METRIC_INPUT_POOL_USAGE, new 
InputBufferPoolUsageGauge(inputGates));
+
+   if (config.isCreditBased()) {
 
 Review comment:
   For exclusive case there are no buffer pool actually. So maybe we could 
break down into `ExclusiveBuffersUsageGauge`, `FloatingBuffersUsageGauge`, 
`InputBuffersUsageGauge` instead?


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


[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-05-29 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r288852438
 
 

 ##
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/metrics/CreditBasedInputBufferPoolMetric.java
 ##
 @@ -0,0 +1,136 @@
+/*
+ * 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.runtime.io.network.metrics;
+
+import org.apache.flink.metrics.Gauge;
+import org.apache.flink.runtime.io.network.partition.consumer.InputChannel;
+import 
org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel;
+import org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate;
+
+/**
+ * Gauge metric measuring the input buffer pool usage gauge for {@link 
SingleInputGate}s under credit based mode.
+ */
+public class CreditBasedInputBufferPoolMetric {
+
+   /**
+* Gauge metric measuring the floating buffer usage for {@link 
SingleInputGate}.
+*/
+   public static class FloatingBufferPoolUsage implements Gauge {
+
+   public SingleInputGate[] inputGates;
+
+   public FloatingBufferPoolUsage(SingleInputGate[] inputGates) {
+   this.inputGates = inputGates;
+   }
+
+   @Override
+   public Float getValue() {
+   int leftFloatingBuffer = 0;
+   int requestedFloatingBuffer = 0;
+
+   for (SingleInputGate inputGate : inputGates) {
+   requestedFloatingBuffer += 
inputGate.getBufferPool().bestEffortGetNumOfUsedBuffers();
+   for (InputChannel ic : 
inputGate.getInputChannels().values()) {
+   if (ic instanceof RemoteInputChannel) {
+   leftFloatingBuffer += 
((RemoteInputChannel) ic).unsafeGetFloatingBufferLeft();
+   }
+   }
+   }
+
+   if (requestedFloatingBuffer == 0) {
+   return 0.0f;
+   } else {
+   return 1 - ((float) leftFloatingBuffer) / 
requestedFloatingBuffer;
+   }
+   }
+   }
+
+   /**
+* Gauge metric measuring the exclusive buffer usage for {@link 
SingleInputGate}.
+*/
+   public static class ExclusiveBufferPoolUsage implements Gauge {
+
+   public SingleInputGate[] inputGates;
+
+   public ExclusiveBufferPoolUsage(SingleInputGate[] inputGates) {
+   this.inputGates = inputGates;
+   }
+
+   @Override
+   public Float getValue() {
+   int usedExclusiveBuffer = 0;
+   int requestedExclusiveBuffer = 0;
+
+   for (SingleInputGate inputGate : inputGates) {
+   for (InputChannel ic : 
inputGate.getInputChannels().values()) {
+   if (ic instanceof RemoteInputChannel) {
+   requestedExclusiveBuffer += 
((RemoteInputChannel) ic).getInitialCredit();
+   usedExclusiveBuffer += 
((RemoteInputChannel) ic).unsafeGetExclusiveBufferUsed();
+   }
+   }
+   }
+
+   if (requestedExclusiveBuffer != 0) {
+   return ((float) usedExclusiveBuffer) / 
requestedExclusiveBuffer;
+   } else {
+   return 0.0f;
+   }
+   }
+   }
+
+   /**
+* Gauge metric measuring the overall buffer usage for {@link 
SingleInputGate} under credit based mode.
+*/
+   public static class InputBufferPoolUsageGauge implements Gauge {
+
+   public SingleInputGate[] inputGates;
+
+   public 

[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-05-29 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r288851783
 
 

 ##
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/metrics/CreditBasedInputBufferPoolMetric.java
 ##
 @@ -0,0 +1,136 @@
+/*
+ * 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.runtime.io.network.metrics;
+
+import org.apache.flink.metrics.Gauge;
+import org.apache.flink.runtime.io.network.partition.consumer.InputChannel;
+import 
org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel;
+import org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate;
+
+/**
+ * Gauge metric measuring the input buffer pool usage gauge for {@link 
SingleInputGate}s under credit based mode.
+ */
+public class CreditBasedInputBufferPoolMetric {
+
+   /**
+* Gauge metric measuring the floating buffer usage for {@link 
SingleInputGate}.
+*/
+   public static class FloatingBufferPoolUsage implements Gauge {
+
+   public SingleInputGate[] inputGates;
+
+   public FloatingBufferPoolUsage(SingleInputGate[] inputGates) {
+   this.inputGates = inputGates;
+   }
+
+   @Override
+   public Float getValue() {
+   int leftFloatingBuffer = 0;
+   int requestedFloatingBuffer = 0;
+
+   for (SingleInputGate inputGate : inputGates) {
+   requestedFloatingBuffer += 
inputGate.getBufferPool().bestEffortGetNumOfUsedBuffers();
+   for (InputChannel ic : 
inputGate.getInputChannels().values()) {
+   if (ic instanceof RemoteInputChannel) {
+   leftFloatingBuffer += 
((RemoteInputChannel) ic).unsafeGetFloatingBufferLeft();
+   }
+   }
+   }
+
+   if (requestedFloatingBuffer == 0) {
+   return 0.0f;
+   } else {
+   return 1 - ((float) leftFloatingBuffer) / 
requestedFloatingBuffer;
 
 Review comment:
   I think it is not very accurate here. 
   It should be `(requestedFloatingBuffer - leftFloatingBuffer) / 
LocalBufferPool.getNumBuffers`


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


[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-05-29 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r288849334
 
 

 ##
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/RemoteInputChannel.java
 ##
 @@ -439,6 +439,14 @@ public int getInitialCredit() {
return initialCredit;
}
 
+   public int unsafeGetExclusiveBufferUsed() {
+   return Math.max(0, initialCredit - 
bufferQueue.exclusiveBuffers.size());
+   }
+
+   public int unsafeGetFloatingBufferLeft() {
 
 Review comment:
   FloatingBuffers
   Left->Available?


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


[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-05-29 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r288849334
 
 

 ##
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/RemoteInputChannel.java
 ##
 @@ -439,6 +439,14 @@ public int getInitialCredit() {
return initialCredit;
}
 
+   public int unsafeGetExclusiveBufferUsed() {
+   return Math.max(0, initialCredit - 
bufferQueue.exclusiveBuffers.size());
+   }
+
+   public int unsafeGetFloatingBufferLeft() {
 
 Review comment:
   FloatingBuffers
   Left->Used to consistent with above ExclusiveBuffersUsed?


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


[GitHub] [flink] zhijiangW commented on a change in pull request #8455: [FLINK-12284][Network, Metrics]Fix the incorrect inputBufferUsage metric in credit-based network mode

2019-05-29 Thread GitBox
zhijiangW commented on a change in pull request #8455: 
[FLINK-12284][Network,Metrics]Fix the incorrect inputBufferUsage metric in 
credit-based network mode
URL: https://github.com/apache/flink/pull/8455#discussion_r288849162
 
 

 ##
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/RemoteInputChannel.java
 ##
 @@ -439,6 +439,14 @@ public int getInitialCredit() {
return initialCredit;
}
 
+   public int unsafeGetExclusiveBufferUsed() {
 
 Review comment:
   ExclusiveBuffers


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