How do you Schedule Index Updates in CouchDB

Jonathan Tran picture Jonathan Tran · Sep 23, 2008 · Viewed 7.2k times · Source

As far as I understand, CouchDB indexes are updated when a view is queried. Assuming there are more reads than writes, isn't this bad for scaling? How would I configure CouchDB to update indexes on writes, or better yet, on a schedule?

Answer

Paul J. Davis picture Paul J. Davis · Sep 23, 2008

CouchDB does regenerate views on update, but only on what has changed since the last read access to the view. Assuming your read volume greatly outweighs your write volume, this shouldn't be a problem.

When you're changing large numbers of documents at once this could lead to the possibility of the first read requests taking a noticeable amount of time. To alleviate this a few different possibilities have been suggested. Most rely on registering with CouchDB's update notifications and triggering reads automatically.

An example script for doing exactly that is available on the CouchDB wiki at [1].

[1] http://wiki.apache.org/couchdb/RegeneratingViewsOnUpdate