Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the performance of CouchDB's stale=update_after?

I'm curious about how the stale=update_after feature of the CouchDB view API works.

I can see here that it returns stale results and then updates the view:

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. update_after was added in version 1.1.0.

Assume that I have inserted some large number of documents -- enough to require several minutes to update the view index -- and then I query the view twice in rapid succession with stale=update_after. The first query will return very quickly; that's the whole point of update_after.

My question is, will the 2nd query also return stale results quickly, or will it wait for the view to finish updating?

like image 698
Mark E. Haase Avatar asked Sep 24 '12 01:09

Mark E. Haase


People also ask

What is the maximum number of views a document can have CouchDB?

The default value for many OSes is 1024 or 4096. On a system with many databases or many views, CouchDB can very rapidly hit this limit.

What are views in CouchDB?

Basically views are JavaScript codes which will be put in a document inside the database that they operate on. This special document is called Design document in CouchDB. Each Design document can implement multiple view. Please consult Official CouchDB Design Documents to learn more about how to write view.


1 Answers

The second query also returns stale results. It uses the partial results that are available at the time the query hits the server. If you just added documents, you're fine.

But if you have modified your view, the first query will return the results of the first query and trigger a complete rebuild of the view. So the second query will probably deliver no results or just very few rows.

So the short answer: In your case, both queries will return quickly, with the second query probably giving the same result as the first one, maybe with some additional rows.

Hope I could help!

Yours, Bernhard

like image 81
Bernhard Gschwantner Avatar answered Sep 18 '22 14:09

Bernhard Gschwantner