【问题标题】:Couchbase bulk retrieving multiple keys in JavaCouchbase 批量检索 Java 中的多个键
【发布时间】:2015-04-03 02:31:22
【问题描述】:

在 couchbase 中,假设一个文档有一个字段,其中包含一组引用其他文档的键

{
    "some_ids": ["otherdoc1", "otherdoc2", "otherdoc3"]
}

这两种用于检索some_ids 字段中的所有文档的解决方案中哪一种具有最佳性能?

  1. Batching with RxJava

    List<JsonDocument> foundDocs = Observable
    .just("otherdoc1", "otherdoc2", "otherdoc3")
    .flatMap(new Func1<String, Observable<JsonDocument>>() {
        @Override
        public Observable<JsonDocument> call(String id) {
            return bucket.async().get(id);
        }
    })
    .toList()
    .toBlocking()
    .single();
    
  2. 创建一个设计视图,然后使用startKeyendKey 检索其索引的子集

    // Map function
    function(doc, meta) {
        if (doc.type == 'otherdoc') {
            emit(meta.id, doc);
        }
    }
    
    // ViewQuery (in a java method)
    ViewQuery.from('designOther', 'viewOther')
      .startKey('otherdoc1')
      .endKey('otherdoc2');
    

【问题讨论】:

    标签: java couchbase rx-java


    【解决方案1】:

    在 Couchbase 中,当您知道密钥时,SDK 就知道向哪个节点请求该密钥(通过散列)。另一方面,查询视图意味着视图引擎要联系集群中的每个节点。

    因此,在 RxJava 中直接获取 && 批处理,因为您知道密钥,因此可以节省额外的往返次数,并且最终会获得更好的性能!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多