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

IndexingScheduler: fetch and import in batches #24285

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions app/workers/scheduler/indexing_scheduler.rb
Expand Up @@ -6,17 +6,21 @@ class Scheduler::IndexingScheduler

sidekiq_options retry: 0

IMPORT_BATCH_SIZE = 1000
Copy link
Contributor

Choose a reason for hiding this comment

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

Wonder if this would make sense as a namespaced environment variable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe? Mastodon doesn't break out the majority of its limits and tuning constants, but I don't know if that's house style or what.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this kind of tuning is marginal enough to not warrant adding an environment variable. That can be revisited in the future if the need arises.

SCAN_BATCH_SIZE = 10 * IMPORT_BATCH_SIZE

def perform
return unless Chewy.enabled?

indexes.each do |type|
with_redis do |redis|
ids = redis.smembers("chewy:queue:#{type.name}")

type.import!(ids)

redis.pipelined do |pipeline|
ids.each { |id| pipeline.srem("chewy:queue:#{type.name}", id) }
redis.sscan_each("chewy:queue:#{type.name}", count: SCAN_BATCH_SIZE) do |ids|
redis.pipelined do
ids.each_slice(IMPORT_BATCH_SIZE) do |slice_ids|
type.import!(slice_ids)
redis.srem("chewy:queue:#{type.name}", slice_ids)
end
end
end
end
end
Expand Down