huyuanfeng2018 commented on code in PR #904:
URL: 
https://github.com/apache/flink-kubernetes-operator/pull/904#discussion_r1841449375


##########
flink-autoscaler/src/main/java/org/apache/flink/autoscaler/ParallelismAdjuster.java:
##########
@@ -106,4 +107,43 @@ public static <KEY, Context extends 
JobAutoScalerContext<KEY>> int adjust(
                 context.getConfiguration().get(SCALING_EVENT_INTERVAL));
         return p;
     }
+
+    private static int calculateMinimumParallelism(
+            int numKeyGroupsOrPartitions, int newParallelism, int 
parallelismLowerLimit) {
+        int p = newParallelism;
+        for (; p > 0; p--) {
+            if (numKeyGroupsOrPartitions / p > numKeyGroupsOrPartitions / 
newParallelism) {
+                if (numKeyGroupsOrPartitions % p != 0) {
+                    p++;
+                }
+                break;
+            }
+        }
+        p = Math.max(p, parallelismLowerLimit);
+        return p;
+    }

Review Comment:
   nice catch. I missed this
   
   



##########
flink-autoscaler/src/main/java/org/apache/flink/autoscaler/ParallelismAdjuster.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.autoscaler;
+
+import org.apache.flink.autoscaler.event.AutoScalerEventHandler;
+import org.apache.flink.autoscaler.topology.ShipStrategy;
+import org.apache.flink.runtime.jobgraph.JobVertexID;
+
+import java.util.Collection;
+
+import static 
org.apache.flink.autoscaler.JobVertexScaler.SCALE_LIMITED_MESSAGE_FORMAT;
+import static org.apache.flink.autoscaler.JobVertexScaler.SCALING_LIMITED;
+import static 
org.apache.flink.autoscaler.config.AutoScalerOptions.SCALING_EVENT_INTERVAL;
+import static org.apache.flink.autoscaler.topology.ShipStrategy.HASH;
+
+/**
+ * Component responsible adjusts the parallelism of a vertex.
+ *
+ * <p>When input vertex {@link ShipStrategy} is {@link ShipStrategy#HASH} or 
knows the number of
+ * current partitions of vertex. We hope to adjust the parallelism of the 
current vertex according
+ * to the number of key groups or partitions to achieve the goal of evenly 
distributing data among
+ * subtasks or maximizing utilization.
+ */
+public class ParallelismAdjuster {
+
+    public static <KEY, Context extends JobAutoScalerContext<KEY>> int adjust(
+            JobVertexID vertex,
+            Context context,
+            AutoScalerEventHandler<KEY, Context> eventHandler,
+            int maxParallelism,
+            int numSourcePartitions,
+            int newParallelism,
+            int upperBound,
+            int parallelismLowerLimit,
+            Collection<ShipStrategy> inputShipStrategies) {
+
+        var adjustByMaxParallelismOrPartitions =
+                numSourcePartitions > 0 || inputShipStrategies.contains(HASH);
+        if (!adjustByMaxParallelismOrPartitions) {
+            return newParallelism;
+        }
+
+        var numKeyGroupsOrPartitions =
+                numSourcePartitions <= 0 ? maxParallelism : 
numSourcePartitions;

Review Comment:
   IMHO, in our subsequent work, there may be other ways to adjust the logic of 
parallelism. It’s not just based on the numPartitions or keygroups, so I want 
to unify it with ParallelismAdjuster. WDYT?
   
   
   



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