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

The usage of leastActiveLoadBalance in dubbo-go

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

Share

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

This article mainly introduces "the usage of leastActiveLoadBalance in dubbo-go". In daily operation, I believe many people have doubts about the usage of leastActiveLoadBalance in dubbo-go. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about the usage of leastActiveLoadBalance in dubbo-go! Next, please follow the editor to study!

Order

This paper mainly studies the leastActiveLoadBalance of dubbo-go.

LeastActiveLoadBalance

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

Const (/ / LeastActive... LeastActive = "leastactive") func init () {extension.SetLoadbalance (LeastActive, NewLeastActiveLoadBalance)} type leastActiveLoadBalance struct {} / / NewLeastActiveLoadBalance... func NewLeastActiveLoadBalance () cluster.LoadBalance {return & leastActiveLoadBalance {}}

The NewLeastActiveLoadBalance method of leastActiveLoadBalance to create leastActiveLoadBalance

Select

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

Func (lb * leastActiveLoadBalance) Select (invokers [] protocol.Invoker) Invocation protocol.Invocation) protocol.Invoker {count: = len (invokers) if count = = 0 {return nil} if count = = 1 {return invokers [0]} var (leastActive int32 =-1 / / The least active value of all invokers totalWeight int64 / / The number of invokers having the same least active value (LEAST_ACTIVE) firstWeight int64 / / Initial value Used for comparison leastCount int / / The number of invokers having the same least active value (LEAST_ACTIVE) leastIndexes = make ([] int, count) / / The index of invokers having the same least active value (LEAST_ACTIVE) sameWeight = true / / Every invoker has the same weight value?) For I: = 0; I

< count; i++ { invoker := invokers[i] // Active number active := protocol.GetMethodStatus(invoker.GetUrl(), invocation.MethodName()).GetActive() // current weight (maybe in warmUp) weight := GetWeight(invoker, invocation) // There are smaller active services if leastActive == -1 || active < leastActive { leastActive = active leastIndexes[0] = i leastCount = 1 // next available leastIndex offset totalWeight = weight firstWeight = weight sameWeight = true } else if active == leastActive { leastIndexes[leastCount] = i totalWeight += weight leastCount++ if sameWeight && (i >

0) & & weight! = firstWeight {sameWeight = false} if leastCount = 1 {return invokers [0]} if! sameWeight & & totalWeight > 0 {offsetWeight: = rand.Int63n (totalWeight) + 1 for I: = 0; I

< leastCount; i++ { leastIndex := leastIndexes[i] offsetWeight -= GetWeight(invokers[i], invocation) if offsetWeight 0 { //get service register time an do warm up time now := time.Now().Unix() timestamp := url.GetParamInt(constant.REMOTE_TIMESTAMP_KEY, now) if uptime := now - timestamp; uptime >

0 {warmup: = url.GetParamInt (constant.WARMUP_KEY, constant.DEFAULT_WARMUP) if uptime < warmup {if ww: = float64 (uptime) / float64 (warmup) / float64 (weight) Ww < 1 {weight = 1} else if int64 (ww)

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