-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support wr/wrr policy degradation #1571
Conversation
src/brpc/load_balancer.cpp
Outdated
@@ -24,6 +24,7 @@ | |||
namespace brpc { | |||
|
|||
DEFINE_bool(show_lb_in_vars, false, "Describe LoadBalancers in vars"); | |||
DEFINE_bool(wlb_policy_degradation, false, "Weighted LoadBalancers policy degradation"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default_weight_of_wlb,表示默认权重值,默认0,如果大于0,表示开启默认权重值。
这样默认权重的大小可以由用户设定
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default_weight_of_wlb,表示默认权重值,默认0,如果大于0,表示开启默认权重值。 这样默认权重的大小可以由用户设定
意思是把wlb_policy_degradation替换为default_weight_of_wlb,默认0,同时代表不开启策略降级,若大于0则代表用户开启了策略降级,并且同时也设定了默认的权重大小对吧。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是的。另外,看提交的代码,这里没有降级策略吧,就是要提供一个默认的权重值。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有的,因为没有设置权重值的机器是不会加到机器列表当中的,也就无法提供服务,这样提供一个默认值,对与那些没有配置权重的机器也会得到一个默认的权值,从而也会被添加到服务机器列表中,wr/wrr的策略也就相应降级到了r/rr策略。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
了解,存在这种情况:新加入的节点没有设置正确的权重值,但已有节点是有权重值的,综合提供一个默认权重值gflag更合理些。
src/brpc/load_balancer.cpp
Outdated
@@ -24,6 +24,7 @@ | |||
namespace brpc { | |||
|
|||
DEFINE_bool(show_lb_in_vars, false, "Describe LoadBalancers in vars"); | |||
DEFINE_int32(default_weight_of_wlb, 0, "Default weight of Weighted LoadBalancer"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Huixxi 这里需要补充下评论或细化下描述,否则光看选项名称,并不太清楚作用是什么。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jamesge 好的,我重新修改下描述部分再重新提交PR
if (!butil::StringToUint(id.tag, &weight) || weight <= 0) { | ||
if (FLAGS_default_weight_of_wlb > 0) { | ||
LOG(WARNING) << "Invalid weight is set: " << id.tag | ||
<< ". Now, 'weight' has been set to 1 by default."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里输出的 1 应该改成 FLAGS_default_weight_of_wlb 吧
if (!butil::StringToUint(id.tag, &weight) || weight <= 0) { | ||
if (FLAGS_default_weight_of_wlb > 0) { | ||
LOG(WARNING) << "Invalid weight is set: " << id.tag | ||
<< ". Now, 'weight' has been set to 1 by default."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
当前的wr/wrr负载均衡策略模式下,未配置权重的下游机器无法被添加到本次服务的机器列表当中,当用户忘记配置下游机器的权重时可能会因为机器列表为空无法选择一台下游机器而导致程序运行出错,提供策略降级机制可避免这种情况发生。
解决方案:通过给工作在这两种负载均衡机制下的未配置权重值的下游机器设置一个默认权重值1,从而这两种策略便自动降级至各自的非加权版本r/rr,并通过增加一个gflags:wlb_policy_degradation(默认关闭,false)来控制,当打开这个开关的时候(true)执行上述逻辑,默认条件下,则维持原有逻辑,即过滤未配置权重的下游机器。