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


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

Review Comment:
   If last comment makes sense, we could update the method name to 
`adjustViaNumKeyGroupsOrPartitions`.
   
   And remove `int maxParallelism, int numSourcePartitions,` from parameters, 
and add `numKeyGroupsOrPartitions` as the parameter.



##########
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:
   Is this method also refactor?
   
   If so, it's better to do in the first refactor commit.



##########
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:
   I prefer these lines keep in the original method.
   
   Because current method is pretty long, it's better to only adjust 
parallelism based on  `numKeyGroupsOrPartitions`.



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