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

Use iterator() when rehashing to save memory #4139

Merged
merged 1 commit into from
Jul 12, 2023
Merged

Conversation

nllong
Copy link
Member

@nllong nllong commented Jul 12, 2023

Any background context you want to provide?

The 0200_rehash migration was failing due to memory pressure when migrating the production database with over 14E6 states.

What's this PR do?

Convert the .all() call to .all().iterator() to prevent all records from returing at one time, rather force a database iterator.

This migration still takes a long time to run--around 10 hours. We might need to parallalize this in the future.

How should this be manually tested?

If CI passes, then there are no syntax errors. The PR does not change the core functionality.

What are the relevant tickets?

n/a

Screenshots (if appropriate)

@github-actions
Copy link

Label error. Requires at least 1 of: Feature, Bug, Enhancement, Maintenance, Documentation, Performance, Do not publish. Found:


for state in property_states:
print(f"Re-hashing {property_count} Property States ")
for idx, state in enumerate(PropertyState.objects.all().iterator()):
Copy link
Member Author

Choose a reason for hiding this comment

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

this is the only real change

@nllong nllong added the Bug label Jul 12, 2023
Copy link
Contributor

@perryr16 perryr16 left a comment

Choose a reason for hiding this comment

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

Between count() and iterator() this seems like a simple way to reduce memory usage

@nllong
Copy link
Member Author

nllong commented Jul 12, 2023

Between count() and iterator() this seems like a simple way to reduce memory usage

yeah, I think the memory pressure probably started with the len(PropertyState.objects.all()... because it would need to load the .all() to calculate len

@nllong nllong merged commit e7a3563 into develop Jul 12, 2023
7 of 8 checks passed
@nllong nllong deleted the fix-rehash-memory branch July 12, 2023 19:51
dhaley pushed a commit that referenced this pull request Jul 21, 2023
use iterator() when going through all the states to save memory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants