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

fix: Fix CPU balancing where calculations are done in float instead of int. #93

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions .changelogs/1.0.4/75_fix_cpu_balancing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fixed:
- Fix CPU balancing where calculations are done in float instead of int. (by @glitchvern) [#75]
11 changes: 8 additions & 3 deletions proxlb
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,11 @@ def get_node_statistics(api_object, ignore_nodes, maintenance_nodes):
node_statistics[node['node']]['maintenance'] = False
node_statistics[node['node']]['ignore'] = False
node_statistics[node['node']]['cpu_total'] = node['maxcpu']
node_statistics[node['node']]['cpu_assigned'] = node['cpu']
node_statistics[node['node']]['cpu_assigned'] = 0
node_statistics[node['node']]['cpu_assigned_percent'] = int((node_statistics[node['node']]['cpu_assigned']) / int(node_statistics[node['node']]['cpu_total']) * 100)
node_statistics[node['node']]['cpu_assigned_percent_last_run'] = 0
node_statistics[node['node']]['cpu_used'] = 0
node_statistics[node['node']]['cpu_free'] = int(node['maxcpu']) - int(node['cpu'])
node_statistics[node['node']]['cpu_used'] = node['cpu']
node_statistics[node['node']]['cpu_free'] = (node['maxcpu']) - (node['cpu'] * node['maxcpu'])
node_statistics[node['node']]['cpu_free_percent'] = int((node_statistics[node['node']]['cpu_free']) / int(node['maxcpu']) * 100)
node_statistics[node['node']]['cpu_free_percent_last_run'] = 0
node_statistics[node['node']]['memory_total'] = node['maxmem']
Expand Down Expand Up @@ -834,6 +834,11 @@ def balancing_vm_calculations(balancing_method, balancing_mode, balancing_mode_o
resources_vm_most_used, processed_vms = __get_most_used_resources_vm(balancing_method, balancing_mode, vm_statistics, processed_vms)
resources_node_most_free = __get_most_free_resources_node(balancing_method, balancing_mode, balancing_mode_option, node_statistics)

# If most used vm is on most free node then skip it and get another one.
while resources_vm_most_used[1]['node_parent'] == resources_node_most_free[0] and len(processed_vms) < len(vm_statistics):
resources_vm_most_used, processed_vms = __get_most_used_resources_vm(balancing_method, balancing_mode, vm_statistics, processed_vms)
logging.debug(f'{info_prefix} processed {len(processed_vms)} out of {len(vm_statistics)} vms.')

# Update resource statistics for VMs and nodes.
node_statistics, vm_statistics = __update_vm_resource_statistics(resources_vm_most_used, resources_node_most_free,
vm_statistics, node_statistics, balancing_method, balancing_mode)
Expand Down
Loading