Bug 2226567

Summary: Slow "Katello::Applicability::Hosts::BulkGenerate" task when the host has many installed modular packages
Product: Red Hat Satellite Reporter: Hao Chang Yu <hyu>
Component: Errata ManagementAssignee: satellite6-bugs <satellite6-bugs>
Status: CLOSED DUPLICATE QA Contact: Satellite QE Team <sat-qe-bz-list>
Severity: high Docs Contact:
Priority: high    
Version: 6.13.3CC: ahumbe, jlenz, rlavi
Target Milestone: UnspecifiedKeywords: Performance, Regression, Triaged, UserExperience
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-10-20 15:24:29 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Hao Chang Yu 2023-07-26 01:12:58 UTC
Description of problem:
The calculation of errata applicability takes long time to complete. It will take 5 to 10 minutes to calculate if the host has thousands of installed modular packages.


How reproducible:
Easy

Steps to Reproduce:
1. Prepare a RHEL 8 client and register it to the Satellite.
2. Enable the appstream repository.
3. Enable and install as many module streams as possible.
4. After that force upload the package profile to the Satellite to trigger the  "Katello::Applicability::Hosts::BulkGenerate" task.


Actual results:
~~~
Label: Actions::Katello::Applicability::Hosts::BulkGenerate
Status: stopped
Result: success
...
2: Actions::Katello::Applicability::Hosts::BulkGenerate (success) [ 193.02s / 193.02s ]

Queue: hosts_queue
Started at: 2023-07-05 00:14:14 UTC
Ended at: 2023-07-05 00:17:27 UTC
Real time: 193.02s
Execution time (excluding suspended state): 193.02s
~~~

Expected results:
should at least take second to complete.

Additional info:

We can use the following rake script to test the peformance.
~~~
cat << EOF | foreman-rake console
cf = Host.find(XXXX).content_facet
bound_repos = cf.bound_repositories.collect {|repo| repo.library_instance_id.nil? ? repo.id : repo.library_instance_id}
helper = Katello::Applicability::ApplicableContentHelper.new(cf, ::Katello::Rpm, bound_repos)
helper.fetch_enabled_module_stream_ids.size
Benchmark.measure {p helper.locked_modular_installed_packages(helper.fetch_enabled_module_stream_ids).size}
EOF
~~~

Example output of the rake
~~~
...
helper.fetch_enabled_module_stream_ids.size
442
Benchmark.measure {p helper.locked_modular_installed_packages(helper.fetch_enabled_module_stream_ids).size}
3021
#<Benchmark::Tms:0x0000000014c0e4a0 @label="", @real=114.56473832399934, @cstime=0.0, @cutime=0.0, @stime=0.017389999999998906, @utime=1.518035999999995, @total=1.535425999999994>
~~~