java - Ignite 性能:如何调整 ignite 瘦客户端的缓存写入性能?
问题描述
我正在做一个简单的 POC 来写入大量条目以在客户端服务器模式下点燃缓存,在测试期间观察到如下所示;
1) 如果瘦客户端和服务器位于同一主机上,将 100 万个条目持久保存到两个缓存中大约需要 10 分钟。
2)如果瘦客户端和服务器驻留在不同的主机上,大约需要 4 分钟才能将 500 个条目保存到两个缓存中。这看起来很糟糕。
即使我们考虑到一些网络延迟,我也无法证明 case2(我们希望采用的实现模式)中的这种显着延迟是合理的。我想知道它是否与我的缓存配置有关,如下所示?
<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="workDirectory" value="/path/"/>
<property name="activeOnStart" value="true"/>
<property name="autoActivationEnabled" value="true"/>
<property name="deploymentMode" value="SHARED"/>
<property name="igniteInstanceName" value="test"/>
<property name="dataStorageConfiguration">
<bean class="org.apache.ignite.configuration.DataStorageConfiguration">
<property name="defaultDataRegionConfiguration">
<bean class="org.apache.ignite.configuration.DataRegionConfiguration">
<property name="persistenceEnabled" value="true"/>
</bean>
</property>
<property name="storagePath" value="/path/"/>
</bean>
</property>
<!--
For better performance set this property to false in case
peer deployment is not used.
Default value is true.
-->
<property name="peerClassLoadingEnabled" value="false"/>
<property name="cacheConfiguration">
<!--
Specify list of cache configurations here. Any property from
CacheConfiguration interface can be configured here.
Note that absolutely all configuration properties are optional.
-->
<list>
<bean parent="cache-template">
<!-- Cache name is 'testcache1'. -->
<property name="name" value="testcache1"/>
</bean>
<bean parent="cache-template">
<!-- Cache name is 'testcache2'. -->
<property name="name" value="testcache2"/>
</bean>
</list>
</property>
</bean>
<!-- Template for all example cache configurations. -->
<bean id="cache-template" abstract="true" class="org.apache.ignite.configuration.CacheConfiguration">
<!-- REPLICATED cache mode. -->
<property name="cacheMode" value="REPLICATED"/>
<!-- Set synchronous rebalancing (default is asynchronous). -->
<property name="rebalanceMode" value="SYNC"/>
<!-- Set to FULL_SYNC for examples, default is PRIMARY_SYNC. -->
<property name="writeSynchronizationMode" value="FULL_SYNC"/>
<property name="atomicityMode" value="TRANSACTIONAL"/>
</bean>
瘦客户端代码:
公共类 IgniteDataGridApplication {
static DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
private ClientCache<String, String> testcache1;
private ClientCache<String, String> testcache2;
public IgniteDataGridApplication() {
ClientConfiguration cfg = new ClientConfiguration().setAddresses("serverhostname.net:10800");
IgniteClient ignite = Ignition.startClient(cfg);
testcache1 = ignite.cache("testcache1");
testcache2 = ignite.cache("testcache2");
}
public static void main(String[] args) throws Exception {
IgniteDataGridApplication igniteDataGridApplication = new IgniteDataGridApplication();
igniteDataGridApplication.load();
}
private void load() throws Exception {
List<ThreadProducer> cacheMessages = new ArrayList<>();
for (int i = 1; i <= 1000000; i++) {
String testentry = i+"";
cacheMessages.add(new ThreadProducer("testKey" + i, testentry));
}
ExecutorService executorService = Executors.newFixedThreadPool(1000);
cacheMessages.forEach(executorService::submit);
executorService.shutdown();
executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
}
class ThreadProducer implements Runnable {
private String String;
private String key;
public ThreadProducer(String key, String String) {
this.key = key;
this.String = String;
}
public void run() {
testcache1.putIfAbsent(key, String);
testcache2.putIfAbsent(key, String);
System.out.println("entry :: " + key + " :: " + sdf.format(Calendar.getInstance().getTime()));
}
}
}
解决方案
尝试使用 JFR、JProfiler 或您选择的其他分析器来分析服务器节点和瘦客户端,以找到减慢操作的瓶颈。
确保在这两种情况下,基线拓扑中存在相同数量的节点。如果基线拓扑数据配置不当,则可能仅将其加载到节点之一。
您可以尝试使用批量加载数据的 API 方法来提高性能。ClientCache#putAll()就是这样的方法之一。
推荐阅读
- azure-data-explorer - 用于分组 AppInsights 消息的 Kusto 查询
- javascript - 我想按类将 H2 - H5 标签替换为 P
- python - 使用 Python 在 SQL Server 2019 上创建随机用户
- flutter - 如何在颤振上创建带有圆角的方形头像?
- python - 全局关闭 Colorama 颜色代码
- linux - Xrandr 检测到但不连接 HDMI
- reactjs - 片段不在本地主机中呈现(第一个反应应用程序)
- php - 如何在php中解析xml子树
- python - Google 测试工具 API - MobileFriendlyTest Python 403 Forbidden
- python - 在 Python 中更新新列表时如何停止更新旧列表