1

My CouchDB view indexes are being created slower than I would like. Writing the documents is not such a problem but the users can edit them offline and then bulk update, which seems to slow things right down.

This answer helped but I was just wondering is it better to separate out various views into different design documents (eg1) or to store them all in one (eg2).

    Eg. 1
    _design/posts/_view/id
    _design/comments/_view/id
    _design/tags/_view/id



    Eg.2
    _design/webresources/_view/_id?key="posts"
    _design/webresources/_view/_id?key="comments"
    _design/webresources/_view/_id?key="tags"

*This example is just for illustration purposes. I am only concerned with the time it takes to build the indexes.

Community
  • 1
  • 1
brianf
  • 505
  • 5
  • 11

1 Answers1

0

You will gain better performance if you read often. Couchdb views are updated and build at read time. So you can can read the view every time the document updates to keep it hot*.

Or maybe listen to the changes feed and keep a track of documents updated. Once they reach a certain threshold value read a view.

Another option is use stale parameter.

If stale=ok is set, CouchDB will not refresh the view even if it is stale, the benefit is a an improved query latency. If stale=update_after is set, CouchDB will update the view after the stale result is returned

Every design document is a separate erlang process. So separating your views across different design documents will cause them to be built concurrently. However each view will still be built in a blocking manner. That is the two views across different design documents can start updating at the same time but the time it takes to update the individual views will be the same as if they were in the same design document.

*You don't necessarily have to care about the result. Our goal here is to trick couchdb to update the view. So you can fire off a request in a separate async process and be done with it.

Akshat Jiwan Sharma
  • 15,430
  • 13
  • 50
  • 60
  • Thanks. So essentially it makes no difference whether they are all packed into the one design doc or spread out over multiple? The problem is arising when I perform a bulk update on many docs. I suppose I could change my bulk update of all files to update the docs in segments and perform a read after each update – brianf Jul 02 '14 at 09:17
  • "I suppose I could change my bulk update of all files to update the docs in segments and perform a read after each update" - yes this is a good strategy. "So essentially it makes no difference whether they are all packed into the one design doc or spread out over multiple?" - It does make a difference. If you have views spread out they will be in a separate concurrent process. Will Holley gave a [great answer](http://stackoverflow.com/questions/20789356/couchdb-views-and-design-documents/20835978#20835978) here. Check it out. – Akshat Jiwan Sharma Jul 02 '14 at 09:35