Skip to content
Snippets Groups Projects
Commit a97fa47c authored by zonghaishang's avatar zonghaishang
Browse files

format code

parent 83409cab
No related branches found
No related tags found
No related merge requests found
......@@ -13,20 +13,22 @@
// @author yiji@apache.org
package loadbalance
import (
"math/rand"
)
import (
"github.com/dubbo/go-for-apache-dubbo/cluster"
"github.com/dubbo/go-for-apache-dubbo/common/extension"
"github.com/dubbo/go-for-apache-dubbo/filter"
"github.com/dubbo/go-for-apache-dubbo/protocol"
"math/rand"
)
const (
leastActive = "leastactive"
LeastActive = "leastactive"
)
func init() {
extension.SetLoadbalance(leastActive, NewLeastActiveLoadBalance)
extension.SetLoadbalance(LeastActive, NewLeastActiveLoadBalance)
}
type leastActiveLoadBalance struct {
......@@ -37,9 +39,8 @@ func NewLeastActiveLoadBalance() cluster.LoadBalance {
}
func (lb *leastActiveLoadBalance) Select(invokers []protocol.Invoker, invocation protocol.Invocation) protocol.Invoker {
count := len(invokers)
if invokers == nil || count == 0 {
if count == 0 {
return nil
}
if count == 1 {
......@@ -48,17 +49,17 @@ func (lb *leastActiveLoadBalance) Select(invokers []protocol.Invoker, invocation
var (
leastActive int32 = -1 // The least active value of all invokers
totalWeight int64 = 0 // The number of invokers having the same least active value (leastActive)
totalWeight int64 = 0 // The number of invokers having the same least active value (LEAST_ACTIVE)
firstWeight int64 = 0 // Initial value, used for comparision
leastIndexes = make([]int, count) // The index of invokers having the same least active value (leastActive)
leastCount = 0 // The number of invokers having the same least active value (leastActive)
leastIndexes = make([]int, count) // The index of invokers having the same least active value (LEAST_ACTIVE)
leastCount = 0 // The number 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 := filter.GetStatus(invoker.GetUrl(), invocation.MethodName()).GetActive()
active := protocol.GetStatus(invoker.GetUrl(), invocation.MethodName()).GetActive()
// current weight (maybe in warmUp)
weight := GetWeight(invoker, invocation)
// There are smaller active services
......
......@@ -35,13 +35,13 @@ type ActiveFilter struct {
func (ef *ActiveFilter) Invoke(invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
logger.Infof("invoking active filter. %v,%v", invocation.MethodName(), len(invocation.Arguments()))
filter.BeginCount(invoker.GetUrl(), invocation.MethodName())
protocol.BeginCount(invoker.GetUrl(), invocation.MethodName())
return invoker.Invoke(invocation)
}
func (ef *ActiveFilter) OnResponse(result protocol.Result, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
filter.EndCount(invoker.GetUrl(), invocation.MethodName())
protocol.EndCount(invoker.GetUrl(), invocation.MethodName())
return result
}
......
......@@ -11,16 +11,19 @@
// limitations under the License.
// @author yiji@apache.org
package filter
package protocol
import (
"github.com/dubbo/go-for-apache-dubbo/common"
"sync"
"sync/atomic"
)
import (
"github.com/dubbo/go-for-apache-dubbo/common"
)
var (
methodStatistics = sync.Map{} // url -> { methodName : RpcStatus}
methodStatistics sync.Map // url -> { methodName : RpcStatus}
)
type RpcStatus struct {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment