dawidwys commented on a change in pull request #17737:
URL: https://github.com/apache/flink/pull/17737#discussion_r746352025



##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/throughput/BufferDebloater.java
##########
@@ -83,6 +81,20 @@ public OptionalInt recalculateBufferSize(long 
currentThroughput, int buffersInUs
         return OptionalInt.of(newSize);
     }
 
+    @VisibleForTesting
+    boolean skipUpdate(int newSize) {
+        if (newSize == lastBufferSize) {
+            return true;
+        }
+
+        if (newSize <= minBufferSize || newSize >= maxBufferSize) {

Review comment:
       Mostly to double check, we cannot end up here with `newSize < 
minBufferSize` or `newSize > maxBufferSize`, right? At most we can have 
equality?

##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/throughput/BufferDebloaterTest.java
##########
@@ -163,6 +164,54 @@ public void 
testAnnouncedMinBufferSizeEvenDespiteLastDiffLessThanThreshold() {
         bufferDebloater.recalculateBufferSize(40, numberOfBuffersInUse);
     }
 
+    @Test
+    public void testSkipUpdate() {
+        int maxBufferSize = 32768;
+        int minBufferSize = 256;
+        double threshold = 0.3;
+        BufferDebloater bufferDebloater =
+                testBufferDebloater()
+                        .withDebloatTarget(1000)
+                        .withBufferSize(minBufferSize, maxBufferSize)
+                        // 30 % Threshold.
+                        .withThresholdPercentages((int) (threshold * 100))
+                        .getBufferDebloater();
+
+        int currentBufferSize = maxBufferSize / 2;
+
+        OptionalInt optionalInt = 
bufferDebloater.recalculateBufferSize(currentBufferSize, 1);
+        assertTrue(optionalInt.isPresent());
+        assertEquals(currentBufferSize, optionalInt.getAsInt());
+
+        // It is true because less than threshold.
+        assertTrue(bufferDebloater.skipUpdate(currentBufferSize));
+        assertTrue(bufferDebloater.skipUpdate(currentBufferSize - 1));
+        assertTrue(bufferDebloater.skipUpdate(currentBufferSize + 1));
+
+        assertTrue(
+                bufferDebloater.skipUpdate(
+                        currentBufferSize - (int) (currentBufferSize * 
threshold) + 1));
+        assertTrue(
+                bufferDebloater.skipUpdate(
+                        currentBufferSize + (int) (currentBufferSize * 
threshold) - 1));
+
+        // It is false because it reaches threshold.
+        assertFalse(
+                bufferDebloater.skipUpdate(
+                        currentBufferSize - (int) (currentBufferSize * 
threshold)));
+        assertFalse(
+                bufferDebloater.skipUpdate(
+                        currentBufferSize + (int) (currentBufferSize * 
threshold)));
+        assertFalse(bufferDebloater.skipUpdate(minBufferSize + 1));

Review comment:
       this case might be slightly misleading, don't you think? It still tests 
the line 95 in `skipUpdate`, right? It has little to do with `minBufferSize`.




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to