Last active
August 21, 2019 12:28
-
-
Save pat/53dbe982a2b311f5f7294809109419d2 to your computer and use it in GitHub Desktop.
Thinking Sphinx parallel processing of real-time indices.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This will process each real-time index in parallel (using separate | |
# processes, up to the number of CPUs available). | |
# | |
# You will also need the 'parallel' gem, and what is currently the | |
# edge release of Thinking Sphinx (until there's been a release after | |
# v4.3.2). | |
# | |
# This could all go in an initialiser, or put the class wherever you | |
# like, and the assignment in the initialiser. | |
class ParallelProcessor < ThinkingSphinx::RealTime::Processor | |
def call(&block) | |
Parallel.map(indices) do |index| | |
puts "Populating index #{index.name}" | |
ThinkingSphinx::RealTime.populator.populate index | |
puts "Populated index #{index.name}" | |
block.call | |
end | |
end | |
end | |
ThinkingSphinx::RealTime.processor = ParallelProcessor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment