-
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
Performance improvements to MiqProvisionVirtWorkflow#allowed_templates #18353
Performance improvements to MiqProvisionVirtWorkflow#allowed_templates #18353
Conversation
2d3c993
to
84a3280
Compare
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.
This is nice.
Even without the performance improvements
84a3280
to
2ce540b
Compare
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.
This looks much nicer.
I'll give @syncrou a little time to check it out.
I'll merge tomorrow unless I hear otherwise
If we aren't in DEBUG mode for `_log` (evm.log), render the strings and loop through the list to "print debug statements. Also fixed some rubocop complexity issues by moving this logic into it's own method.
2ce540b
to
e00cd2a
Compare
Use virtual_attributes where possible when fetching from the `vms` table to avoid memory bloat. Makes use of `Rbac`'s `:extra_cols` feature. Benchmark --------- **Before** | ms | queries | query (ms) | rows | | ---: | ---: | ---: | ---: | | 110281 | 36 | 3005.5 | 364586 | | 106174 | 36 | 2786.2 | 364586 | | 106952 | 36 | 2812.0 | 364586 | **After** | ms | queries | query (ms) | rows | | ---: | ---: | ---: | ---: | | 43988 | 33 | 2435.7 | 243133 | | 44452 | 33 | 2438.9 | 243133 | | 44009 | 33 | 2470.0 | 243133 |
In #create_hash_struct_from_vm_or_template, avoid generating the `MiqHashStruct` until the end of the method to prevent expensive method missing calls for every generated record. Also does a few things to improve things: - Use `.ems_id` instead of `.ext_management_system`, since it is a non-sql way of checking if there is a relation (performance) - Fixes some rubocop complaints by changing/inverting the if statements
This creates a @_ems_allowed_templates_cache, which is used to keep track of the IDs of ems records that have been fetched, and prevents and additional loop over the @allowed_templates records to perform a preload of the associated ems records. In the case of a AWS Ems with 100k+ templates (after a refresh including public images), this is a non-trivial amount of work that is worth avoiding. Benchmark --------- **Before** | ms | queries | query (ms) | rows | | ---: | ---: | ---: | ---: | | 44251 | 33 | 2479.0 | 243133 | | 43795 | 33 | 2433.2 | 243133 | | 41723 | 33 | 2468.1 | 243133 | **After** | ms | queries | query (ms) | rows | | ---: | ---: | ---: | ---: | | 39488 | 33 | 2439.4 | 243133 | | 38879 | 33 | 2438.2 | 243133 | | 39256 | 33 | 2444.3 | 243133 |
e00cd2a
to
88c1cb7
Compare
@tinaafitz Could you or someone from the automate team also give this a look and confirm what is here is okay? |
@miq-bot remove_label unmergeable |
@miq-bot add_label ivanchuk/yes |
@mkanoor @gmcculloug @lfu Please review. |
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.
Nice job!
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.
Overall this looks good to me, but I suggest we hold off merging until @kbrock can review and comment on https://github.com/ManageIQ/manageiq/pull/18353/files#r312716130
@gmcculloug thanks!
Yeah, I agree. At this point, it isn't going to get merged any faster if we don't wait for Keenan to get back Monday, so let's just do that. |
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.
LGTM. just the one comment/response
This reduces the number of columns returned from the VMs table to reduce what is returned and serialized from the DB. Benchmark --------- **Before** | ms | queries | query (ms) | rows | | ---: | ---: | ---: | ---: | | 39488 | 33 | 2439.4 | 243133 | | 38879 | 33 | 2438.2 | 243133 | | 39256 | 33 | 2444.3 | 243133 | **After** | ms | queries | query (ms) | rows | | ---: | ---: | ---: | ---: | | 28440 | 33 | 1929.5 | 243133 | | 28491 | 33 | 1933.6 | 243133 | | 28858 | 33 | 2631.9 | 243133 |
respond_to? calls in mass are slow since they require some object introspection, where doing a simple `nil` check is much quicker. By including just the `cloud_tenant_id` in the SELECT clause, it allows for the swapping of `respond_to?` with an `nil` check, with the functionality that existed preserved. Benchmark --------- **Before** | ms | queries | query (ms) | rows | | ---: | ---: | ---: | ---: | | 28440 | 33 | 1929.5 | 243133 | | 28491 | 33 | 1933.6 | 243133 | | 28858 | 33 | 2631.9 | 243133 | **After** | ms | queries | query (ms) | rows | | ---: | ---: | ---: | ---: | | 27107 | 33 | 1958.5 | 243133 | | 26803 | 33 | 1944.2 | 243133 | | 27642 | 33 | 1965.5 | 243133 |
88c1cb7
to
f83c69f
Compare
Checked commits NickLaMuro/manageiq@32be9ec~...f83c69f with ruby 2.4.6, rubocop 0.69.0, 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.
@miq-bot add_label blocker |
…_better_allowed_templates Performance improvements to MiqProvisionVirtWorkflow#allowed_templates (cherry picked from commit e1ed394) https://bugzilla.redhat.com/show_bug.cgi?id=1662972
Ivanchuk backport details:
|
This PR introduces a number of improvements to the
MiqProvisionVirtWorkflow#allowed_templates
, and specifically is beneficial to environments that have EMS's with lots of templates (Amazon in particular when public images are included).These changes specifically do as much as possible without trying to change anything in the database, but a follow up PR (will be posted shortly) will take these changes further with a few database modifications.
Notable Changes
More specific numbers in the commit messages.
Links
Steps for Testing/QA
The main pain points with this can be recreated with a single AWS EMS that has public images enabled, and has had it's initial refresh.
I was using a combination of this script for testing the full routes:
And this one, which tested
MiqProvisionVirtWorkflow#allowed_templates
on it's own: