具有 OutOfMemoryError 的 Apache Ignite Grid 计算的最佳配置是什么?
What is the good configuration for Apache Ignite Grid computing with an OutOfMemoryError?
我想使用 Apache Ignite 的网格计算功能,但是当我 运行 我的程序在两个节点上时,Java 堆 space (OutOfMemoryError) 出现问题.为了说明这个问题,我提出了一个简单的程序来计算字符串中的单词数:
try (Ignite ignite = Ignition.start("C:/Apache-Ignite/config/test-config.xml")) {
IgniteCompute compute = ignite.compute();
String[] elements = "Count characters using callable".repeat(10000).split(" ");
Collection<IgniteCallable<Integer>> calls = new ArrayList<>();
Arrays.stream(elements).forEach(word -> calls.add((IgniteCallable<Integer>) word::length));
IgniteReducer<Integer, Integer> reducer = new IgniteReducer<>() {
private Integer sum = 0;
@Override
public boolean collect(Integer integer) {
sum += integer;
return true;
}
@Override
public Integer reduce() {
return sum;
}
};
IgniteFuture<Integer> result = compute.callAsync(calls, reducer);
System.out.println("Result : " + result.get());
}
和测试-config.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="peerClassLoadingEnabled" value="true"/>
<property name="dataStorageConfiguration">
<bean class="org.apache.ignite.configuration.DataStorageConfiguration">
<!-- Redefining the default region's settings -->
<property name="defaultDataRegionConfiguration">
<bean class="org.apache.ignite.configuration.DataRegionConfiguration">
<property name="name" value="Default_Region"/>
<!-- Initial size. -->
<property name="initialSize" value="#{2L * 1024 * 1024 * 1024}"/>
<!-- Maximum size. -->
<property name="maxSize" value="#{2L * 1024 * 1024 * 1024}"/>
</bean>
</property>
</bean>
</property>
</bean>
</beans>
enter image description here
当我在程序执行过程中观察堆时,我们可以清楚地看到堆达到了他的极限。也许垃圾收集器被锁定了,但我不知道。
此外,如果我 运行 我的程序在我的单个本地节点上(以 Ignition.start("...")
开头),我没有任何问题。
我刚刚重试了您的案例,callAsync()
性能似乎随着 calls.size()
超过 5000 而逐渐变差。
在你的情况下它是 ~40000 所以你不会看到这个调用的完成,即使它不会导致 OOM。
请确保将您的计算分成约 1000 次调用的批次。实际上建议计算工作是大量的,在你的情况下,无论如何你将花费 99% 的资源来编组工作及其参数。
尽管如此,我会就此行为提交罚单。
我想使用 Apache Ignite 的网格计算功能,但是当我 运行 我的程序在两个节点上时,Java 堆 space (OutOfMemoryError) 出现问题.为了说明这个问题,我提出了一个简单的程序来计算字符串中的单词数:
try (Ignite ignite = Ignition.start("C:/Apache-Ignite/config/test-config.xml")) {
IgniteCompute compute = ignite.compute();
String[] elements = "Count characters using callable".repeat(10000).split(" ");
Collection<IgniteCallable<Integer>> calls = new ArrayList<>();
Arrays.stream(elements).forEach(word -> calls.add((IgniteCallable<Integer>) word::length));
IgniteReducer<Integer, Integer> reducer = new IgniteReducer<>() {
private Integer sum = 0;
@Override
public boolean collect(Integer integer) {
sum += integer;
return true;
}
@Override
public Integer reduce() {
return sum;
}
};
IgniteFuture<Integer> result = compute.callAsync(calls, reducer);
System.out.println("Result : " + result.get());
}
和测试-config.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="peerClassLoadingEnabled" value="true"/>
<property name="dataStorageConfiguration">
<bean class="org.apache.ignite.configuration.DataStorageConfiguration">
<!-- Redefining the default region's settings -->
<property name="defaultDataRegionConfiguration">
<bean class="org.apache.ignite.configuration.DataRegionConfiguration">
<property name="name" value="Default_Region"/>
<!-- Initial size. -->
<property name="initialSize" value="#{2L * 1024 * 1024 * 1024}"/>
<!-- Maximum size. -->
<property name="maxSize" value="#{2L * 1024 * 1024 * 1024}"/>
</bean>
</property>
</bean>
</property>
</bean>
</beans>
enter image description here
当我在程序执行过程中观察堆时,我们可以清楚地看到堆达到了他的极限。也许垃圾收集器被锁定了,但我不知道。
此外,如果我 运行 我的程序在我的单个本地节点上(以 Ignition.start("...")
开头),我没有任何问题。
我刚刚重试了您的案例,callAsync()
性能似乎随着 calls.size()
超过 5000 而逐渐变差。
在你的情况下它是 ~40000 所以你不会看到这个调用的完成,即使它不会导致 OOM。
请确保将您的计算分成约 1000 次调用的批次。实际上建议计算工作是大量的,在你的情况下,无论如何你将花费 99% 的资源来编组工作及其参数。
尽管如此,我会就此行为提交罚单。