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

Avoid duplicate host load in allowed_hosts_obj #17402

Merged

Conversation

NickLaMuro
Copy link
Member

@NickLaMuro NickLaMuro commented May 9, 2018

MiqRequestWorkflow#allowed_hosts_obj originally would collect the known host ids from the ems tree it has already built up, combine those with any hosts associated to the storage it had, do a query against the src[:ems]'s hosts, and select only the ones that match the original set of host ids. From there, it would take that list of host objects, throw it through Rbac, which would also make another query to find the hosts that match that list AND filter it based on the targeted user, throwing out the previously instantiated hosts that were used as the intermediate list from src[:ems].

This change simply avoids creating that intermediate Host object list by replacing the .find_all with a .where, meaning we pass a scoped query to Rbac (instead of an Array) that hasn't been executed until it has the user filter applied to it.

Metrics

Benchmarks were taken by monitoring the UI requests using the manageiq_performance gem. The route monitored was selecting the "Lifecycle" -> "Publish this VM to a Template" menu button from a VM show page. The metrics shown are against database with a fairly large EMS, with about 600 hosts, and are 3 subsequent requests against that route.

Note the change in row counts:

Before

ms queries query (ms) rows
18613 2062 1463.7 70017
17695 2062 1475.5 70017
17774 2062 1578.4 70017

After

ms queries query (ms) rows
18553 2061 1560.7 61866
17385 2061 1564.6 61866
17468 2061 1437.5 61866

Note: The benchmarks for this change do NOT include the changes from other PRs (#17354 for example). Benchmarks of all changes can be found here.

Links

MiqRequestWorkflow#allowed_hosts_obj originally would collect the known
host ids from the ems tree it has already built up, combine those with
any hosts associated to the storage it had, do a query against the
`src[:ems]`'s hosts, and select only the ones that match the original
set of host ids.  From there, it would take that list of host objects,
throw it through Rbac, which would also make another query to find the
hosts that match that list AND filter it based on the targeted user,
throwing out the previously instantiated hosts that were used as the
intermediate list from `src[:ems]`.

This change simply avoids creating that intermediate `Host` object list
by replacing the `.find_all` with a `.where`, meaning we pass a scoped
query to Rbac (instead of an `Array`) that hasn't been executed until it
has the user filter applied to it.

Metrics
-------

Benchmarks were taken by monitoring the UI requests using the
`manageiq_performance` gem.  The route monitored was selecting the
`"Lifecycle" -> "Publish this VM to a Template"` menu button from a VM
show page.  The metrics shown are against database with a fairly large
EMS, with about 600 hosts, and are 3 subsequent requests against that
route.

**Before**

|    ms | queries | query (ms) |  rows |
|  ---: |    ---: |       ---: |  ---: |
| 18613 |    2062 |     1463.7 | 70017 |
| 17695 |    2062 |     1475.5 | 70017 |
| 17774 |    2062 |     1578.4 | 70017 |

**After**

|    ms | queries | query (ms) |  rows |
|  ---: |    ---: |       ---: |  ---: |
| 18553 |    2061 |     1560.7 | 61866 |
| 17385 |    2061 |     1564.6 | 61866 |
| 17468 |    2061 |     1437.5 | 61866 |
@NickLaMuro NickLaMuro force-pushed the lighter_queries_in_miq_request_workflow branch from ac52ed3 to 809f655 Compare May 9, 2018 21:35
@miq-bot
Copy link
Member

miq-bot commented May 9, 2018

Checked commit NickLaMuro@809f655 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
1 file checked, 0 offenses detected
Everything looks fine. 🏆

@NickLaMuro
Copy link
Member Author

@miq-bot add_label fine/yes, gaprindashvili/yes

@agrare agrare added this to the Sprint 87 Ending Jun 4, 2018 milestone Jun 4, 2018
simaishi pushed a commit that referenced this pull request Jun 21, 2018
…est_workflow

Avoid duplicate host load in allowed_hosts_obj
(cherry picked from commit d577df7)

https://bugzilla.redhat.com/show_bug.cgi?id=1593798
@simaishi
Copy link
Contributor

Fine backport details:

$ git log -1
commit 361707d59833a4b0b388e4f880b6e7cc9f022c84
Author: Greg McCullough <[email protected]>
Date:   Tue May 22 15:45:25 2018 -0400

    Merge pull request #17402 from NickLaMuro/lighter_queries_in_miq_request_workflow
    
    Avoid duplicate host load in allowed_hosts_obj
    (cherry picked from commit d577df7a6d6f28c24264a65b30d7011db1d6d71a)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1593798

simaishi pushed a commit that referenced this pull request Jun 21, 2018
…est_workflow

Avoid duplicate host load in allowed_hosts_obj
(cherry picked from commit d577df7)

https://bugzilla.redhat.com/show_bug.cgi?id=1593797
@simaishi
Copy link
Contributor

Gaprindashvili backport details:

$ git log -1
commit 6296c6044b096edc6d45bd83017f504163e9f785
Author: Greg McCullough <[email protected]>
Date:   Tue May 22 15:45:25 2018 -0400

    Merge pull request #17402 from NickLaMuro/lighter_queries_in_miq_request_workflow
    
    Avoid duplicate host load in allowed_hosts_obj
    (cherry picked from commit d577df7a6d6f28c24264a65b30d7011db1d6d71a)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1593797

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants