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-unsubscr...@inlong.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org