Skip to content

Commit

Permalink
feature: Add option to select best node by free resources in percent.
Browse files Browse the repository at this point in the history
Fixes: #29
  • Loading branch information
gyptazy committed Jul 25, 2024
1 parent 5c6cf04 commit 2df14cb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ The following options can be set in the `proxlb.conf` file:
| api_pass | FooBar | Password for the API. |
| verify_ssl | 1 | Validate SSL certificates (1) or ignore (0). (default: 1) |
| method | memory | Defines the balancing method (default: memory) where you can use `memory`, `disk` or `cpu`. |
| mode | used | Rebalance by `used` resources (efficiency) or `assigned` (avoid overprovisioning) resources. (default: used)|
| mode | used | Rebalance by `used` resources (efficiency) or `assigned` (avoid over provisioning) resources. (default: used)|
| type | vm | Rebalance only `vm` (virtual machines), `ct` (containers) or `all` (virtual machines & containers). (default: vm)|
| balanciness | 10 | Value of the percentage of lowest and highest resource consumption on nodes may differ before rebalancing. (default: 10) |
| ignore_nodes | dummynode01,dummynode02,test* | Defines a comma separated list of nodes to exclude. |
Expand Down
12 changes: 9 additions & 3 deletions proxlb
Original file line number Diff line number Diff line change
Expand Up @@ -495,11 +495,11 @@ def __validate_balancing_mode(balancing_mode):
error_prefix = 'Error: [balancing-mode-validation]:'
info_prefix = 'Info: [balancing-mode-validation]]:'

if balancing_mode not in ['used', 'assigned']:
logging.error(f'{error_prefix} Invalid balancing method: {balancing_mode}')
if balancing_mode not in ['used', 'free_percent', 'assigned']:
logging.error(f'{error_prefix} Invalid balancing mode: {balancing_mode}')
sys.exit(2)
else:
logging.info(f'{info_prefix} Valid balancing method: {balancing_mode}')
logging.info(f'{info_prefix} Valid balancing mode: {balancing_mode}')


def __validate_balanciness(balanciness, balancing_method, balancing_mode, node_statistics):
Expand All @@ -511,6 +511,8 @@ def __validate_balanciness(balanciness, balancing_method, balancing_mode, node_s
# Remap balancing mode to get the related values from nodes dict.
if balancing_mode == 'used':
node_resource_selector = 'free'
if balancing_mode == 'free_percent':
node_resource_selector = 'free'
if balancing_mode == 'assigned':
node_resource_selector = 'assigned'

Expand Down Expand Up @@ -556,6 +558,8 @@ def __get_most_used_resources_vm(balancing_method, balancing_mode, vm_statistics
# Remap balancing mode to get the related values from nodes dict.
if balancing_mode == 'used':
vm_resource_selector = 'used'
if balancing_mode == 'free_percent':
vm_resource_selector = 'used'
if balancing_mode == 'assigned':
vm_resource_selector = 'total'

Expand All @@ -573,6 +577,8 @@ def __get_most_free_resources_node(balancing_method, balancing_mode, node_statis
# Return the node information based on the balancing mode.
if balancing_mode == 'used':
node = max(node_statistics.items(), key=lambda item: item[1][f'{balancing_method}_free'])
if balancing_mode == 'free_percent':
node = max(node_statistics.items(), key=lambda item: item[1][f'{balancing_method}_free_percent'])
if balancing_mode == 'assigned':
node = min(node_statistics.items(), key=lambda item: item[1][f'{balancing_method}_assigned'] if item[1][f'{balancing_method}_assigned_percent'] > 0 or item[1][f'{balancing_method}_assigned_percent'] < 100 else -float('inf'))

Expand Down

0 comments on commit 2df14cb

Please sign in to comment.