【问题标题】:Ignite/GridGain putAllIfAbsent点燃/GridGain putAllIfAbsent
【发布时间】:2021-06-04 06:24:59
【问题描述】:

我使用 GridGain 作为我的持久性数据库。我有以下要求。

  1. 如果键不存在则插入多条记录
  2. 如果 key 存在或不存在,则放置多条记录。

对于 1,我看到 cache.putIfAbsent(key, value) 方法在不存在时插入单个记录。但是我没有找到cache.putAllIfAbsent(Map<key, value>) 这样的方法。我可以循环以一一插入多条记录。是否存在性能问题?

对于2,我想我可以使用cache.putAll(Map<key, value>) 方法。如果方法合适?

我在谷歌云 Kubernetes 引擎中作为胖客户端运行服务器。

【问题讨论】:

    标签: ignite gridgain


    【解决方案1】:
    • putAll 总是覆盖现有记录
    • 循环中的putIfAbsent 会比putAll 慢。衡量您的具体用例以了解多少

    如果对排序和原子性没有要求,DataStreamer 是一个不错的选择。当allowOverwrite 标志为假(默认)时,您将获得putIfAbsent 行为和良好的性能。

    try (IgniteDataStreamer<Integer, String> stmr = ignite.dataStreamer("myCache")) {    
        stmr.allowOverwrite(false); // Don't overwrite existing data
    
        Map<Integer, String> entries = getMydata()
        stmr.addData(entries);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-22
      • 1970-01-01
      • 2020-09-27
      • 2015-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多