Has anyone tried to use GridGain as a local cache replacement? With built in eviction and expiration policies, its very attractive.
What is the right way to configure GridGain as a local cache?
EDIT This is a sample configuration I used to run a simple micro benchmark on the GridGain local cache.
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();
}
It took around 16 seconds to do 1M synchronous puts (on my Core i7-2640M 2.8GHz laptop). I agree this is too simple a test, but still this is not the performance I was expecting. I was expecting around 1-2 seconds. Do I need to tweak the config to get some more juice out of the cache?
You can definitely configure GridGain as a local cache and take advantage of local transactions, evictions, and expiration policies.
Here is sample spring-based configuration that would do this:
<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>
You can start the above configuration as following:
$GRIDGAIN_HOME/bin/ggstart.bat path/to/config/file
As far as performance, the issue was fixed in GridGain 6.0.3. The code above executes in less than 1 second for me.