This bug has been migrated to another issue tracking site. It has been closed here and may no longer be being monitored.

If you would like to get updates for this issue, or to participate in it, you may do so at Red Hat Issue Tracker .
Red Hat Satellite engineering is moving the tracking of its product development work on Satellite to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "Satellite project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs will be migrated starting at the end of May. If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "Satellite project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/SAT-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 2142379 - API search for all katello objects redundantly slow
Summary: API search for all katello objects redundantly slow
Keywords:
Status: CLOSED MIGRATED
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Repositories
Version: 6.11.0
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: Unspecified
Assignee: satellite6-bugs
QA Contact: Cole Higgins
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-11-13 14:49 UTC by Pavel Moravec
Modified: 2024-10-05 04:25 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2024-06-06 12:55:04 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker   SAT-25423 0 None Migrated None 2024-06-06 12:55:03 UTC

Description Pavel Moravec 2022-11-13 14:49:44 UTC
Description of problem:
User story: a Satellite with 275k packages is imperformant when querying all packages.

The reason is how scoped_search method works - basically it attempt to hunt too many tails. In our case "get me all packages", it raises at least two complete/complex search queries "get me all packages associated to repos in (list of all repos)".

The nested "associated to repos in <all_repos>" is one performance penalty that is worth of exploring possible simplification (and I haven't dug into it at all).

The second / main point is the repetitive search queries that are sometimes redundant but invoked due to the "let hunt all the tails" reason. I.e.:

    def scoped_search(query, default_sort_by, default_sort_order, options = {})
..
      total = scoped_search_total(query, group)
..
(some optional changes to the query)
..
      subtotal = total.zero? ? 0 : scoped_search_total(query, group)

If the query is not changed at all, we call fully redundant scoped_search_total (which might but not need to be cached).

If the query is changed just cosmetically (well, how to detect it?), we run full scoped_search_total as well. Despite we are not interested in subtotals at all.

Similarly, when we are interested in subtotals, we still invoke a *full* query (*not* only "SELECT COUNT(*)", but full "SELECT *") to feed "total" variable.

TL;DR: the scoped_search should have some smart conditions "invoke this search only when really demanded". This can save us half of search time.



Version-Release number of selected component (if applicable):
Sat 6.11.*


How reproducible:
100%


Steps to Reproduce:
0. Optionally enable sql debugs to see particular sql queries raised by katello - see https://access.redhat.com/solutions/2252291 how to enable it.
1. Have a Satellite with >200k packages; optionally play with :packages_restrict_latest settings (default=false is more evident for the bugzilla).
2. Add to /usr/share/gems/gems/katello-*/app/controllers/katello/api/v2/api_controller.rb debugs per Additional info.
3. Invoke a "get me all packages" query:

time curl -u admin:PASSWORD -k "https://$(hostname -f)/katello/api/v2/packages?organization_id=1" > /dev/null 2>&1

4. Check in production.log timestamps of the debugs (and overall execution time of the query/request.


Actual results:
4. Two similarly long delays between debugs appear, like:

2022-11-08T12:12:07 [I|app|6547c669] 03347790: index_relation to return, size=275444
2022-11-08T12:12:24 [I|app|6547c669] 03347790: final_custom_index_relation collection=275444

and:

2022-11-08T12:12:24 [I|app|6547c669] 03347790: scoped_search, group=
2022-11-08T12:12:37 [I|app|6547c669] 03347790: scoped_search, subtotal=275444

pointing to these methods taking too long (and one is redundantly called for our use case):

      total = scoped_search_total(query, group)
..
(some optional changes to the query)
..
      subtotal = total.zero? ? 0 : scoped_search_total(query, group)

And overall execution time spans many tens of seconds.


Expected results:
For such plain requests, katello should not query total or subtotal (or, if necessary, query their counts only - verify with sql debugs).

For overall execution time: it is questionable how high times are still acceptable, but for even a scaled Satellite, opening WebUI Packages page should not last >30 seconds, imho.


Additional info:
To make this even more complex, the query *object* is changing despite it shouldnt, by adding debugs:

      Rails.logger.info("03347790: total query=#{query} group=#{group}")
      total = scoped_search_total(query, group)
      # If you get an ArgumentError here (wrong number of arguments given)
      # it's probably because query is an array and not an ActiveRecord::Relation
      query = query.select(:id) if query.respond_to?(:select)
      Rails.logger.info("03347790: select query=#{query} group=#{group}")
      query = resource.search_for(*search_options).where("#{resource.table_name}.id" => query)
      Rails.logger.info("03347790: search_for query=#{query} group=#{group}")

      query = self.final_custom_index_relation(query) if self.respond_to?(:final_custom_index_relation)

      Rails.logger.info("03347790: final_custom_index_relation query=#{query} group=#{group}")
      query = query.select(group).group(group) if group
      Rails.logger.info("03347790: second total, query=#{query} group=#{group}")
      subtotal = total.zero? ? 0 : scoped_search_total(query, group)
      Rails.logger.info("03347790: scoped_search, subtotal=#{subtotal}")
      selectable = total.zero? ? 0 : scoped_search_total_selectable(query, group)

      Rails.logger.info("03347790: scoped_search, custom_sort")

then I got:

2022-11-13T15:21:36 [I|app|4e42087b] 03347790: total query=#<Katello::Rpm::ActiveRecord_Relation:0x00005605f8ff16b8> group=
2022-11-13T15:21:39 [I|app|4e42087b] 03347790: select query=#<Katello::Rpm::ActiveRecord_Relation:0x00007f1b5920ed08> group=
2022-11-13T15:21:39 [I|app|4e42087b] 03347790: search_for query=#<Katello::Rpm::ActiveRecord_Relation:0x00007f1b5920d930> group=
2022-11-13T15:21:39 [I|app|4e42087b] 03347790: final_custom_index_relation start, BT=/usr/share/gems/gems/katello-4.3.0.47/app/controllers/katello/api/v2/api_controller.rb:97:in `scoped_search'
2022-11-13T15:21:39 [I|app|4e42087b] 03347790: final_custom_index_relation restrict_latest=false
2022-11-13T15:21:39 [I|app|4e42087b] 03347790: final_custom_index_relation collection=39579
2022-11-13T15:21:39 [I|app|4e42087b] 03347790: final_custom_index_relation query=#<Katello::Rpm::ActiveRecord_Relation:0x00007f1b5920d930> group=
2022-11-13T15:21:39 [I|app|4e42087b] 03347790: second total, query=#<Katello::Rpm::ActiveRecord_Relation:0x00007f1b5920d930> group=

but why query object changed e.g. by:

query = self.final_custom_index_relation(query) if self.respond_to?(:final_custom_index_relation)

if Katello::Api::V2::PackagesController.final_custom_index_relation performs *nothing* when we have params[:packages_restrict_latest] = false ?)

Comment 2 Eric Helms 2024-06-06 12:55:04 UTC
This BZ has been automatically migrated to the issues.redhat.com Red Hat Issue Tracker. All future work related to this report will be managed there.

Due to differences in account names between systems, some fields were not replicated.  Be sure to add yourself to Jira issue's "Watchers" field to continue receiving updates and add others to the "Need Info From" field to continue requesting information.

To find the migrated issue, look in the "Links" section for a direct link to the new issue location. The issue key will have an icon of 2 footprints next to it, and begin with "SAT-" followed by an integer.  You can also find this issue by visiting https://issues.redhat.com/issues/?jql= and searching the "Bugzilla Bug" field for this BZ's number, e.g. a search like:

"Bugzilla Bug" = 1234567

In the event you have trouble locating or viewing this issue, you can file an issue by sending mail to rh-issues. You can also visit https://access.redhat.com/articles/7032570 for general account information.

Comment 3 Red Hat Bugzilla 2024-10-05 04:25:35 UTC
The needinfo request[s] on this closed bug have been removed as they have been unresolved for 120 days


Note You need to log in before you can comment on or make changes to this bug.