-
Notifications
You must be signed in to change notification settings - Fork 17
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
WIP: wlc moved to from dataplane to controlplane #211
Open
levon-a-akopian
wants to merge
1
commit into
main
Choose a base branch
from
move-wlc-to-controlplane
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -886,6 +886,12 @@ void balancer_t::flush_reals(common::idp::updateGlobalBaseBalancer::request& bal | |
} | ||
} | ||
|
||
auto reals_wlc = reals_wlc_weight.find(key); | ||
if (reals_wlc != reals_wlc_weight.end() && reals_wlc->second.has_value()) | ||
{ | ||
effective_weight = reals_wlc->second.value(); | ||
} | ||
|
||
uint32_t real_unordered_id = 0; | ||
{ | ||
std::lock_guard<std::mutex> guard(reals_unordered_mutex); | ||
|
@@ -929,8 +935,152 @@ void balancer_t::reconfigure_wlc_thread() | |
{ | ||
while (!flagStop) | ||
{ | ||
balancer_real_flush(); | ||
if (balancer_t::reconfigure_wlc()) | ||
{ | ||
balancer_real_flush(); | ||
} | ||
|
||
std::this_thread::sleep_for(std::chrono::seconds(YANET_CONFIG_BALANCER_WLC_RECONFIGURE)); | ||
} | ||
} | ||
|
||
bool balancer_t::reconfigure_wlc() | ||
{ | ||
bool wlc_weight_changed = false; | ||
|
||
common::idp::updateGlobalBaseBalancer::request balancer; | ||
const auto balancer_real_connections = dataplane.balancer_real_connections(); | ||
|
||
std::lock_guard<std::mutex> guard(reals_enabled_mutex); | ||
|
||
for (const auto& [module_name, balancer] : generations_config.current().config_balancers) | ||
{ | ||
|
||
for (const auto& [service_id, | ||
virtual_ip, | ||
proto, | ||
virtual_port, | ||
version, | ||
scheduler, | ||
scheduler_params, | ||
forwarding_method, | ||
flags, | ||
ipv4_outer_source_network, | ||
ipv6_outer_source_network, | ||
reals] : balancer.services) | ||
{ | ||
(void)flags; | ||
(void)version; | ||
(void)forwarding_method; | ||
(void)ipv4_outer_source_network; | ||
(void)ipv6_outer_source_network; | ||
|
||
if (scheduler != ::balancer::scheduler::wlc) | ||
{ | ||
continue; | ||
} | ||
|
||
if (service_id >= YANET_CONFIG_BALANCER_SERVICES_SIZE) | ||
{ | ||
continue; | ||
} | ||
|
||
std::vector<std::tuple<balancer::real_key_global_t, uint32_t, uint32_t>> service_reals_usage_info; | ||
uint32_t connection_sum = 0; | ||
uint32_t weight_sum = 0; | ||
|
||
for (const auto& [real_ip, real_port, weight] : reals) | ||
{ | ||
balancer::real_key_global_t key = {module_name, {virtual_ip, proto, virtual_port}, {real_ip, real_port}}; | ||
uint32_t effective_weight = weight; | ||
{ | ||
auto it = reals_enabled.find(key); | ||
if (it != reals_enabled.end()) | ||
{ | ||
if (it->second.has_value()) | ||
{ | ||
effective_weight = it->second.value(); | ||
} | ||
} | ||
} | ||
Comment on lines
+995
to
+1005
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. auto found_weight = get_effective_weight(reals_enabled, key);
uint32_t effective_weight = found_weight ? *found_weight : weight; |
||
|
||
weight_sum += effective_weight; | ||
|
||
// don`t count connections for disabled reals - it can make other reals "feel" underloaded | ||
if (effective_weight == 0) | ||
{ | ||
continue; | ||
} | ||
|
||
common::idp::balancer_real_connections::real_key_t real_connections_key = {balancer.balancer_id, | ||
virtual_ip, | ||
proto, | ||
virtual_port.value(), | ||
real_ip, | ||
real_port.value()}; | ||
uint32_t connections = 0; | ||
for (auto& [socket_id, real_connections] : balancer_real_connections) | ||
{ | ||
(void)socket_id; | ||
|
||
auto it = real_connections.find(real_connections_key); | ||
if (it == real_connections.end()) | ||
{ | ||
continue; | ||
} | ||
connections += it->second; | ||
Comment on lines
+1027
to
+1031
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. IMHO if (it != real_connections.end())
{
connections += it->second;
} is cleaner, but feel free no ignore |
||
} | ||
|
||
connection_sum += connections; | ||
|
||
service_reals_usage_info.emplace_back(key, | ||
effective_weight, | ||
connections); | ||
} | ||
|
||
for (auto [key, | ||
effective_weight, | ||
connections] : service_reals_usage_info) | ||
{ | ||
uint32_t wlc_power = scheduler_params.wlc_power; | ||
if (wlc_power < 1 || wlc_power > 100) | ||
{ | ||
wlc_power = YANET_CONFIG_BALANCER_WLC_DEFAULT_POWER; | ||
} | ||
|
||
effective_weight = calculate_wlc_weight(effective_weight, connections, weight_sum, connection_sum, wlc_power); | ||
|
||
if (reals_wlc_weight[key] != effective_weight) | ||
{ | ||
reals_wlc_weight[key] = effective_weight; | ||
real_updates.insert(key); | ||
if (in_reload) | ||
{ | ||
real_reload_updates.insert(key); | ||
} | ||
wlc_weight_changed = true; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return wlc_weight_changed; | ||
} | ||
|
||
uint32_t balancer_t::calculate_wlc_weight(uint32_t weight, uint32_t connections, uint32_t weight_sum, uint32_t connection_sum, uint32_t wlc_power) | ||
{ | ||
if (weight == 0 || weight_sum == 0 || connection_sum < weight_sum) | ||
{ | ||
return weight; | ||
} | ||
|
||
auto wlc_ratio = std::max(1.0, wlc_power * (1 - 1.0 * connections * weight_sum / connection_sum / weight)); | ||
auto wlc_weight = (uint32_t)(weight * wlc_ratio); | ||
|
||
if (wlc_weight > YANET_CONFIG_BALANCER_REAL_WEIGHT_MAX) | ||
{ | ||
wlc_weight = YANET_CONFIG_BALANCER_REAL_WEIGHT_MAX; | ||
} | ||
|
||
return wlc_weight; | ||
} |
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
Oops, something went wrong.
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.
We will have code duplication here with the following lines:
I think we can add a private method in
balancer_t
likeAnd then use it, for example, with compound initialization: