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

Parallelize scrubbing a single model #13

Merged
merged 2 commits into from
Jun 12, 2019

Conversation

adamstegman
Copy link
Member

@adamstegman adamstegman commented Jun 11, 2019

When a table has tens of millions of records, scrubbing it can take a long time. I added a rake task to parallelize that task so it can go much faster.

I'm assuming the model has an ID column, which may not always be true. For now, this felt good enough. We can always add another PR!

I arbitrarily chose 256 as the number of batches; in my testing it didn't really help to go up or down from there. I'm working on getting a larger data set to test with, though, so I may update that.

I wasn't able to add tests for this—the NullDB adapter doesn't allow you to actually find records. I just tested it on a real application.

When a table has tens of millions of records, scrubbing it can take a long time.
I added a rake task to parallelize that task so it can go much faster.
I'm assuming the model has an ID column, which may not always be true.

[#166599401]
# if the ENV variable is set

unless ENV["SCRUB_CLASSES"].blank?
if ENV["SCRUB_CLASSES"].present?

Choose a reason for hiding this comment

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

💯


# create even ID ranges for the table
def id_ranges_for(ar_class:, count:)
last_id = 2147483647 # naive maximum ID value for sorting

Choose a reason for hiding this comment

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

2^31-1 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I pulled this from the MySQL docs. Like the comment says, naive, because it depends on the data type and the database server. If we find a way to discover that information, we can add it in another PR.

lib/acts_as_scrubbable/parallel_table_scrubber.rb Outdated Show resolved Hide resolved
lib/acts_as_scrubbable/parallel_table_scrubber.rb Outdated Show resolved Hide resolved
lib/acts_as_scrubbable/parallel_table_scrubber.rb Outdated Show resolved Hide resolved
answer = ask("Type '#{db_host}' to continue. \n".red + '-> '.white)
unless answer == db_host
@logger.error "exiting ...".red
exit

Choose a reason for hiding this comment

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

Do we want this rake task to be chainable? exit breaks chaining ☹️

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 an error case, so probably not.

lib/acts_as_scrubbable/tasks.rb Outdated Show resolved Hide resolved
@adamstegman adamstegman merged commit 577bc8b into master Jun 12, 2019
@adamstegman adamstegman deleted the chore/166599401-parallel-one branch June 12, 2019 15:29
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.

5 participants