You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2018/08/25 02:06:05 UTC

[GitHub] liubao68 commented on a change in pull request #883: [SBC-870]refactor to using custom RuleExt, not using Robin IRule.

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

 ##########
 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:
   权重算法就是这样的。对我们的场景,这个计算量很少,以及过滤掉不可用实例了。 即使200实例,这个算法复杂度也很低。

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services