-
Notifications
You must be signed in to change notification settings - Fork 898
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
Add uniq on datacenters in #host_to_folder #17422
Add uniq on datacenters in #host_to_folder #17422
Conversation
The more stripped down version of this method, prior to the change, is as follows: def host_to_folder(src) sources = src[:host].nil? ? allowed_hosts_obj : [src[:host]] datacenters = sources.collect { |h| find_datacenter_for_ci(h) end.compact datacenters.each_with_object({}) do |dc, folders| folders.merge!(get_ems_folders(dc)) end end The `find_datacenter_for_ci` method basically looks up the datacenter for the matching host object in the xml tree that has been generated. In most (all) cases though, their will be more than one host per datacenter, and that wasn't taken into account for this method since the next block blindly takes those datacenters and merges the folder structure it gets from `get_ems_folders` for each datacenter. By adding a `.uniq` prior to the assignment of datacenters, this saves a significant number of unnecessary CPU cycles and object allocations to fetch the same data and apply it to the `folders` variable, without changing the end result. Note: Ideally we would want a better algorithm for finding the datacenters for a collection of hosts, one that allowed for ejecting early from find_datacenter_for_ci when we knew an existing datacenter for a given host had already been found. But the time taken to get the datacenters from the hosts is far less in CPU time than the time taken to call `#get_ems_folders` per datacenter object and merge the hash with the existing results.
Checked commit NickLaMuro@1bc8c3f with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.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.
@NickLaMuro - LGTM
@miq-bot add_label fine/yes, gaprindashvili/yes |
@miq-bot add_label performance, provisioning |
…ders_for_datacenters Add uniq on datacenters in #host_to_folder (cherry picked from commit 9b33e0b) https://bugzilla.redhat.com/show_bug.cgi?id=1593798
Fine backport details:
|
…ders_for_datacenters Add uniq on datacenters in #host_to_folder (cherry picked from commit 9b33e0b) https://bugzilla.redhat.com/show_bug.cgi?id=1593797
Gaprindashvili backport details:
|
The more stripped down version of this method, prior to the change, is as follows:
When setting the
datacenters
local variable in that method, thefind_datacenter_for_ci
method basically looks up the datacenter for the matchingHost
object in the xml tree that has most likely already been generated. In most/all cases, though, their will be more than one host per datacenter, and that wasn't taken into account for this method since the next block blindly takes the datacenters it found previously and merges the folder structure it gets fromget_ems_folders
for each datacenter.By adding a
.uniq
prior to the assignment of datacenters, this saves a significant number of unnecessary CPU cycles and object allocations to fetch the same data and apply it to thefolders
variable, without changing the end result.Note: Ideally we would want a better algorithm for finding the datacenters for a collection of hosts, one that allowed for ejecting early from find_datacenter_for_ci when we knew an existing datacenter for a given host had already been found. But the time taken to get the datacenters from the hosts is far less in CPU time than the time taken to call
#get_ems_folders
per datacenter object and merge the hash with the existing results.Benchmarks
The benchmark script used here basically runs the following:
And is targeting a fairly large EMS, with about 600 hosts.
Note: The benchmarks for this change do NOT include the changes from other PRs in the links below. Benchmarks of all changes can be found here.
Links