You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/08/18 13:59:56 UTC

[GitHub] [inlong] rhizoma-atractylodis opened a new pull request, #5595: [INLONG-5101][DataProxy] Optimize load balancing for DataProxy

rhizoma-atractylodis opened a new pull request, #5595:
URL: https://github.com/apache/inlong/pull/5595

   PR#5544 was closed due to wrong operation and 0 commits were merged


-- 
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-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] dockerzhang commented on pull request #5595: [INLONG-5101][DataProxy] Optimize load balancing for DataProxy

Posted by GitBox <gi...@apache.org>.
dockerzhang commented on PR #5595:
URL: https://github.com/apache/inlong/pull/5595#issuecomment-1232552239

   @rhizoma-atractylodis please update the document at same time.


-- 
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-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] baomingyu commented on a diff in pull request #5595: [INLONG-5101][DataProxy] Optimize load balancing for DataProxy

Posted by GitBox <gi...@apache.org>.
baomingyu commented on code in PR #5595:
URL: https://github.com/apache/inlong/pull/5595#discussion_r956868736


##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/network/Sender.java:
##########
@@ -513,15 +537,39 @@ private boolean validAttribute(String attr) {
     /**
      * Following methods used by asynchronously message sending.
      */
-    public void asyncSendMessage(EncodeObject encodeObject, SendMessageCallback callback, String msgUUID,
-            long timeout, TimeUnit timeUnit) throws ProxysdkException {
+    public void asyncSendMessage(EncodeObject encodeObject, SendMessageCallback callback,
+                                 String msgUUID, long timeout, TimeUnit timeUnit) throws ProxysdkException {
+        asyncSendMessage(encodeObject, callback, msgUUID, timeout,
+                timeUnit, ConfigConstants.DEFAULT_LOAD_BALANCE);
+    }
+
+    public void asyncSendMessage(EncodeObject encodeObject,
+                                 SendMessageCallback callback, String msgUUID,
+                                 long timeout, TimeUnit timeUnit, String loadBalance) throws ProxysdkException {
         metricWorker.recordNumByKey(encodeObject.getMessageId(), encodeObject.getGroupId(),
                 encodeObject.getStreamId(), Utils.getLocalIp(), encodeObject.getPackageTime(),
                 encodeObject.getDt(), encodeObject.getRealCnt());
 
         // send message package time
 
-        NettyClient client = clientMgr.getClientByRoundRobin();
+        NettyClient client = null;
+        switch (loadBalance) {
+            case "random":
+                client = clientMgr.getClientByRandom();

Review Comment:
   plz make "random"、“consistency hash” ... as constants in constants class



##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/utils/LoadBalance.java:
##########
@@ -0,0 +1,22 @@
+/*
+ * 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.sdk.dataproxy.utils;
+
+public enum LoadBalance {
+    RANDOM,ROUND_ROBIN,CONSISTENCY_HASH
+}

Review Comment:
   only three load balance enum?  what are these "weight robin“, "weight random""



-- 
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-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] vernedeng commented on a diff in pull request #5595: [INLONG-5101][DataProxy] Optimize load balancing for DataProxy

Posted by GitBox <gi...@apache.org>.
vernedeng commented on code in PR #5595:
URL: https://github.com/apache/inlong/pull/5595#discussion_r957275485


##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/network/ClientMgr.java:
##########
@@ -348,6 +351,90 @@ public synchronized NettyClient getClientByRoundRobin() {
         return client;
     }
 
+    public synchronized NettyClient getClientByRandom() {
+        NettyClient client;
+        if (clientList.isEmpty()) {
+            return null;
+        }
+        int currSize = clientList.size();
+        int maxRetry = this.configure.getMaxRetry();
+        Random random = new Random(System.currentTimeMillis());
+        do {
+            int randomId = random.nextInt();
+            client = clientList.get(randomId % currSize);
+            if (client != null && client.isActive()) {
+                break;
+            }
+            maxRetry--;
+        } while (maxRetry > 0);
+        if (client == null || !client.isActive()) {
+            return null;
+        }
+        return client;
+    }
+
+    public synchronized NettyClient getClientByConsistencyHash(String messageId) {
+        NettyClient client;
+        if (clientList.isEmpty()) {
+            return null;
+        }
+        String hash = ConsistencyHashUtil.hashMurMurHash(messageId);
+        HashRing cluster = HashRing.getInstance();
+        HostInfo info = cluster.getNode(hash);
+        client = this.clientMap.get(info);
+        return client;
+    }
+
+//    public synchronized NettyClient getClientByLeastConnections() {}
+
+    public synchronized NettyClient getClientByWeightRoundRobin() {
+        NettyClient client = null;
+        double maxWeight = Double.MIN_VALUE;
+        int clientId = 0;
+        if (clientList.isEmpty()) {
+            return null;
+        }
+        int currSize = clientList.size();
+        for (int retryTime = 0; retryTime < currSize; retryTime++) {
+            currentIndex = (++currentIndex) % currSize;
+            client = clientList.get(currentIndex);
+            if (client != null && client.isActive() && client.getWeight() > maxWeight) {
+                clientId = currentIndex;
+            }
+        }
+        if (client == null || !client.isActive()) {
+            return null;
+        }
+        return clientList.get(clientId);
+    }
+
+    public synchronized NettyClient getClientByWeightRandom() {
+        NettyClient client;
+        double maxWeight = Double.MIN_VALUE;
+        int clientId = 0;
+        if (clientList.isEmpty()) {
+            return null;
+        }
+        int currSize = clientList.size();
+        int maxRetry = 1000;

Review Comment:
   plz make it configurable



-- 
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-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] vernedeng commented on a diff in pull request #5595: [INLONG-5101][DataProxy] Optimize load balancing for DataProxy

Posted by GitBox <gi...@apache.org>.
vernedeng commented on code in PR #5595:
URL: https://github.com/apache/inlong/pull/5595#discussion_r949744731


##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/utils/LoadBalance.java:
##########
@@ -0,0 +1,22 @@
+/*
+ * 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.sdk.dataproxy.utils;

Review Comment:
   it's more like **_constants_** rather than **_utils_**



-- 
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-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] rhizoma-atractylodis commented on a diff in pull request #5595: [INLONG-5101][DataProxy] Optimize load balancing for DataProxy

Posted by GitBox <gi...@apache.org>.
rhizoma-atractylodis commented on code in PR #5595:
URL: https://github.com/apache/inlong/pull/5595#discussion_r957880860


##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/network/ClientMgr.java:
##########
@@ -348,6 +351,90 @@ public synchronized NettyClient getClientByRoundRobin() {
         return client;
     }
 
+    public synchronized NettyClient getClientByRandom() {
+        NettyClient client;
+        if (clientList.isEmpty()) {
+            return null;
+        }
+        int currSize = clientList.size();
+        int maxRetry = this.configure.getMaxRetry();
+        Random random = new Random(System.currentTimeMillis());
+        do {
+            int randomId = random.nextInt();
+            client = clientList.get(randomId % currSize);
+            if (client != null && client.isActive()) {
+                break;
+            }
+            maxRetry--;
+        } while (maxRetry > 0);
+        if (client == null || !client.isActive()) {
+            return null;
+        }
+        return client;
+    }
+
+    public synchronized NettyClient getClientByConsistencyHash(String messageId) {
+        NettyClient client;
+        if (clientList.isEmpty()) {
+            return null;
+        }
+        String hash = ConsistencyHashUtil.hashMurMurHash(messageId);
+        HashRing cluster = HashRing.getInstance();
+        HostInfo info = cluster.getNode(hash);
+        client = this.clientMap.get(info);
+        return client;
+    }
+
+//    public synchronized NettyClient getClientByLeastConnections() {}
+
+    public synchronized NettyClient getClientByWeightRoundRobin() {
+        NettyClient client = null;
+        double maxWeight = Double.MIN_VALUE;
+        int clientId = 0;
+        if (clientList.isEmpty()) {
+            return null;
+        }
+        int currSize = clientList.size();
+        for (int retryTime = 0; retryTime < currSize; retryTime++) {
+            currentIndex = (++currentIndex) % currSize;
+            client = clientList.get(currentIndex);
+            if (client != null && client.isActive() && client.getWeight() > maxWeight) {
+                clientId = currentIndex;
+            }
+        }
+        if (client == null || !client.isActive()) {
+            return null;
+        }
+        return clientList.get(clientId);
+    }
+
+    public synchronized NettyClient getClientByWeightRandom() {
+        NettyClient client;
+        double maxWeight = Double.MIN_VALUE;
+        int clientId = 0;
+        if (clientList.isEmpty()) {
+            return null;
+        }
+        int currSize = clientList.size();
+        int maxRetry = 1000;

Review Comment:
   please check the commit [b1c6f5e](https://github.com/apache/inlong/pull/5595/commits/b1c6f5efcb509d645a72f4cc4417fad9c05c7e97)



-- 
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-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] pocozh commented on a diff in pull request #5595: [INLONG-5101][DataProxy] Optimize load balancing for DataProxy

Posted by GitBox <gi...@apache.org>.
pocozh commented on code in PR #5595:
URL: https://github.com/apache/inlong/pull/5595#discussion_r959284814


##########
inlong-common/src/main/java/org/apache/inlong/common/pojo/dataproxy/DataProxyNodeResponse.java:
##########
@@ -52,4 +52,8 @@ public class DataProxyNodeResponse {
      */
     private List<DataProxyNodeInfo> nodeList;
 
+    private String loadBalance;

Review Comment:
   These two configuration parameters should be added in `ProxyClientConfig`, instead of `DataProxyNodeResponse` which is the meta data from `inlong-manager`.  Let user to choose different load balancing strategy while initializing `ProxyClientConfig`. What's more, it is better to use `enum` type to define `loadBalance`.



-- 
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-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] rhizoma-atractylodis commented on a diff in pull request #5595: [INLONG-5101][DataProxy] Optimize load balancing for DataProxy

Posted by GitBox <gi...@apache.org>.
rhizoma-atractylodis commented on code in PR #5595:
URL: https://github.com/apache/inlong/pull/5595#discussion_r957880520


##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/network/ClientMgr.java:
##########
@@ -348,6 +351,90 @@ public synchronized NettyClient getClientByRoundRobin() {
         return client;
     }
 
+    public synchronized NettyClient getClientByRandom() {
+        NettyClient client;
+        if (clientList.isEmpty()) {
+            return null;
+        }
+        int currSize = clientList.size();
+        int maxRetry = this.configure.getMaxRetry();
+        Random random = new Random(System.currentTimeMillis());
+        do {
+            int randomId = random.nextInt();
+            client = clientList.get(randomId % currSize);
+            if (client != null && client.isActive()) {
+                break;
+            }
+            maxRetry--;
+        } while (maxRetry > 0);
+        if (client == null || !client.isActive()) {
+            return null;
+        }
+        return client;
+    }
+
+    public synchronized NettyClient getClientByConsistencyHash(String messageId) {
+        NettyClient client;
+        if (clientList.isEmpty()) {
+            return null;
+        }
+        String hash = ConsistencyHashUtil.hashMurMurHash(messageId);
+        HashRing cluster = HashRing.getInstance();
+        HostInfo info = cluster.getNode(hash);
+        client = this.clientMap.get(info);
+        return client;
+    }
+
+//    public synchronized NettyClient getClientByLeastConnections() {}
+
+    public synchronized NettyClient getClientByWeightRoundRobin() {
+        NettyClient client = null;
+        double maxWeight = Double.MIN_VALUE;
+        int clientId = 0;
+        if (clientList.isEmpty()) {
+            return null;
+        }
+        int currSize = clientList.size();
+        for (int retryTime = 0; retryTime < currSize; retryTime++) {
+            currentIndex = (++currentIndex) % currSize;
+            client = clientList.get(currentIndex);
+            if (client != null && client.isActive() && client.getWeight() > maxWeight) {
+                clientId = currentIndex;
+            }
+        }
+        if (client == null || !client.isActive()) {
+            return null;
+        }
+        return clientList.get(clientId);
+    }
+
+    public synchronized NettyClient getClientByWeightRandom() {
+        NettyClient client;
+        double maxWeight = Double.MIN_VALUE;
+        int clientId = 0;
+        if (clientList.isEmpty()) {
+            return null;
+        }
+        int currSize = clientList.size();
+        int maxRetry = 1000;

Review Comment:
   this was changed yesterday



-- 
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-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] pocozh commented on a diff in pull request #5595: [INLONG-5101][DataProxy] Optimize load balancing for DataProxy

Posted by GitBox <gi...@apache.org>.
pocozh commented on code in PR #5595:
URL: https://github.com/apache/inlong/pull/5595#discussion_r960186159


##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/network/ClientMgr.java:
##########
@@ -911,10 +997,33 @@ private List<HostInfo> getRealHosts(List<HostInfo> hostList, int realSize) {
         return resultHosts;
     }
 
+    public NettyClient getClient(LoadBalance loadBalance, EncodeObject encodeObject) {

Review Comment:
   `loadBalance` is unnecessary, you can directly use member var `loadBalance`.



-- 
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-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] rhizoma-atractylodis commented on a diff in pull request #5595: [INLONG-5101][DataProxy] Optimize load balancing for DataProxy

Posted by GitBox <gi...@apache.org>.
rhizoma-atractylodis commented on code in PR #5595:
URL: https://github.com/apache/inlong/pull/5595#discussion_r959231331


##########
.idea/vcs.xml:
##########
@@ -1,24 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!--
-  ~ 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.
-  -->
 <project version="4">

Review Comment:
   What does the original file look like? I don't know where it's moved, I don't want to change it



-- 
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-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] dockerzhang merged pull request #5595: [INLONG-5101][DataProxy] Optimize load balancing for DataProxy

Posted by GitBox <gi...@apache.org>.
dockerzhang merged PR #5595:
URL: https://github.com/apache/inlong/pull/5595


-- 
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-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] vernedeng commented on a diff in pull request #5595: [INLONG-5101][DataProxy] Optimize load balancing for DataProxy

Posted by GitBox <gi...@apache.org>.
vernedeng commented on code in PR #5595:
URL: https://github.com/apache/inlong/pull/5595#discussion_r949748961


##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/DefaultMessageSender.java:
##########
@@ -211,20 +211,22 @@ public SendResult sendMessage(byte[] body, String groupId, String streamId, long
         } else if (msgtype == 3 || msgtype == 5) {
             if (isCompressEnd) {
                 return sender.syncSendMessage(new EncodeObject(body, "groupId=" + groupId
-                        + "&streamId=" + streamId + "&dt=" + dt + "&cp=snappy",
-                        idGenerator.getNextId(), this.getMsgtype(), true, groupId), msgUUID, timeout, timeUnit);
+                                + "&streamId=" + streamId + "&dt=" + dt + "&cp=snappy",
+                        idGenerator.getNextId(), this.getMsgtype(), true, groupId), msgUUID,
+                        timeout, timeUnit);
             } else {
                 return sender.syncSendMessage(new EncodeObject(body, "groupId=" + groupId
-                        + "&streamId=" + streamId + "&dt=" + dt,
-                        idGenerator.getNextId(), this.getMsgtype(), false, groupId), msgUUID, timeout, timeUnit);
+                                + "&streamId=" + streamId + "&dt=" + dt,

Review Comment:
   ditto



##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/network/ClientMgr.java:
##########
@@ -348,6 +351,37 @@ public synchronized NettyClient getClientByRoundRobin() {
         return client;
     }
 
+    public synchronized NettyClient getClientByRandom() {
+        NettyClient client = null;
+        if (clientList.isEmpty()) {
+            return null;
+        }
+        int currSize = clientList.size();
+        int maxRetry = 1000;

Review Comment:
   magic number.
   please make **_maxRetry_** configurable



##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/network/ClientMgr.java:
##########
@@ -348,6 +351,37 @@ public synchronized NettyClient getClientByRoundRobin() {
         return client;
     }
 
+    public synchronized NettyClient getClientByRandom() {
+        NettyClient client = null;
+        if (clientList.isEmpty()) {
+            return null;
+        }
+        int currSize = clientList.size();
+        int maxRetry = 1000;
+        Random random = new Random(System.currentTimeMillis());
+        do {
+            int randomId = random.nextInt();
+            client = clientList.get(randomId % currSize);
+            maxRetry--;
+        } while (client != null && client.isActive() && maxRetry > 0);

Review Comment:
   why loop **_maxRetry_** times to get client? 
   If you want to make it random enough, just loop **_random.nextInt()_** to get randomId, then get client from clientList once.
   Or you just make a wrong condition? 
   client != null && **!client.isActive()** && maxRetry > 0



##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/utils/HashRing.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.inlong.sdk.dataproxy.utils;
+
+import org.apache.inlong.sdk.dataproxy.config.HostInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.TreeMap;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+public class HashRing {
+    private int virtualNode = 1000;
+    private TreeMap<String, HostInfo> virtualNode2RealNode = new TreeMap<>();
+    private List<HostInfo> nodeList = new ArrayList<>();
+    private static final HashRing instance = new HashRing();
+    private static final Logger LOGGER = LoggerFactory.getLogger(HashRing.class);
+
+    public static HashRing getInstance() {
+        return instance;
+    }
+
+    public TreeMap<String, HostInfo> getVirtualNode2RealNode() {
+        return virtualNode2RealNode;
+    }
+
+    public String node2VirtualNode(HostInfo node, int index) {
+        return  "virtual&&" + index + "&&" + node.toString();
+    }
+
+    public void initHashRing(List<HostInfo> ipList) {
+        this.virtualNode2RealNode = new TreeMap<>();
+        this.nodeList = ipList;
+        for (HostInfo host : this.nodeList) {
+            for (int i = 0; i < this.virtualNode; i++) {
+                String key = node2VirtualNode(host, i);
+                String hash = ConsistencyHashUtil.hashMurMurHash(key);
+                virtualNode2RealNode.put(hash, host);
+            }
+        }
+        LOGGER.info("init hash ring {}", this.virtualNode2RealNode);
+    }
+
+    private void setVirtualNode(int virtualNode) {
+        this.virtualNode = virtualNode;
+    }
+
+    public HostInfo getNode(String key) {
+        String hash = ConsistencyHashUtil.hashMurMurHash(key);
+        SortedMap<String, HostInfo> tailMap = this.virtualNode2RealNode.tailMap(hash);
+        HostInfo node;
+        if (tailMap.isEmpty()) {
+            node = this.virtualNode2RealNode.get(this.virtualNode2RealNode.firstKey());
+        } else {
+            node = this.virtualNode2RealNode.get(tailMap.firstKey());
+        }
+        LOGGER.info("{} located to {}", key, node);
+        return node;
+    }
+
+    public void appendNode(HostInfo host) {

Review Comment:
   private



##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/utils/HashRing.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.inlong.sdk.dataproxy.utils;
+
+import org.apache.inlong.sdk.dataproxy.config.HostInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.TreeMap;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+public class HashRing {
+    private int virtualNode = 1000;
+    private TreeMap<String, HostInfo> virtualNode2RealNode = new TreeMap<>();
+    private List<HostInfo> nodeList = new ArrayList<>();
+    private static final HashRing instance = new HashRing();
+    private static final Logger LOGGER = LoggerFactory.getLogger(HashRing.class);
+
+    public static HashRing getInstance() {
+        return instance;
+    }
+
+    public TreeMap<String, HostInfo> getVirtualNode2RealNode() {
+        return virtualNode2RealNode;
+    }
+
+    public String node2VirtualNode(HostInfo node, int index) {
+        return  "virtual&&" + index + "&&" + node.toString();
+    }
+
+    public void initHashRing(List<HostInfo> ipList) {

Review Comment:
   since the instance has been constructed at the very beginning, why not directly init it at the constructor?
   if multi thread call initHashRing, what will happend?



##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/utils/HashRing.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.inlong.sdk.dataproxy.utils;
+
+import org.apache.inlong.sdk.dataproxy.config.HostInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.TreeMap;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+public class HashRing {
+    private int virtualNode = 1000;
+    private TreeMap<String, HostInfo> virtualNode2RealNode = new TreeMap<>();
+    private List<HostInfo> nodeList = new ArrayList<>();
+    private static final HashRing instance = new HashRing();
+    private static final Logger LOGGER = LoggerFactory.getLogger(HashRing.class);
+
+    public static HashRing getInstance() {
+        return instance;
+    }
+
+    public TreeMap<String, HostInfo> getVirtualNode2RealNode() {
+        return virtualNode2RealNode;
+    }
+
+    public String node2VirtualNode(HostInfo node, int index) {
+        return  "virtual&&" + index + "&&" + node.toString();
+    }
+
+    public void initHashRing(List<HostInfo> ipList) {
+        this.virtualNode2RealNode = new TreeMap<>();
+        this.nodeList = ipList;
+        for (HostInfo host : this.nodeList) {
+            for (int i = 0; i < this.virtualNode; i++) {
+                String key = node2VirtualNode(host, i);
+                String hash = ConsistencyHashUtil.hashMurMurHash(key);
+                virtualNode2RealNode.put(hash, host);
+            }
+        }
+        LOGGER.info("init hash ring {}", this.virtualNode2RealNode);
+    }
+
+    private void setVirtualNode(int virtualNode) {

Review Comment:
   setter should not be private



##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/DefaultMessageSender.java:
##########
@@ -273,20 +277,24 @@ public SendResult sendMessage(List<byte[]> bodyList, String groupId, String stre
             return sender.syncSendMessage(encodeObject, msgUUID, timeout, timeUnit);
         } else if (msgtype == 3 || msgtype == 5) {
             if (isCompress) {
-                return sender.syncSendMessage(new EncodeObject(bodyList, "groupId=" + groupId + "&streamId=" + streamId
+                return sender.syncSendMessage(new EncodeObject(bodyList, "groupId=" + groupId
+                                + "&streamId=" + streamId

Review Comment:
   ditto



##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/utils/HashRing.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.inlong.sdk.dataproxy.utils;
+
+import org.apache.inlong.sdk.dataproxy.config.HostInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.TreeMap;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+public class HashRing {
+    private int virtualNode = 1000;

Review Comment:
   magic number. 
   and the it seems like virtualNodeNum instead of virtualNode



##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/utils/ConsistencyHashUtil.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.sdk.dataproxy.utils;
+
+import com.google.common.hash.HashFunction;
+import com.google.common.hash.Hashing;
+
+import java.nio.charset.StandardCharsets;
+
+public class ConsistencyHashUtil {
+    @Deprecated

Review Comment:
   since it's deprecated and never used, please remove it



##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/DefaultMessageSender.java:
##########
@@ -211,20 +211,22 @@ public SendResult sendMessage(byte[] body, String groupId, String streamId, long
         } else if (msgtype == 3 || msgtype == 5) {
             if (isCompressEnd) {
                 return sender.syncSendMessage(new EncodeObject(body, "groupId=" + groupId
-                        + "&streamId=" + streamId + "&dt=" + dt + "&cp=snappy",
-                        idGenerator.getNextId(), this.getMsgtype(), true, groupId), msgUUID, timeout, timeUnit);
+                                + "&streamId=" + streamId + "&dt=" + dt + "&cp=snappy",

Review Comment:
   Unnecessary code formatting. 
   Personally, I think it's worse than before.



##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/utils/HashRing.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.inlong.sdk.dataproxy.utils;
+
+import org.apache.inlong.sdk.dataproxy.config.HostInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.TreeMap;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+public class HashRing {
+    private int virtualNode = 1000;
+    private TreeMap<String, HostInfo> virtualNode2RealNode = new TreeMap<>();
+    private List<HostInfo> nodeList = new ArrayList<>();
+    private static final HashRing instance = new HashRing();
+    private static final Logger LOGGER = LoggerFactory.getLogger(HashRing.class);
+
+    public static HashRing getInstance() {
+        return instance;
+    }
+
+    public TreeMap<String, HostInfo> getVirtualNode2RealNode() {
+        return virtualNode2RealNode;
+    }
+
+    public String node2VirtualNode(HostInfo node, int index) {
+        return  "virtual&&" + index + "&&" + node.toString();
+    }
+
+    public void initHashRing(List<HostInfo> ipList) {
+        this.virtualNode2RealNode = new TreeMap<>();
+        this.nodeList = ipList;
+        for (HostInfo host : this.nodeList) {
+            for (int i = 0; i < this.virtualNode; i++) {
+                String key = node2VirtualNode(host, i);
+                String hash = ConsistencyHashUtil.hashMurMurHash(key);
+                virtualNode2RealNode.put(hash, host);
+            }
+        }
+        LOGGER.info("init hash ring {}", this.virtualNode2RealNode);
+    }
+
+    private void setVirtualNode(int virtualNode) {
+        this.virtualNode = virtualNode;
+    }
+
+    public HostInfo getNode(String key) {

Review Comment:
   seems like private function



##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/utils/HashRing.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.inlong.sdk.dataproxy.utils;
+
+import org.apache.inlong.sdk.dataproxy.config.HostInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.TreeMap;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+public class HashRing {

Review Comment:
   Do not make **_utils_** to singleton.
   utils are usually static.
   please move HashRing to other directory



##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/utils/HashRing.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.inlong.sdk.dataproxy.utils;
+
+import org.apache.inlong.sdk.dataproxy.config.HostInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.TreeMap;
+import java.util.SortedMap;
+import java.util.stream.Collectors;
+
+public class HashRing {
+    private int virtualNode = 1000;
+    private TreeMap<String, HostInfo> virtualNode2RealNode = new TreeMap<>();
+    private List<HostInfo> nodeList = new ArrayList<>();
+    private static final HashRing instance = new HashRing();
+    private static final Logger LOGGER = LoggerFactory.getLogger(HashRing.class);
+
+    public static HashRing getInstance() {
+        return instance;
+    }
+
+    public TreeMap<String, HostInfo> getVirtualNode2RealNode() {
+        return virtualNode2RealNode;
+    }
+
+    public String node2VirtualNode(HostInfo node, int index) {
+        return  "virtual&&" + index + "&&" + node.toString();
+    }
+
+    public void initHashRing(List<HostInfo> ipList) {
+        this.virtualNode2RealNode = new TreeMap<>();
+        this.nodeList = ipList;
+        for (HostInfo host : this.nodeList) {
+            for (int i = 0; i < this.virtualNode; i++) {
+                String key = node2VirtualNode(host, i);
+                String hash = ConsistencyHashUtil.hashMurMurHash(key);
+                virtualNode2RealNode.put(hash, host);
+            }
+        }
+        LOGGER.info("init hash ring {}", this.virtualNode2RealNode);
+    }
+
+    private void setVirtualNode(int virtualNode) {
+        this.virtualNode = virtualNode;
+    }
+
+    public HostInfo getNode(String key) {
+        String hash = ConsistencyHashUtil.hashMurMurHash(key);
+        SortedMap<String, HostInfo> tailMap = this.virtualNode2RealNode.tailMap(hash);
+        HostInfo node;
+        if (tailMap.isEmpty()) {
+            node = this.virtualNode2RealNode.get(this.virtualNode2RealNode.firstKey());
+        } else {
+            node = this.virtualNode2RealNode.get(tailMap.firstKey());
+        }
+        LOGGER.info("{} located to {}", key, node);
+        return node;
+    }
+
+    public void appendNode(HostInfo host) {
+        this.nodeList.add(host);
+        for (int i = 0; i < this.virtualNode; i++) {
+            String key = node2VirtualNode(host, i);
+            String hash = ConsistencyHashUtil.hashMurMurHash(key);
+            virtualNode2RealNode.put(hash, host);
+            LOGGER.info("append node {}", host);
+        }
+    }
+
+    public void extendNode(List<HostInfo> nodes) {

Review Comment:
   private



-- 
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-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] pocozh commented on a diff in pull request #5595: [INLONG-5101][DataProxy] Optimize load balancing for DataProxy

Posted by GitBox <gi...@apache.org>.
pocozh commented on code in PR #5595:
URL: https://github.com/apache/inlong/pull/5595#discussion_r959258131


##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/DefaultMessageSender.java:
##########
@@ -194,7 +194,7 @@ public SendResult sendMessage(byte[] body, String attributes, String msgUUID,
     }
 
     public SendResult sendMessage(byte[] body, String groupId, String streamId, long dt, String msgUUID,
-            long timeout, TimeUnit timeUnit) {
+                                  long timeout, TimeUnit timeUnit) {

Review Comment:
   Please don't change code style. Refer to https://github.com/apache/inlong/discussions/3082.



-- 
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-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] dockerzhang commented on a diff in pull request #5595: [INLONG-5101][DataProxy] Optimize load balancing for DataProxy

Posted by GitBox <gi...@apache.org>.
dockerzhang commented on code in PR #5595:
URL: https://github.com/apache/inlong/pull/5595#discussion_r959204158


##########
.idea/vcs.xml:
##########
@@ -1,24 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!--
-  ~ 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.
-  -->
 <project version="4">

Review Comment:
   why change this file?



-- 
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-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] vernedeng commented on pull request #5595: [INLONG-5101][DataProxy] Optimize load balancing for DataProxy

Posted by GitBox <gi...@apache.org>.
vernedeng commented on PR #5595:
URL: https://github.com/apache/inlong/pull/5595#issuecomment-1220205495

   RoundRobin is the best load balance algorithm in the case of high load and irregular data.
   While Consistent Hash is usually applied in the case of low load or regular data to make sure that all familiar data will be sent to the same server


-- 
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-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] vernedeng commented on a diff in pull request #5595: [INLONG-5101][DataProxy] Optimize load balancing for DataProxy

Posted by GitBox <gi...@apache.org>.
vernedeng commented on code in PR #5595:
URL: https://github.com/apache/inlong/pull/5595#discussion_r956852383


##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/config/ProxyConfigManager.java:
##########
@@ -101,6 +102,8 @@ public class ProxyConfigManager extends Thread {
     private boolean bShutDown = false;
     private long doworkTime = 0;
     private EncryptConfigEntry userEncryConfigEntry;
+    private final HashRing hashRing = HashRing.getInstance();
+    private String loadBalance = ConfigConstants.DEFAULT_LOAD_BALANCE;

Review Comment:
   plz make it configurable



##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/config/ProxyConfigManager.java:
##########
@@ -621,6 +630,14 @@ private ProxyConfigEntry getProxyConfigEntry(DataProxyNodeResponse proxyCluster)
         if (ObjectUtils.isNotEmpty(proxyCluster.getIsSwitch())) {
             isSwitch = proxyCluster.getIsSwitch();
         }
+        int virtualNode = ConfigConstants.DEFAULT_VIRTUAL_NODE;

Review Comment:
   plz make it configurable



##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/network/ClientMgr.java:
##########
@@ -348,6 +351,90 @@ public synchronized NettyClient getClientByRoundRobin() {
         return client;
     }
 
+    public synchronized NettyClient getClientByRandom() {
+        NettyClient client;
+        if (clientList.isEmpty()) {
+            return null;
+        }
+        int currSize = clientList.size();
+        int maxRetry = 1000;

Review Comment:
   plz make it configurable



##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/config/ProxyConfigManager.java:
##########
@@ -116,6 +119,10 @@ public void setGroupId(String groupId) {
         this.groupId = groupId;
     }
 
+    public HashRing getHashRing() {

Review Comment:
    why use methond **_getHashRing_** to acquire a singleton instance?
   



-- 
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-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] baomingyu commented on a diff in pull request #5595: [INLONG-5101][DataProxy] Optimize load balancing for DataProxy

Posted by GitBox <gi...@apache.org>.
baomingyu commented on code in PR #5595:
URL: https://github.com/apache/inlong/pull/5595#discussion_r956868632


##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/network/Sender.java:
##########
@@ -228,12 +229,35 @@ private SendResult syncSendInternalMessage(NettyClient client,
      * @param timeUnit
      * @return
      */
+//    @Deprecated
     public SendResult syncSendMessage(EncodeObject encodeObject, String msgUUID,
             long timeout, TimeUnit timeUnit) {
-        metricWorker.recordNumByKey(encodeObject.getMessageId(),
-                encodeObject.getGroupId(), encodeObject.getStreamId(),
+        return syncSendMessage(encodeObject, msgUUID, timeout,
+                timeUnit, ConfigConstants.DEFAULT_LOAD_BALANCE);
+    }
+
+    public SendResult syncSendMessage(EncodeObject encodeObject, String msgUUID, long timeout,
+                                      TimeUnit timeUnit, String loadBalance) {
+        metricWorker.recordNumByKey(encodeObject.getMessageId(), encodeObject.getGroupId(), encodeObject.getStreamId(),
                 Utils.getLocalIp(), encodeObject.getDt(), encodeObject.getPackageTime(), encodeObject.getRealCnt());
-        NettyClient client = clientMgr.getClientByRoundRobin();
+        NettyClient client = null;
+        switch (loadBalance) {
+            case "random":

Review Comment:
   plz make "random"、“consistency hash” ... as constants in constants class



-- 
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-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] pocozh commented on a diff in pull request #5595: [INLONG-5101][DataProxy] Optimize load balancing for DataProxy

Posted by GitBox <gi...@apache.org>.
pocozh commented on code in PR #5595:
URL: https://github.com/apache/inlong/pull/5595#discussion_r960167501


##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/network/Sender.java:
##########
@@ -726,4 +736,26 @@ public boolean isIdleClient(NettyClient client) {
         return true;
     }
 
+    private NettyClient getClient(LoadBalance loadBalance, EncodeObject encodeObject) {

Review Comment:
   Is it better to remove this into `ClientMgr`? Then,  methods such as `asyncSendMessage` can directly use previous signature, and no need to add additional parameter.



-- 
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-unsubscribe@inlong.apache.org

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