For Faster Hazelcast Queries
Here some tips on improving hazelcast query performance:
1- Add indexes for queried fields. For queries with ranges (gt, lt, between) you can use ordered index.
IMap imap = Hazelcast.getMap("employees");
// ordered, since we have ranged queries for this field
imap.addIndex("age", true);
// not ordered, because boolean field cannot have range
imap.addIndex("active", false);
2- Set optimizeQuery = true, in map config. By enabling this flag, hazelcast will cache a deserialized (object) form, and use it when necessary. Disadvantage of this approach is memory overhead of cached object.
MapConfig mapConfig = config.getMapConfig(“mapName”);
mapConfig.setOptimizeQueries(true);
3- Object “in memory format”: By default hazelcast stores objects in their serialized form. This is an optimization: an extra serialisation step is skipped for remote operations. But if the majority of a map’s operations is query; then you can consider changing in-memory-format to object. With object format, queries will be run on directly objects, getting rid of de-serialisation. Disadvantage of this approach: The remote get operations from this map will have a serialisation step.
MapConfig mapConfig = config.getMapConfig(“mapName”);
mapConfig.setInMemoryFormat(InMemoryFormat.OBJECT);
Note: If you use 3rd approach (in-memory-format=OBJECT) then no need for optimizeQuery setting (2nd one) because objects will be already stored in deserialized.