首页 > 解决方案 > 在慢速网络上从 Ignite 缓存中读取所有键值对需要很长时间

问题描述

我正在从已创建的具有 1M 键值对的 Ignite 缓存中读取所有行。当我从运行 ignite 集群的同一网络读取它时,大约需要 20 秒。但是,当我从运行 ignite 集群的网络之外的机器上读取它时,需要 10 分钟。整个缓存的大小约为 100 MB。我尝试通过传输大小为 100MB 的文件来测试 ignite 集群网络和外部网络之间的带宽。只用了5秒钟。我想知道为什么 Ignite 需要 600 秒才能从缓存中传输所有键值对?

//缓存配置

CacheConfiguration<BenchmarkCacheStoreKey, OptionalDouble> cfg = new CacheConfiguration<BenchmarkCacheStoreKey, OptionalDouble>();
cfg.setName(cacheName);
cfg.setCacheMode(CacheMode.PARTITIONED);
//1 backup of each cache
cfg.setBackups(1);
cfg.setStatisticsEnabled(true);
cfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
cfg.setGroupName(CACHE_GROUP_NAME);
cfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
//do not blockk read/write for cache rebalancing
cfg.setRebalanceMode(CacheRebalanceMode.ASYNC);

从下面的缓存中读取的逻辑:

Map<K, V> readMap = new HashMap<>();
IgniteCache cache = ignite.cache(cacheName)
cache.forEach(action ->readMap.put(action.getKey(), action.getValue()));

标签: ignite

解决方案


尝试将文件拆分为 1M 部分,然后按部分再次传输。我想这次你会得到类似于 10 分钟的结果。

cache.forEach(action ->readMap.put(action.getKey(), action.getValue()));

forEach 做扫描查询,默认扫描查询的页面大小== 1024,你可以尝试增加它,它会增加批处理大小,你可以这样做:

cache.query(new ScanQuery<>().setPageSize(10_240));

这是一个集群解决方案,所有默认配置都配置为在同一个网络中工作,所以如果您的网络不好并且在与服务器不同的集群中运行客户端,那么您可能需要对其进行调整。但是,与其将数据移动到客户端,不如将计算任务发送到服务器并在可能的情况下将一些小结果返回给客户端。


推荐阅读