Zach Smith
Zach Smith

Reputation: 8961

Can you estimate build time of CouchDB JavaScript views?

I have a very simple view to test indexing a CouchDB database with around 44 million documents. The view looks like this:

function(doc) {
  if (doc.type_) { // I added a type_ property to each doc
    emit(doc.type_, 1);
  };
};

And the results of this (using the _count reduce function) are:

+---+----------+
| a |   154716 |
| b |   162353 |
| c |   170626 |
| d |   180893 |
| e |     7590 |
| f |     8419 |
| g | 44420508 |
+---+----------+

I'm using CouchDB 2.1 on Windows 10 (Surface Pro i7) and the indexing took about 3 hours in total (I turned the computer off and on during the indexing, but I assume that this didn't require the index to be rebuilt from scratch).

The view as written above will have to 'touch' every document in the database. Considering this, how can I make some kind of qualitative estimate on how a more complex view will perform?

i.e. since an index is already touching every document in the database, would doing some manipulation of every document's properties greatly effect performance?

It seems to me that it wouldn't - that time would still be measured as O(n)ish. Is that correct?

In that case I should be able to estimate that a view-index that touches every doc should take around the same amount of time as the simple view I wrote above, +/-

  1. An allowance for how long it would take to do a linear scan of each document for the 'type_' property (so documents with more properties would increase index-build time)
  2. An allowance for how many steps the 'emit' function call requires; each of which would require linear scans of document objects and other calculations. i.e. longer documents == longer index-build times.

Upvotes: 1

Views: 46

Answers (0)

Related Questions