Wednesday, October 17, 2018

Performance | Replicating to multiple replication agents programmatically without looping

Objective:

Normally developers use loops to Replicate pages or assets programmatically through Java code to multiple replication agents, which is a bad practice in terms of performance. It particularly impacts the queue performance when replicating thousands of content nodes and one can observe the lag between queuing of items in replication queue to different agents.

Solution:

Do not use loops instead utilize AgentFilters to set list of replication agents through which replication should be done. Here is sample code:

String replicationAgents = { "publish_agent1", "publish_agent2" }; // From configuration
ReplicationOptions options = new ReplicationOptions();
options.setFilter(agent -> Arrays.asList(replicationAgents).contains(agent.getId()));
replicate.replicate(resolver.adaptTo(Session.class), type, targetPathsArray, options);

Advantage of this approach is that it reduces the queue lag significantly. While processing all replication items, individual item is assigned to various replication agents at one go.

No comments:

Post a Comment

CDN | Clearing Cloudflare cache

In order to clear Cloudflare cache automatically via code, follow below steps: 1. Develop Custom TransportHandler Develop a custom Trans...