Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CouchDB Views and Design Documents

For CouchDB you can create multiple views and/or multiple design documents.

Is it better to group views in the same design document or keep each view to its own design document?

like image 995
Justin Cloud Avatar asked Jan 11 '23 14:01

Justin Cloud


1 Answers

Internally, views within each design document are managed together in a "view group". Each view group spawns a separate view server when accessed - i.e. if there are 8 view groups, you will have 8 JavaScript processes. This certainly has design and performance implications. From the CouchDB documentation,

View index rebuilds occur when one view from the same the view group (i.e. all the views defined within a single a design document) has been determined as needing a rebuild. For example, if you have a design document with different views, and you update the database, all three view indexes within the design document will be updated.

So, from a design/deployment perspective, you need to be aware that changing a single view will rebuild all of the other views within the design document. You can use this trick to build them in the background but it is still going to build all of the views in the group so is potentially expensive.

You can also use the view group-view server relationship to your advantage. For example, if you have a CPU with 8 cores you might have 8 view groups, 1 for each core, to improve parallelism.

like image 164
Will Holley Avatar answered Jan 29 '23 22:01

Will Holley