Couchdb Mango 性能与 Map Reduce Views

Couchdb Mango Performance vs Map Reduce Views

我刚刚注意到在 Couchdb 2.0 的 the release notes 中,提到新应用程序推荐使用 Mango 查询。还提到显然 Mango 索引比 javascript 查询快 2 到 x10,这真的让我感到惊讶,因此我有很多问题:

We recommend all new apps start using Mango as a default.

我主要追求的一方面是对 Mango 的一些见解,另一方面是对 Mango 和 Map/Reduce 在 2.x 时代应该如何共存的概述.

我最近尝试将我的应用程序切换为使用 Mango 查询,结果完全废弃并切换回 map/reduce。以下是我的一些理由:

  1. Mango 在处理未准确指定要使用的索引的查询时存在错误。上周末这个让我发疯了一段时间。如果您不指定索引,有时会 select 编辑一个备用索引并且 return 没有(或不正确的)结果。
  2. Mango 的表现不是'magic'。许多类型的查询最终将在内存搜索中进行。 Couch 将 select 最适合的索引,然后遍历内存中的所有记录以适应极端情况。 Cloudant 通过说使用基于 'text' 的搜索来解决其中一些问题,这在 Couchdb 中不可用。
  3. 正如您所指出的,Mango 搜索根本无法很好地处理某些类型的查询结构。我不认为我的应用程序过于复杂,但我 运行 遇到了几种情况,在这些情况下我无法为手头的任务构建合适的 Mango 查询。这里的一个主要问题是搜索数组以查找标签(例如,搜索以查看哪些用户是某个组的成员)。 Mango 无法索引数组元素,因此求助于在内存中进行全面扫描。
  4. 视图具有一些非常强大的功能,可以运行以列表形式形成搜索结果。这在 Mango 中不存在。

你的里程可能会有所不同,但只是想留下一个警告,这仍然是相当新的功能。

我是 Mango 和 CouchDB 的新手,但我想我可以提供一些见解。一旦您的 index/view 更新,Mango 并没有变得更快。 Mango 的巨大性能提升是在您第一次创建索引时,因为 couch 不需要为此创建单独的 couchjs 进程。

我发现即使您的某些文档很大,Mango 也能正常工作。当前使用 CouchDB 2.0.0,至少使用 windows,大型文档会使使用 Map/Reduce 的 couchjs.exe 视图服务器崩溃。 CouchDB 1.6.1 不是这种情况,并且已经在开发版本中修复 https://github.com/apache/couchdb-couch/commit/1659fda5dd1808f55946a637fc26c73913b57e96

核心开发人员的回答:

Some good questions. I don't think Mango will ever replace Map/Reduce completely. It is an alternative querying tool. What is great about the Mango query syntax is that it is a lot easier to understand and get started. And we can use it in a lot of places outside of just querying for documents. It can be used for replication filtering and the changes feed. We hope to soon have support for validation doc updates as well.

Underneath Mango is using erlang map/reduce. Which means it is creating a B-tree index just like map/reduce. What makes it faster is that it is using erlang/native functions to create the B-Tree instead of javascript. I wrote a blog post a long time ago about the internals of PouchDB-find [1] which is the mango syntax for PouchDB. It might help you understand a little more how the internals work. The key thing to understand is that there is a Map query part which uses the B-Tree and an in-memory filter. Ideally the less memory filtering you do the faster your query will be.

I would say that Mango is very much a work in process but the basic ground work is done. There are definitely things we can improve on. I've seen it used quite a bit when developers start a new project because its quick and simple to do basic querying, like find by email address or find all users with the name "John Rambo".

Hope that helps.

[1] http://www.redcometlabs.com/blog/2015/12/1/a-look-under-the-covers-of-pouchdb-find