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

Performance updates for virtual_attribute_search #557

Merged

Conversation

NickLaMuro
Copy link
Member

@NickLaMuro NickLaMuro commented Feb 7, 2019

Fixes two simple performance issues:

  • Avoids trying to Rbac records that don't need to be "Rbac'd" (first commit)
  • Avoids repeating Rbac on records that have already been checked in the initial collection_search (second commit)

Benchmarks

Before

|   ms | queries | query (ms) | rows |
| ---: |    ---: |       ---: | ---: |
| 2197 |     322 |      194.4 | 1627 |
|  953 |     321 |      182.7 |  196 |
|  996 |     321 |      187.1 |  196 |

After (first commit)

|   ms | queries | query (ms) | rows |
| ---: |    ---: |       ---: | ---: |
| 2274 |     282 |      166.2 | 1612 |
|  858 |     281 |      147.9 |  181 |
|  960 |     281 |      164.2 |  181 |

After (second commit)

|   ms | queries | query (ms) | rows |
| ---: |    ---: |       ---: | ---: |
| 2004 |     263 |      156.8 | 1593 |
|  756 |     261 |      142.9 |  161 |
|  769 |     261 |      138.9 |  161 |

TODO

  • Make sure existing tests pass...
  • Add Tests

Links

@NickLaMuro
Copy link
Member Author

@lpichler Can I have you take a look at this and make sure this still falls in line with the goals of ManageIQ/manageiq#15145 ? I might adds some tests before calling this good, but would at least like your opinion if what I changed here seems kosher. Thanks!

@lpichler
Copy link
Contributor

@lpichler Can I have you take a look at this and make sure this still falls in line with the goals of ManageIQ/manageiq#15145 ? I might adds some tests before calling this good, but would at least like your opinion if what I changed here seems kosher. Thanks!

@NickLaMuro Looks good to me, I tested out - nice finding - just question to - would be helpful to bring your Better Rbac-able check mechanism from first commit also for this RBAC call ?

thanks!

@NickLaMuro
Copy link
Member Author

@lpichler Thanks for taking a look!

would be helpful to bring your Better Rbac-able check mechanism from first commit also for this RBAC call ?

Oh, I assume you mean this part:

return resource_attr unless Rbac::Filterer.new.send(:apply_rbac_directly?, klass)

Then yeah, I think this makes sense to do. I can add that and hopefully getting to writing some tests for this today as well.

Thanks again!

@kbrock
Copy link
Member

kbrock commented Feb 26, 2019

Note: This is for speeding up https://bugzilla.redhat.com/show_bug.cgi?id=1656371

@kbrock
Copy link
Member

kbrock commented Mar 7, 2019

:shipit: :)

@kbrock
Copy link
Member

kbrock commented Mar 21, 2019

@NickLaMuro does it make sense to add this bail out shortcut to Rbac#filtered?

@NickLaMuro NickLaMuro force-pushed the optimized_virtual_attribute_search branch from 07178e7 to c1d7f9e Compare March 25, 2019 21:03
@NickLaMuro NickLaMuro changed the title [WIP][POC] Performance updates for virtual_attribute_search Performance updates for virtual_attribute_search Mar 25, 2019
@NickLaMuro NickLaMuro force-pushed the optimized_virtual_attribute_search branch from c1d7f9e to ccd826b Compare March 25, 2019 21:08
@miq-bot miq-bot removed the wip label Mar 25, 2019
@NickLaMuro
Copy link
Member Author

NickLaMuro commented Mar 25, 2019

Added some specs on this one, so removed the [WIP] on this as I feel a little more confident now with some tests validating some of the changes.

Previously, the check against the `resource_attr` was only handling
cases where the resource was "ActiveRecord-like", but didn't properly
handle when the record in question wasn't something that we apply Rbac
on to begin with.

This properly makes that check (in a slightly hacky fashion).

Benchmarks:
-----------

Example request:

