-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bee8445
wr/wrr policy degradation
Huixxi b26e879
Merge branch 'apache:master' into wlb_policy_degradation
Huixxi e7dc30c
Merge branch 'apache:master' into wlb_policy_degradation
Huixxi f710aff
Merge branch 'wlb_policy_degradation' of github.com:Huixxi/incubator-…
Huixxi 9a4066e
Update load_balancer.cpp
Huixxi 75e66f1
Update weighted_randomized_load_balancer.cpp
Huixxi 65921af
Update weighted_round_robin_load_balancer.cpp
Huixxi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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."; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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."; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
意思是把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更合理些。