Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the function of roundRobinLoadBalance in dubbo-go

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail what the role of roundRobinLoadBalance in dubbo-go is, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

RoundRobinLoadBalance

Dubbo-go-v1.4.2/cluster/loadbalance/round_robin.go

Const (/ / RoundRobin... RoundRobin = "roundrobin" / / COMPLETE. COMPLETE = 0 / / UPDATING... UPDATING = 1) var (methodWeightMap sync.Map / / [string] invokers state = int32 (COMPLETE) / / update lock acquired? RecyclePeriod = 60 * time.Second.Nanoseconds () func init () {extension.SetLoadbalance (RoundRobin, NewRoundRobinLoadBalance)} type roundRobinLoadBalance struct {} / / NewRoundRobinLoadBalance... func NewRoundRobinLoadBalance () cluster.LoadBalance {return & roundRobinLoadBalance {}}

The NewRoundRobinLoadBalance method of roundRobinLoadBalance creates the roundRobinLoadBalance

Select

Dubbo-go-v1.4.2/cluster/loadbalance/round_robin.go

Func (lb * roundRobinLoadBalance) Select (invokers [] protocol.Invoker, invocation protocol.Invocation) protocol.Invoker {count: = len (invokers) if count = 0 {return nil} if count = = 1 {return invokers [0]} key: = invokers [0] .GetUrl (). Path + "." + invocation.MethodName () cache, _: = methodWeightMap.LoadOrStore (key) & cachedInvokers {}) cachedInvokers: = cache. (* cachedInvokers) var (clean = false totalWeight = int64 (0) maxCurrentWeight = int64 (math.MinInt64) now = time.Now () selectedInvoker protocol.Invoker SelectedWeightRobin * weightedRoundRobin) for _ Invoker: = range invokers {var weight = GetWeight (invoker, invocation) if weight

< 0 { weight = 0 } identifier := invoker.GetUrl().Key() loaded, found := cachedInvokers.LoadOrStore(identifier, &weightedRoundRobin{weight: weight}) weightRobin := loaded.(*weightedRoundRobin) if !found { clean = true } if weightRobin.Weight() != weight { weightRobin.setWeight(weight) } currentWeight := weightRobin.increaseCurrent() weightRobin.lastUpdate = &now if currentWeight >

MaxCurrentWeight {maxCurrentWeight = currentWeight selectedInvoker = invoker selectedWeightRobin = weightRobin} totalWeight + = weight} cleanIfRequired (clean, cachedInvokers & now) if selectedWeightRobin! = nil {selectedWeightRobin.Current (totalWeight) return selectedInvoker} / / should never happen return invokers [0]}

The Select method traverses invokers, uses weightRobin.increaseCurrent () as currentWeight, updates maxCurrentWeight if currentWeight is greater than maxCurrentWeight, sets selectedInvoker as current invoker, and returns selectedInvoker for execution selectedWeightRobin.Current (totalWeight) if selectedWeightRobin is not nil after setting selectedWeightRobin as current weightRobin;

Summary

RoundRobinLoadBalance's NewRoundRobinLoadBalance method creates roundRobinLoadBalance; and its Select method traverses invokers, using weightRobin.increaseCurrent () as currentWeight, updating maxCurrentWeight if currentWeight is greater than maxCurrentWeight, setting selectedInvoker as current invoker and selectedWeightRobin as current weightRobin

About what the role of roundRobinLoadBalance in dubbo-go is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report