CouchDB视图:map reduce中可以接受多少处理? [英] CouchDB Views: How much processing is acceptable in map reduce?

查看:463
本文介绍了CouchDB视图:map reduce中可以接受多少处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用CouchDB Map Reduce。一些示例显示了map reduce函数中的一些可能很重的逻辑。



map reduce是在每个可能的文档发出所选文档之前运行的吗?



如果是这样,我认为这意味着在映射reduce函数内运行任何类型的迭代处理将会使处理负担增加一个数量级,至少。 / p>

基本上可以归结为以下问题:在map reduce之前可以执行多少逻辑,然后再执行不合理的查询

解决方案

CouchDB map-reduce中可以接受大量昂贵的处理。



CouchDB视图(map-reduce)更像 CREATE INDEX ,而不是 SELECT FROM



具体来说,CouchDB保证映射函数每个文档只运行一次



因此,假设你有一个10,000个文件,他们需要1秒每个进程(这是方式比我见过的更高)。这是10,000秒或2.8小时完全构建视图。但是一旦视图完成,查询任何行(?key = ... )或行切片(?startkey = ...& endkey = ... )与直接查询文档的时间相同。查找时间是文档计数的O(log n)。



换句话说,即使每个文档需要1秒执行地图,毫秒来获取结果。 (当然,视图必须首先构建,因为它实际上是一个索引。)


I've been toying around with Map Reduce with CouchDB. Some of the examples show some possibly heavy logic within the map reduce functions. In one particular case, they were performing for loops within map.

Is map reduce run on every single possible document before it emits your selected documents?

If so, I would think that means that running any kind of iterative processing within the map reduce functions would increase processing burden by an order of magnitude, at least.

Basically it boils down to the following question: how much logic can be performed within map reduce before its an unreasonably expensive query?

解决方案

Lots of expensive processing is acceptable in CouchDB map-reduce.

CouchDB views (map-reduce) are more like CREATE INDEX than they are SELECT FROM.

Specifically, CouchDB guarantees that a map function runs only once per document, ever. (Well, actually once per document change ever.) That is what the "iterative map-reduce" is.

Therefore, suppose you had 10,000 documents and they take 1 second each to process (which is way higher than I have ever seen). That is 10,000 seconds or 2.8 hours to completely build the view. However once the view is complete, querying any row (?key=...) or row slice (?startkey=...&endkey=...) takes the same time as querying for documents directly. Lookup time is O(log n) for the document count.

In other words, even if it takes 1 second per document to execute the map, it will take a few milliseconds to fetch the result. (Of course, the view must build first, since it is actually an index.)

这篇关于CouchDB视图:map reduce中可以接受多少处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