有没有人试图将GridGain用作本地缓存替换?随着内置的驱逐和到期政策,它非常有吸引力。
将GridGain配置为本地缓存的正确方法是什么?
修改 这是我用于在GridGain本地缓存上运行简单微基准测试的示例配置。
final GridCacheConfiguration cfg = new GridCacheConfiguration();
cfg.setCacheMode(GridCacheMode.LOCAL);
cfg.setSwapEnabled(false);
cfg.setAtomicityMode(GridCacheAtomicityMode.ATOMIC);
cfg.setQueryIndexEnabled(false);
cfg.setBackups(0);
cfg.setStartSize(1000000);
cfg.setName("test");
final GridConfiguration gridConfiguration = new GridConfiguration();
gridConfiguration.setRestEnabled(false);
gridConfiguration.setMarshaller(new GridOptimizedMarshaller());
gridConfiguration.setCacheConfiguration(cfg);
try (final Grid grid = GridGain.start(gridConfiguration)){
final GridCache<String, String> test = grid.cache("test");
final String keyPrefix = "key";
final String valuePrefix = "value";
final LoggingStopWatch stopWatch = new LoggingStopWatch("cacheWrite - GRIDGAIN");
for (int i = 0; i < 1000000; i++) {
test.put(keyPrefix + i, valuePrefix + i);
}
stopWatch.stop();
} catch (GridException e) {
e.printStackTrace();
}
在我的Core i7-2640M 2.8GHz笔记本电脑上进行1M同步放置需要大约16秒。我同意这是一个太简单的测试,但这仍然不是我期望的表现。我期待大约1-2秒。我是否需要调整配置以从缓存中获取更多汁液?
答案 0 :(得分:0)
您绝对可以将GridGain配置为本地缓存,并利用本地事务,驱逐和过期策略。
以下是基于弹簧的示例配置:
<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-2.5.xsd">
<bean id="grid.cfg" class="org.gridgain.grid.GridConfiguration" scope="singleton">
<property name="cacheConfiguration">
<list>
<bean class="org.gridgain.grid.cache.GridCacheConfiguration">
<property name="name" value="myCache"/>
<property name="cacheMode" value="LOCAL"/>
<!-- Eviction policy. -->
<property name="evictionPolicy">
<bean class="org.gridgain.grid.cache.eviction.lru.GridCacheLruEvictionPolicy">
<property name="maxSize" value="10000"/>
</bean>
</property>
</bean>
</list>
</property>
</bean>
</beans>
您可以按照以下步骤开始上述配置:
$GRIDGAIN_HOME/bin/ggstart.bat path/to/config/file
就性能而言,GridGain 6.0.3中修复了该问题。上面的代码对我来说不到1秒钟。