Skip to content
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

Merged
merged 7 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/brpc/load_balancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Copy link
Contributor

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,表示开启默认权重值。
这样默认权重的大小可以由用户设定

Copy link
Contributor Author

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则代表用户开启了策略降级,并且同时也设定了默认的权重大小对吧。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的。另外,看提交的代码,这里没有降级策略吧,就是要提供一个默认的权重值。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有的,因为没有设置权重值的机器是不会加到机器列表当中的,也就无法提供服务,这样提供一个默认值,对与那些没有配置权重的机器也会得到一个默认的权值,从而也会被添加到服务机器列表中,wr/wrr的策略也就相应降级到了r/rr策略。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

了解,存在这种情况:新加入的节点没有设置正确的权重值,但已有节点是有权重值的,综合提供一个默认权重值gflag更合理些。

BRPC_VALIDATE_GFLAG(show_lb_in_vars, PassValidate);

// For assigning unique names for lb.
Expand Down
1 change: 1 addition & 0 deletions src/brpc/load_balancer.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class LoadBalancer : public NonConstDescribable, public Destroyable {
};

DECLARE_bool(show_lb_in_vars);
DECLARE_bool(wlb_policy_degradation);

// A intrusively shareable load balancer created from name.
class SharedLoadBalancer : public SharedObject, public NonConstDescribable {
Expand Down
27 changes: 16 additions & 11 deletions src/brpc/policy/weighted_randomized_load_balancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,23 @@ bool WeightedRandomizedLoadBalancer::Add(Servers& bg, const ServerId& id) {
bg.server_list.reserve(128);
}
uint32_t weight = 0;
if (butil::StringToUint(id.tag, &weight) &&
weight > 0) {
bool insert_server =
bg.server_map.emplace(id.id, bg.server_list.size()).second;
if (insert_server) {
uint64_t current_weight_sum = bg.weight_sum + weight;
bg.server_list.emplace_back(id.id, weight, current_weight_sum);
bg.weight_sum = current_weight_sum;
return true;
if (!butil::StringToUint(id.tag, &weight) || weight <= 0) {
if (FLAGS_wlb_policy_degradation) {
LOG(WARNING) << "Invalid weight is set: " << id.tag
<< ". Now, 'weight' has been set to 1 by default.";
Copy link
Contributor

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 吧

weight = 1;
} else {
LOG(ERROR) << "Invalid weight is set: " << id.tag;
return false;
}
} else {
LOG(ERROR) << "Invalid weight is set: " << id.tag;
}
bool insert_server =
bg.server_map.emplace(id.id, bg.server_list.size()).second;
if (insert_server) {
uint64_t current_weight_sum = bg.weight_sum + weight;
bg.server_list.emplace_back(id.id, weight, current_weight_sum);
bg.weight_sum = current_weight_sum;
return true;
}
return false;
}
Expand Down
25 changes: 15 additions & 10 deletions src/brpc/policy/weighted_round_robin_load_balancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,22 @@ bool WeightedRoundRobinLoadBalancer::Add(Servers& bg, const ServerId& id) {
bg.server_list.reserve(128);
}
uint32_t weight = 0;
if (butil::StringToUint(id.tag, &weight) &&
weight > 0) {
bool insert_server =
bg.server_map.emplace(id.id, bg.server_list.size()).second;
if (insert_server) {
bg.server_list.emplace_back(id.id, weight);
bg.weight_sum += weight;
return true;
if (!butil::StringToUint(id.tag, &weight) || weight <= 0) {
if (FLAGS_wlb_policy_degradation) {
LOG(WARNING) << "Invalid weight is set: " << id.tag
<< ". Now, 'weight' has been set to 1 by default.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

weight = 1;
} else {
LOG(ERROR) << "Invalid weight is set: " << id.tag;
return false;
}
} else {
LOG(ERROR) << "Invalid weight is set: " << id.tag;
}
bool insert_server =
bg.server_map.emplace(id.id, bg.server_list.size()).second;
if (insert_server) {
bg.server_list.emplace_back(id.id, weight);
bg.weight_sum += weight;
return true;
}
return false;
}
Expand Down