akalash commented on a change in pull request #16628:
URL: https://github.com/apache/flink/pull/16628#discussion_r680004548



##########
File path: 
flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/autobuffersize/BufferSizeCalculator.java
##########
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.runtime.tasks.autobuffersize;
+
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.TaskManagerOptions;
+import org.apache.flink.runtime.io.network.partition.consumer.IndexedInputGate;
+import org.apache.flink.runtime.mailbox.MailboxExecutor;
+import org.apache.flink.runtime.throughput.ThroughputCalculator;
+import org.apache.flink.streaming.runtime.tasks.TimerService;
+
+import static 
org.apache.flink.configuration.TaskManagerOptions.AUTOMATIC_BUFFER_ADJUSTMENT_CONSUMPTION_TIME;
+import static 
org.apache.flink.configuration.TaskManagerOptions.AUTOMATIC_BUFFER_ADJUSTMENT_PERIOD;
+import static 
org.apache.flink.configuration.TaskManagerOptions.AUTOMATIC_BUFFER_ADJUSTMENT_THRESHOLD_PERCENTAGES;
+import static org.apache.flink.util.Preconditions.checkArgument;
+
+/**
+ * Class for automatic calculation of the buffer size based on the current 
throughput and
+ * configuration.
+ */
+public class BufferSizeCalculator {
+    private static final double MILLIS_IN_SECOND = 1000.0;
+    private final ThroughputCalculator throughputCalculator;
+    private final int bufferAdjustmentPeriod;
+
+    /**
+     * How different should be the total buffer size compare to throughput 
(when it is 1.0 then
+     * bufferSize == throughput).
+     */
+    private final double throughputFactor;
+
+    private final IndexedInputGate[] inputGates;
+    private final long maxBufferSize;
+    private final long minBufferSize;
+    private final int bufferAdjustmentThresholdPercentages;
+    private final boolean isBufferSizeRecalculationEnabled;
+
+    private long lastBufferSize;
+
+    public BufferSizeCalculator(
+            ThroughputCalculator throughputCalculator,
+            Configuration taskConfig,
+            IndexedInputGate[] inputGates) {
+        this.throughputCalculator = throughputCalculator;
+        this.inputGates = inputGates;
+        this.bufferAdjustmentPeriod = 
taskConfig.get(AUTOMATIC_BUFFER_ADJUSTMENT_PERIOD);
+        this.throughputFactor =
+                taskConfig.get(AUTOMATIC_BUFFER_ADJUSTMENT_CONSUMPTION_TIME) / 
MILLIS_IN_SECOND;
+        this.maxBufferSize = 
taskConfig.get(TaskManagerOptions.MEMORY_SEGMENT_SIZE).getBytes();
+        this.minBufferSize = 
taskConfig.get(TaskManagerOptions.MIN_MEMORY_SEGMENT_SIZE).getBytes();
+        this.isBufferSizeRecalculationEnabled =
+                
taskConfig.get(TaskManagerOptions.AUTOMATIC_BUFFER_ADJUSTMENT_ENABLED);

Review comment:
       It depends on what we want to do when it has disabled. I do it from the 
inside because I allow calculating the throughput despite `buffer adjustment` 
being disabled. But if we want to disable changing buffer size along with the 
throughput calculation we can do it from outside.




-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to