```
url: /api/services
attributes:
  expand: resources
  attributes:
    - picture
    - picture.image_href
    - chargeback_report
    - evm_owner.userid
    - v_total_vms
    - power_state
    - all_service_children
    - tags
  filter[]:      ancestry=null
  sort_by:       created_at
  sort_options:  nil
  sort_order:    desc
  limit:         20
  offset:        0
```

**Before**

```
|   ms | queries | query (ms) | rows |
| ---: |    ---: |       ---: | ---: |
| 2197 |     322 |      194.4 | 1627 |
|  953 |     321 |      182.7 |  196 |
|  996 |     321 |      187.1 |  196 |
```

**After**

```
|   ms | queries | query (ms) | rows |
| ---: |    ---: |       ---: | ---: |
| 2274 |     282 |      166.2 | 1612 |
|  858 |     281 |      147.9 |  181 |
|  960 |     281 |      164.2 |  181 |
```
Previously, the same record that was already "Rbac'd" in the initial
`.collection_search` for an `index` action would be re-done for each
`virtual_attribute` that wasn't in a `has_many`-like relationship.

This made little sense as it wasn't provided any better granularity for
permissions, since the permissions where already checked once before,
and it was a pretty obvious `N+1`.  Also checks that the class is
filterable by Rbac, otherwise that will also just return the attribute.

Benchmarks:
-----------

Example request:

```
url: /api/services
attributes:
  expand: resources
  attributes:
    - picture
    - picture.image_href
    - chargeback_report
    - evm_owner.userid
    - v_total_vms
    - power_state
    - all_service_children
    - tags
  filter[]:      ancestry=null
  sort_by:       created_at
  sort_options:  nil
  sort_order:    desc
  limit:         20
  offset:        0
```

**Before** (previous commit)

```
|   ms | queries | query (ms) | rows |
| ---: |    ---: |       ---: | ---: |
| 2274 |     282 |      166.2 | 1612 |
|  858 |     281 |      147.9 |  181 |
|  960 |     281 |      164.2 |  181 |
```

**After**

```
|   ms | queries | query (ms) | rows |
| ---: |    ---: |       ---: | ---: |
| 2004 |     263 |      156.8 | 1593 |
|  756 |     261 |      142.9 |  161 |
|  769 |     261 |      138.9 |  161 |
```

Note:  Metrics were taken three times right after a server restart, so
the first request suffers from autoloading slowness.
@NickLaMuro NickLaMuro force-pushed the optimized_virtual_attribute_search branch from ccd826b to 1ad20d2 Compare March 25, 2019 21:13
@miq-bot
Copy link
Member

miq-bot commented Mar 25, 2019

Checked commits NickLaMuro/manageiq-api@9cedec7~...1ad20d2 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 0 offenses detected
Everything looks fine. 🍪

Copy link
Member

@kbrock kbrock left a comment

Choose a reason for hiding this comment

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

Such a big improvement

Later we’ll research how to get changed like these into rbac itself

Copy link
Contributor

@lpichler lpichler left a comment

Choose a reason for hiding this comment

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

thanks 👍

BTW: you have tests here, so you can check test item✔️ in description :)

@lpichler
Copy link
Contributor

lpichler commented Apr 9, 2019

@miq-bot assign @abellotti

@NickLaMuro
Copy link
Member Author

BTW: you have tests here, so you can check test item✔️ in description :)

@lpichler Sorry I missed this (@kbrock bugged me about it). Thanks!

@kbrock
Copy link
Member

kbrock commented Apr 22, 2019

@abellotti does this look good for you?
Or is there anything to help push this forward?

@kbrock
Copy link
Member

kbrock commented Apr 22, 2019

@miq-bot add_label bug

@miq-bot miq-bot added the bug label Apr 22, 2019
@abellotti abellotti added this to the Sprint 111 Ending May 13, 2019 milestone Apr 30, 2019
@abellotti
Copy link
Member

This looks great @NickLaMuro Thanks for fixing this. 👍

@abellotti abellotti merged commit 4a63f71 into ManageIQ:master Apr 30, 2019
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.

5 participants