dworrad
dworrad

Reputation: 719

CouchDB Views - List function performance hit?

As many of you will know the response from a couchdb view is as follows

{"rows":[
  {"key":"1","value":{"Col1":"Some Value"}},
  {"key":"2","value":{"Col1":"Another Value"}},
]}

Well I would like to collate that to

[{"key":"1","value":{"Col1":"Some Value"}},
  {"key":"2","value":{"Col1":"Another Value"}}]

I am considering using a "List Function" to collate the response but I wanted to know the potential performance overhead of doing something like this?? Is it worth it... or should I consider changing all my code to handle the different response??

Thanks Damo

Upvotes: 3

Views: 1331

Answers (2)

duomark
duomark

Reputation: 1

I use JSON_XS to format the result, then curl, awk and other unix utilities to reformat the result. In this case pretty-printing the JSON doesn't help so:

curl -s -S --compressed -X GET 'your_view_url' | sed -e '/^{"rows"://' -e '/^]}/]/'

Upvotes: 0

JasonSmith
JasonSmith

Reputation: 73722

A list function runs in a separate process (couchjs) which is connected to couchdb via standard i/o. Data is serialized to/from JSON to communicate with this channel. In other words, all of your rows will be serialized and sent to couchjs; and couchjs will send the results back.

Therefore, a list function will add (at least) an O(n) latency to receive your results. For small (I say less than 10,000 documents but it depends on your needs) view results, it is well worth the convenience. For very large amounts of rows, you may find benefit in upgrading your clients.

Upvotes: 5

Related Questions