Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

The usage of leastActiveLoadBalance in dubbo-go

Shulou Source: shulou.com Published: 2022-06-02 07:21:25 10月03日 Update

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)

Tags: Methods learning information more help practical next summary articles theories knowledge articles websites materials follow questions easy to use practice research solutions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple MySQL Shulou Tech Info NVidia OPPO Reno