jeho0815 commented on a change in pull request #883: [SBC-870]refactor to using custom RuleExt, not using Robin IRule. URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/883#discussion_r212784348
########## File path: handlers/handler-loadbalance/src/main/java/org/apache/servicecomb/loadbalance/WeightedResponseTimeRuleExt.java ########## @@ -0,0 +1,65 @@ +/* + * 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.servicecomb.loadbalance; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.util.concurrent.atomic.AtomicInteger; + +import org.apache.servicecomb.core.Invocation; + +/** + * Rule based on response time. + */ +public class WeightedResponseTimeRuleExt extends RoundRobinRuleExt { + // 10ms + private static final int MIN_GAP = 10; + + private Random random = new Random(); + + @Override + public ServiceCombServer choose(List<ServiceCombServer> servers, Invocation invocation) { + List<AtomicInteger> stats = new ArrayList<>(servers.size()); + int totalWeights = 0; + boolean needRandom = false; + for (ServiceCombServer server : servers) { Review comment: 每次都进行重新计算,如果server很多的时候,会影响性能吧 ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
