Question
2
Replies
626
Views
Cts
Posted: September 25, 2018
Last activity: October 11, 2018
Cache in multiple node setup in Pega
Hi,
We have a cluster environment where we have multiple nodes in multiple physical servers. We want to maintain common cache across all nodes. If we have node level data page, it wont suite our requirement because it is per node. How can we achieve one single common cache across all pega nodes?
Thanks.
***Edited by Moderator Marissa to update platform capability tags****
For your information, Pega is leveraging internally Hazelcast which is an in-memory data grid which helps implementing a distributed cache.
So you could attempt to leverage this but this is custom. Pega doesn't provide out of the box hook on this.
You would have to use custom java code to use it.
Also with great power comes great responsibilities...If badly implemented, the distributed cache can create stuck threads on all nodes and you can end up in the whole cluster unavailable. In other words this can become a single point of failure.
Having said that, you would need to set the password for the hazelcast cluster with a prconfig setting like this:
<env name="identification/cluster/password" value="myPasswordHere"/>
You also need the Hazelcast cluster ID and I'm not sure where you find it out which it should be one value found in the "Cluster Management" landing page-> Download system state, you get a JSON file with a description of the cluster.
Then use some code like this (in an activity step) to connect to the cluster:
(Please note my code only tried to connect and inspect the cluster. To leverage Hazelcast you would need to check directly hazelcast documentation. Please also note I wrote this in a hurry at the time so forgive me if there is a better way.)
com.hazelcast.client.config.ClientConfig clientConfig = new com.hazelcast.client.config.ClientConfig();
java.lang.String hostname="notInitialized";
try{
oLog.infoForced("xav: hostname is"+Runtime.getRuntime().exec("hostname"));
java.net.InetAddress myHost = java.net.InetAddress.getLocalHost();
oLog.infoForced("xav: hostname 2 is"+myHost.getHostName());
hostname=myHost.getHostName();
}
catch(java.net.UnknownHostException e)
{
e.printStackTrace();
}
catch(java.io.IOException e)
{e.printStackTrace();
}
clientConfig.addAddress(hostname + ":" + "5701");
clientConfig.setGroupConfig(new com.hazelcast.config.GroupConfig("2ccdd07ce4d2e48814c61ccd29e3d778","yourpassword"));
com.hazelcast.core.HazelcastInstance.newHazelcastClient(clientConfig);
com.hazelcast.core.HazelcastInstance client = com.hazelcast.client.HazelcastClient.newHazelcastClient(clientConfig);
oLog.infoForced("xav: size of cluster:"+client.getDistributedObjects().size());
java.util.Collection<com.hazelcast.core.DistributedObject> collection=client.getDistributedObjects();
//for(com.hazelcast.core.DistributedObject o: java.util.Collection<com.hazelcast.core.DistributedObject> collection)
for(com.hazelcast.core.DistributedObject o: collection)
{
oLog.infoForced("xav: "+o.getName());
}
I hope this helps.