-
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
Convert ComplianceMixin to use has_one/virtual_delegate #17475
Convert ComplianceMixin to use has_one/virtual_delegate #17475
Conversation
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 very promising / sweet.
Let me know when the tests are in.
|
||
virtual_delegate :last_compliance_status, | ||
:to => "last_compliance.compliant", | ||
:type => :boolean, |
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.
pretty sure :type
not required (for either of these)
@NickLaMuro could you rebase to get rid of the first commit? Possibly drop the |
When this becomes a priority or I have free time, sure. Update: Added the |
adfbfb5
to
890dcd7
Compare
@NickLaMuro is this still a WIP? (it is good stuff) |
890dcd7
to
c1a57a2
Compare
This converts the functionality defined in the virtual_has_one, virtual_columns, and associated methods to a has_one and a pair of virtual_delegates. This allows these columns to also be used in SQL, and removes some of the boilerplate code necessary for the methods that are defined.
c1a57a2
to
f6a75b0
Compare
@kbrock yes, it was. Was getting some specs together (via some blatant plagiarism of your specs from #18198), as well as putting together some metrics and reproduction steps in place. But now it is not. |
Checked commit NickLaMuro@f6a75b0 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.
This looks great. I kicked one test - looked like a sporadic failure. I will merge once it goes green.
Thanks for catching that! |
This PR causes ui-classic travis to go red:
seems that..
(mentioning ManageIQ/manageiq-ui-classic#4921) |
Over time, the `compliances` table will get quiet large, and when paired with the rest of the tables in this report, you end up getting a query executed that looks like this: SELECT "vms"."id" AS t0_r0, ..., "vms"."memory_hot_add_increment" AS t0_r75, "hosts"."id" AS t1_r0, ..., "hosts"."physical_server_id" AS t1_r36, "storages"."id" AS t2_r0, ..., "storages"."storage_domain_type" AS t2_r18, "ext_management_systems"."id" AS t3_r0, ..., "ext_management_systems"."tenant_mapping_enabled" AS t3_r23, "snapshots"."id" AS t4_r0, ..., "snapshots"."ems_ref" AS t4_r16, "compliances"."id" AS t5_r0, ..., "compliances"."event_type" AS t5_r6, "operating_systems"."id" AS t6_r0, ..., "operating_systems"."kernel_version" AS t6_r25, "hardwares"."id" AS t7_r0, ..., "hardwares"."provision_state" AS t7_r34, "tags"."id" AS t8_r0, "tags"."name" AS t8_r1 FROM "vms" LEFT OUTER JOIN "hosts" ON "hosts"."id" = "vms"."host_id" LEFT OUTER JOIN "storages" ON "storages"."id" = "vms"."storage_id" LEFT OUTER JOIN "ext_management_systems" ON "ext_management_systems"."id" = "vms"."ems_id" LEFT OUTER JOIN "snapshots" ON "snapshots"."vm_or_template_id" = "vms"."id" LEFT OUTER JOIN "compliances" ON "compliances"."resource_id" = "vms"."id" AND "compliances"."resource_type" = $1 LEFT OUTER JOIN "operating_systems" ON "operating_systems"."vm_or_template_id" = "vms"."id" LEFT OUTER JOIN "hardwares" ON "hardwares"."vm_or_template_id" = "vms"."id" LEFT OUTER JOIN "taggings" ON "taggings"."taggable_id" = "vms"."id" AND "taggings"."taggable_type" = $2 LEFT OUTER JOIN "tags" ON "tags"."id" = "taggings"."tag_id" WHERE "vms"."type" IN (...) AND "vms"."template" = $3 AND (lower(vms.name) like '%win2k%' escape '`') AND "vms"."id" IN (...) ORDER BY LOWER("vms"."name") ASC This ends up creating 243 columns per record, and the number of rows returned has been observed to be over 80k with just 20 VMs being targeted in the `"vms"."id" IN (...)` portion of the query. Since some fixes have been made to avoid the N+1 that results from doing this: - ManageIQ/manageiq#17473 - ManageIQ/manageiq#17474 - ManageIQ/manageiq#17475 It is much better to do use those facilities. Even with the N+1, it is much better making extra round trips than the gigs of data that would be returned as a result.
related to https://bugzilla.redhat.com/show_bug.cgi?id=1733351 but please don't merge yet until we verify this |
@simaishi I have verified that this PR does indeed removed the join to compliances in Hammer |
@kbrock Please add a comment regarding this PR in the BZ. I don't look for |
…iance_to_virtual_delegate Convert ComplianceMixin to use has_one/virtual_delegate (cherry picked from commit 391cf5d) https://bugzilla.redhat.com/show_bug.cgi?id=1738266
Hammer backport details:
|
Built off of: #17473Now MergedThis converts the functionality defined in the
virtual_has_one
,virtual_columns
, and associated methods to ahas_one
and a pair ofvirtual_delegates
.This allows these columns to also be used in SQL, and removes some of the boilerplate code necessary for the methods that are defined.
This allows the changes in #17474 to then be used on the
Compute -> Infrastructure -> Host
page, among others, and circumvents needing all of the compliance records to be downloaded to get thelast_compliance_status
for those reports.Metrics
An example set of runs I had with a 50
Host
provider:Before
After
Links
Steps for Testing/QA
Need to build up some seed data, but a before and after with all of these changes in place makes it so that when a large number of compliance reports exists for a small number of hosts (even when it is something like 20...), there isn't aLEFT JOIN
bomb to build the report data (due to the.includes
/.references
calls inRbac
).Here is some test data that I was using:
https://gist.github.com/NickLaMuro/225833358423723ed17ff294415fa6b4
For testing, I did the following:
bin/rails r bz_1580569_db_replication_script.rb
bin/rails s
Compute -> Infrastructure -> Providers
in the side menuper_page
to 1k (just to load all of the records in a single pageHost
records, ideally)Hosts
buttonBetween
master
, and this change, you should see the number of queries per request for the last portion in the above drop by the number ofHost
records for that provider. TheMetrics
section above used this process.