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

Implement optimistic resource quota utilization computation #60

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

bastian-src
Copy link
Contributor

Instead of re-computing the Resource Quota utilization by iterating all Resource Quota hosts and determining their resources, an optimistic tracking of the utilized resources is implemented.

When a host is created/added to a Resource Quota, its resources are determined once and added to the Resource Quota utilization. When a host is destroyed/unassigned from a Resource Quota, its utilization is freed from the host's resource capacities.

Comment on lines 10 to 11
validate :verify_resource_quota_on_create, if: -> { new_record? }
validate :verify_resource_quota_on_change, if: -> { resource_quota_id_change_to_be_saved && !new_record? }
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
validate :verify_resource_quota_on_create, if: -> { new_record? }
validate :verify_resource_quota_on_change, if: -> { resource_quota_id_change_to_be_saved && !new_record? }
validate :verify_resource_quota_on_host_create, if: -> { new_record? }
validate :verify_resource_quota_on_resource_quota_change, if: -> { resource_quota_id_change_to_be_saved && !new_record? }

Copy link
Contributor

Choose a reason for hiding this comment

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

Even better: Merge the two methods into one.


host_resources.each do |resource_type, resource_value|
new_utilization[resource_type] ||= 0
new_utilization[resource_type] = yield(new_utilization[resource_type], resource_value, resource_type)
Copy link
Contributor

Choose a reason for hiding this comment

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

Try to simplify the code such that it is easier to understand.

@bastian-src bastian-src force-pushed the feature/switch_to_stored_utilization branch from 2ba48da to a34fedc Compare November 13, 2024 15:20
@bastian-src bastian-src force-pushed the feature/switch_to_stored_utilization branch from fdf8253 to e5798e9 Compare November 18, 2024 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants