fuweng11 commented on code in PR #10916:
URL: https://github.com/apache/inlong/pull/10916#discussion_r1737676926


##########
inlong-manager/manager-plugins/base/src/main/java/org/apache/inlong/manager/plugin/flink/FlinkParallelismOptimizer.java:
##########
@@ -0,0 +1,218 @@
+/*
+ * 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.inlong.manager.plugin.flink;
+
+import org.apache.inlong.audit.AuditIdEnum;
+import org.apache.inlong.audit.entity.FlowType;
+import org.apache.inlong.manager.pojo.audit.AuditInfo;
+import org.apache.inlong.manager.pojo.stream.InlongStreamInfo;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.http.HttpEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+import java.util.StringJoiner;
+
+import static org.apache.inlong.audit.consts.OpenApiConstants.*;
+import static org.apache.inlong.manager.common.consts.InlongConstants.*;
+
+/**
+ *     This class is used to calculate the recommended parallelism based on 
the maximum message per second per core.
+ *     The data volume is calculated based on the average data count per hour.
+ *     The data count is retrieved from the inlong audit API.
+ */
+@Slf4j
+@Component
+public class FlinkParallelismOptimizer {
+
+    @Value("${audit.query.url:http://127.0.0.1:10080}";)
+    public String auditQueryUrl;
+
+    private static final int MAX_PARALLELISM = 2048;
+    private long maximumMessagePerSecondPerCore = 1000L;
+    private static final long DEFAULT_ERROR_DATA_VOLUME = 0L;
+    private static final FlowType DEFAULT_FLOWTYPE = FlowType.OUTPUT;
+    private static final String DEFAULT_AUDIT_TYPE = "DataProxy";
+    private static final String AUDIT_CYCLE_REALTIME = "1";
+    // maxmimum data scale counting range in hours
+    private static final int DATA_SCALE_COUNTING_RANGE_IN_HOURS = 1;
+    // sample time format: 2024-08-23T22:47:38.866
+    private static final String AUDIT_QUERY_DATE_TIME_FORMAT = 
"yyyy-MM-dd'T'HH:mm:ss.SSS";
+
+    private static final String LOGTS_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
+    private static final String TIMEZONE_REGEX = "([+-])(\\d):";
+
+    /**
+     * Calculate recommended parallelism based on maximum message per second 
per core
+     *
+     * @return Recommended parallelism
+     */
+    public int calculateRecommendedParallelism(List<InlongStreamInfo> 
streamInfos) {
+        long averageDataVolume;
+        InlongStreamInfo streamInfo = streamInfos.get(0);
+        try {
+            averageDataVolume = getAverageDataVolume(streamInfo);
+            log.info("Retrieved data volume: {}", averageDataVolume);
+        } catch (Exception e) {
+            log.error("Error retrieving data volume: {}", e.getMessage(), e);
+            log.warn("Using default data volume: {}", 
DEFAULT_ERROR_DATA_VOLUME);

Review Comment:
   Please delete one of the warm and error logs.



-- 
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: commits-unsubscr...@inlong.apache.org

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

Reply via email to