Using one bucket vs. many
The docs mention a few reasons why a popular logical 'model' or object class might need to go into its own bucket, '10.6.5. View Writing Best Practice'. For example having one bucket for the 'players' and another for the 'monsters' - as compared to putting them all in a single bucket with a jsonType:'player' or jsonType:'monster' in the document.
Once it's decided we have to have a separate bucket once for a model type, it might be easier from an architectural standpoint to simply repeat this pattern for all object types.
My question is, is there any *disadvantage* to separating every type of object into a different bucket? I.e. if there are say 10 models, would having 10 buckets be less performant than coalescing a subset of those into a single bucket, and using a 'jsonType' field to maintain type info? What about 50 models?
Or are there any other disadvantages, for example it's harder to calculate memory requirements?
Thank you
There are a few different aspects to this.
First, each bucket comes with a certain amount of overhead incurred for monitoring, housekeeping, etc. It's not a lot, but it is not something you'd want to take on with 50 separate buckets.
Second, buckets are used for resource controls and administration domains. This could be an advantage or a disadvantage. Does it help to dedicate a certain amount of memory to one model type over another, or is it better to let Couchbase Server try to keep the hottest working set possible over your entire dataset? On administration, do you want to backup/restore one bucket separate from others?
A third consideration is that of building views. You'll have to make your views minorly more complex by including an if() guard checking for datatype, but also if you have a high rate of change for one model over another, you'll be running that view mapper a lot for items that won't necessarily emit anything into the view. By design this is mostly background work, but it's work nonetheless.
Generally speaking, buckets are tied to applications. There are times to split things out, but not too many. I'd recommend just keeping to one bucket until you find you have a need to split things out.
That's great, thank you both for the insight.
One bucket for now, and will keep these points in mind.
Cachvico,
Bucket are similar to databases rather than tables. Depending on your hardware we would recommend some where from 2-4 buckets to 7-10 buckets.
If you take a look at the architecture, http://www.couchbase.com/docs/couchbase-manual-1.8/couchbase-architectur... you will see that for each bucket, an instance of the bucket engine (component) is created. Each bucket takes up a part of memory and it is managed independently. Using multiple buckets could lead to heavy CPU usage. So creating multiple buckets does have an impact on the system.
Given the power of Javascript map functions, multiple objects can be stored in the same bucket, and secondary indexes can be created on attributes for each document type.
Example:
function(doc, meta) {
if (doc.jsonType == "player") {
emit(doc.experience, doc);
}
}
More examples and information on views can be found here:
- http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-views-writi...
- http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-views-sampl...