AhahaGe opened a new issue #2957:
URL: https://github.com/apache/incubator-shenyu/issues/2957


   ### Question
   
   First is in HashLoadBalancer, see below code, can ConcurrentSkipListMap be 
replaced by SortedMap as we do not need concurrency logic.
   `public Upstream doSelect(final List<Upstream> upstreamList, final String 
ip) {
           final ConcurrentSkipListMap<Long, Upstream> treeMap = new 
ConcurrentSkipListMap<>();
           upstreamList.forEach(upstream -> IntStream.range(0, 
VIRTUAL_NODE_NUM).forEach(i -> {
               long addressHash = hash("SHENYU-" + upstream.getUrl() + "-HASH-" 
+ i);
               treeMap.put(addressHash, upstream);
           }));
           long hash = hash(ip);
           SortedMap<Long, Upstream> lastRing = treeMap.tailMap(hash);
           if (!lastRing.isEmpty()) {
               return lastRing.get(lastRing.firstKey());
           }
           return treeMap.firstEntry().getValue();
       }`
   
   Second, in AbstractLoadBalancer class, see below code will method 
calculateWarmupWeight always return 1, as uptime always slower than warmup, and 
weight is always int and > 1;
   `private int getWeight(final long timestamp, final int warmup, final int 
weight) {
           if (weight > 0 && timestamp > 0) {
               int uptime = (int) (System.currentTimeMillis() - timestamp);
               if (uptime > 0 && uptime < warmup) {
                   return calculateWarmupWeight(uptime, warmup, weight);
               }
           }
           return weight;
       }
   
       private int calculateWarmupWeight(final int uptime, final int warmup, 
final int weight) {
           int ww = (int) ((float) uptime / ((float) warmup / (float) weight));
           return ww < 1 ? 1 : (Math.min(ww, weight));
       }`


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to