Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Fork of ts-resque-delta that limits rate of delta index population

License

Notifications You must be signed in to change notification settings

acumenbrands/ts-throttled-resque-delta

Repository files navigation

Delayed Deltas for Thinking Sphinx (with Resque)

Forked from ts-resque-delta to support throttling the rate of delta indexing.

This code is HEAVILY borrowed from ts-delayed-delta.

Installation

This gem depends on the following gems: thinking-sphinx, resque, resque-lock-timeout, and resque-throttle.

gem install ts-throttled-resque-delta

Add ts-throttled-resque-delta to your Gemfile file, with the rest of your gem dependencies:

gem 'ts-throttled-resque-delta', '~> 1.2.2'

If you're using Rails 3, the rake tasks will automatically be loaded by Rails. If you're using Rails 2, add the following line to your Rakefile:

require 'thinking_sphinx/deltas/resque_delta/tasks'

Add the delta property to each define_index block:

define_index do
  # ...
  set_property :delta => ThinkingSphinx::Deltas::ResqueDelta
end

If you've never used delta indexes before, you'll want to add the boolean column named :delta to each model's table (note, you must set the :default value to true):

def self.up
  add_column :foos, :delta, :boolean, :default => true, :null => false
end

Also, I highly recommend adding a MySQL index to the table of any model using delta indexes. The Sphinx indexer uses WHERE table.delta = 1 whenever the delta indexer runs and ... = 0 whenever the normal indexer runs. Having the MySQL index on the delta column will generally be a win:

def self.up
  # ...
  add_index :foos, :delta
end

Throttling

You can specify a maximum rate at which the delta indexing jobs will be run:

ThinkingSphinx::Deltas::ResqueDelta::DeltaJob = 30 # seconds

Usage

Once you've got it all set up, all you need to do is make sure that the Resque worker is running. You can do this by specifying the :ts_delta queue when running Resque:

QUEUE=ts_delta,other_queues rake resque:work

Additionally, ts-resque-delta will wrap thinking-sphinx's thinking_sphinx:index and thinking_sphinx:reindex tasks with thinking_sphinx:lock_deltas and thinking_sphinx:unlock_deltas. This will prevent the delta indexer from running at the same time as the main indexer.

Finally, ts-resque-delta also provides a rake task called thinking_sphinx:smart_index (or ts:si for short). This task, instead of locking all the delta indexes at once while the main indexer runs, will lock each delta index independently and sequentially. Thay way, your delta indexer can run while the main indexer is processing large core indexes.

Contributors (for ts-throttled-resque-delta)

Original Contributors (for ts-delayed-delta)

Copyright

Copyright (c) 2011 Aaron Gibralter, and released under an MIT Licence.

About

Fork of ts-resque-delta that limits rate of delta index population

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages