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

Improve opds2_feed_reaper performance for large feeds. (PP-1756) #2089

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tdilauro
Copy link
Contributor

@tdilauro tdilauro commented Sep 26, 2024

Description

Makes memory use and database query size more predictable for the opds2_feed_reaper script.

Motivation and Context

The previous approach could not support very large feeds (somewhere over 150K items) and performed poorly on even smaller feeds than that.

[Jira PP-1756]

How Has This Been Tested?

  • Tested in local dev environment database from dev server.

Checklist

  • N/A - I have updated the documentation accordingly.
  • All new and existing tests passed.

Copy link

codecov bot commented Sep 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.78%. Comparing base (344383b) to head (7742eb4).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2089      +/-   ##
==========================================
+ Coverage   90.67%   90.78%   +0.10%     
==========================================
  Files         344      344              
  Lines       40585    40580       -5     
  Branches     6583     8819    +2236     
==========================================
+ Hits        36801    36839      +38     
+ Misses       2506     2484      -22     
+ Partials     1278     1257      -21     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines -136 to -138
to_be_reaped_qu = unlimited_access_license_pools_qu.join(Identifier).filter(
~Identifier.id.in_(identifier_ids)
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The key change starts here. We remove this join, which scaled poorly because the SELECT grew linearly with the number of identifiers in the feed.

The other part of this change is below, where we iterate over all eligible license pools locally and reap the ones that are not mentioned in the feed.

Comment on lines 153 to 160
for pool in eligible_license_pools_qu.options(raiseload("*")).yield_per(
query_batch_size
):
if pool.identifier_id not in identifier_ids:
reap_count += 1
# Don't actually reap, unless this is explicitly NOT a dry run.
if self.dry_run is False:
pool.unlimited_access = False
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the second part of the main change here, where we iterate over all eligible license pools locally and reap the ones that are not mentioned in the feed.

Copy link
Member

@jonathangreen jonathangreen left a comment

Choose a reason for hiding this comment

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

Looks good

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

Successfully merging this pull request may close these issues.

2 participants