CouchDB Views - List function performance hit?

谁都会走 提交于 2019-12-13 14:27:51

问题


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


回答1:


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.




回答2:


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 '/^]}/]/'



来源:https://stackoverflow.com/questions/3636594/couchdb-views-list-function-performance-hit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!