Greetings,I have been working with a Hazelcast cluster for about a year now and I am having some performance issues that I am trying to address. I understand that when an object is on a remote node serialization must occur if I try to get it from an IMap. What I dont really get is why the local entry set has to be serialized.
Why isn't it possible to have those objects available as objects, as any other object in a hash map for that matter, in the local environment without breaking the paradigm. The need to serialize anything and everything out of hazelcast is presenting a huge problem in performance as I have some large objects in the map. In fact its almost at a level where RDBMS access to partial objects is preferable from the point of view of performance.
So I am wondering perhaps I am doing something wrong? Is there any way to configure an IMap so that entries are not serialized to or from the map if accessed on the owner of the partition? I know that you can use Object format and an entry processor to access objects but the problems with that paradigm are extensive. 1) we are choking executors with hundreds of thousands of calls.
2) Entry processors are EXTREMELY limited in that they cant access other maps so any kind of composite operation, which constitute the bulk of our use cases, is impossible in an EP.
We moved from DB direct to Hazelcast cache to get performance increases but frankly I have not seen the performance increase I expected to see.I would appreciate any constructive guidance on this issue.
--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at http://groups.google.com/group/hazelcast.
To view this discussion on the web visit https://groups.google.com/d/msgid/hazelcast/ca97196b-6cf1-4e38-84c8-d2facc9185ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
NearCacheConfig nearCacheConfig = new NearCacheConfig();
nearCacheConfig.setCacheLocalEntries(true);
nearCacheConfig.setInvalidateOnChange(true);
nearCacheConfig.setInMemoryFormat(InMemoryFormat.OBJECT);
mapConfig.setNearCacheConfig(nearCacheConfig);OBJECT: The data will be stored in deserialized form. This configuration is good for maps where entry processing and queries form the majority of all operations and the objects are complex ones, making the serialization cost respectively high. By storing objects, entry processing will not contain the deserialization cost.
package com.nm.test.hazelcast.nearcache;
import com.hazelcast.config.*;import com.hazelcast.core.Hazelcast;import com.hazelcast.core.HazelcastInstance;import com.hazelcast.core.IMap;import com.nm.test.hazelcast.TestHazelcast;import com.nm.test.hazelcast.utils.TestValue;import org.apache.log4j.BasicConfigurator;import org.apache.log4j.Logger;import junit.framework.TestCase;
public class TestLocalNearCache3 extends TestCase {
private static final Logger logger = Logger.getLogger(TestLocalNearCache3.class);
private static final String mapName = "testMap" + TestLocalNearCache3.class.getSimpleName();
@Override protected void setUp() throws Exception {
// configure logging if (!TestHazelcast.loggingInitialized) { TestHazelcast.loggingInitialized = true; BasicConfigurator.configure(); } }
public void testGet() {
// create config Config config = new XmlConfigBuilder().build(); config.setProperty("hazelcast.logging.type", "log4j");
// configure map MapConfig mapConfig = config.getMapConfig(mapName);
// configure near cache NearCacheConfig nearCacheConfig = new NearCacheConfig(); nearCacheConfig.setEvictionPolicy("NONE"); nearCacheConfig.setInMemoryFormat(InMemoryFormat.OBJECT); nearCacheConfig.setCacheLocalEntries(true); mapConfig.setNearCacheConfig(nearCacheConfig);
// disable multicast for faster startup config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
// disable version check on start-up config.setProperty("hazelcast.version.check.enabled", "false");
// create Hazelcast instance HazelcastInstance hcInstance = Hazelcast.newHazelcastInstance(config);
// try-finally to ensure hazelcast is stopped try {
// get map IMap<String, TestValue> map = hcInstance.getMap(mapName);
// add map entry String key = "key1"; TestValue value = new TestValue("value1"); map.put(key, value);
// get map entry // - count number of read data int countRead0 = TestValue.getNumReadData(); map.get(key); int countRead1 = TestValue.getNumReadData();
// ensure only one readData() call assertTrue("readData() called not exactly one times (" + countRead0 + " -> " + countRead1 + ")", countRead0 + 1 == countRead1);
// get map entry again map.get(key); int countRead2 = TestValue.getNumReadData();
// ensure still only one readData() call assertTrue("readData() called not exactly one times (" + countRead0 + " -> " + countRead2 + ")", countRead0 + 1 == countRead2);
} finally { hcInstance.getLifecycleService().terminate(); }
logger.info("testGet() done."); }
}
package com.nm.test.hazelcast.utils;
import com.hazelcast.nio.ObjectDataInput;import com.hazelcast.nio.ObjectDataOutput;import com.hazelcast.nio.serialization.DataSerializable;import java.io.IOException;import java.util.concurrent.atomic.AtomicInteger;
/** * A test value which counts read and write data calls. */public class TestValue implements DataSerializable {
private static AtomicInteger numWriteData = new AtomicInteger();
private static AtomicInteger numReadData = new AtomicInteger();
public static int getNumWriteData() { return numWriteData.get(); }
public static int getNumReadData() { return numReadData.get(); }
private String value;
/* * protected constructor for deserialization */ TestValue() { }
public TestValue(String value) { this.value = value; }
public String getValue() { return value; }
@Override public void writeData(ObjectDataOutput out) throws IOException { out.writeUTF(value);
// count numWriteData.incrementAndGet(); }
@Override public void readData(ObjectDataInput in) throws IOException { value = in.readUTF();
// count numReadData.incrementAndGet(); }
}