justxuewei commented on code in PR #2067:
URL: https://github.com/apache/dubbo-go/pull/2067#discussion_r991324624
##########
cluster/loadbalance/p2c/loadbalance.go:
##########
@@ -89,49 +85,63 @@ func (l *p2cLoadBalance) Select(invokers
[]protocol.Invoker, invocation protocol
i, invokers[i], j, invokers[j])
methodName := invocation.ActualMethodName()
- // remainingIIface, remainingJIface means remaining capacity of node i
and node j.
- // If one of the metrics is empty, invoke the invocation to that node
directly.
- remainingIIface, err := m.GetMethodMetrics(invokers[i].GetURL(),
methodName, metrics.HillClimbing)
- if err != nil {
- if errors.Is(err, metrics.ErrMetricsNotFound) {
- logger.Debugf("[P2C select] The invoker[%d] was
selected, because it hasn't been selected before.", i)
- return invokers[i]
- }
- logger.Warnf("get method metrics err: %v", err)
- return nil
- }
-
- // TODO(justxuewei): It should have a strategy to drop some metrics
after a period of time.
- remainingJIface, err := m.GetMethodMetrics(invokers[j].GetURL(),
methodName, metrics.HillClimbing)
- if err != nil {
- if errors.Is(err, metrics.ErrMetricsNotFound) {
- logger.Debugf("[P2C select] The invoker[%d] was
selected, because it hasn't been selected before.", j)
- return invokers[j]
- }
- logger.Warnf("get method metrics err: %v", err)
- return nil
- }
-
- // Convert interface to int, if the type is unexpected, panic
immediately
- remainingI, ok := remainingIIface.(uint64)
- if !ok {
- panic(fmt.Sprintf("[P2C select] the type of %s expects to be
uint64, but gets %T",
- metrics.HillClimbing, remainingIIface))
- }
-
- remainingJ, ok := remainingJIface.(uint64)
- if !ok {
- panic(fmt.Sprintf("the type of %s expects to be uint64, but
gets %T", metrics.HillClimbing, remainingJIface))
- }
- logger.Debugf("[P2C select] The invoker[%d] remaining is %d, and the
invoker[%d] is %d.", i, remainingI, j, remainingJ)
+ weightI, weightJ := Weight(invokers[i].GetURL(), invokers[j].GetURL(),
methodName)
// For the remaining capacity, the bigger, the better.
- if remainingI > remainingJ {
+ if weightI > weightJ {
logger.Debugf("[P2C select] The invoker[%d] was selected.", i)
return invokers[i]
}
logger.Debugf("[P2C select] The invoker[%d] was selected.", j)
return invokers[j]
}
+
+//Weight w_i = s_i + ε*t_i
+func Weight(url1, url2 *common.URL, methodName string) (weight1, weight2
float64) {
+
+ s1 := successRateWeight(url1, methodName)
+ s2 := successRateWeight(url2, methodName)
+
+ rtt1Iface, _ := metrics.EMAMetrics.GetMethodMetrics(url1, methodName,
metrics.RTT)
+ rtt2Iface, _ := metrics.EMAMetrics.GetMethodMetrics(url2, methodName,
metrics.RTT)
+ rtt1 := metrics.ToFloat64(rtt1Iface)
+ rtt2 := metrics.ToFloat64(rtt2Iface)
+ logger.Debugf("[P2C Weight Metrics] [invoker1] %s's s score: %f, rtt:
%f; [invoker2] %s's s score: %f, rtt: %f.",
+ url1.Ip, s1, rtt1, url2.Ip, s2, rtt2)
+ avgRtt := (rtt1 + rtt2) / 2
+ t1 := normalize((1 + avgRtt) / (1 + rtt1))
+ t2 := normalize((1 + avgRtt) / (1 + rtt2))
+
+ avgS := (s1 + s2) / 2
+ avgT := (t1 + t2) / 2
Review Comment:
I am thinking that `avgS` and `avgT` are no needs to to divide by 2.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]