network-programmingdistributed-computinghazelcastin-memory-data-grid

How to create asynchronous backups of shared data structures in hazelcast?


I'm trying to add x number of objects via a simple for-loop to a distributed hazelcast queue (IQueue).

        HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
        BlockingQueue<String> configs = hazelcastInstance.getQueue("test"); 
        for(int i = 0; i<1000;i++) {
            configs.add("Some string"+i);
        }

Changing the values and in the config (see below) doesn't have any influence on the execution speed. I'd assume that increasing would block the insert operations and increasing would not (actually the loop should be run through as quickly as if the #add operation was on a local queue). However, the time executing the for-loop is the same. Even if i set both values to 0. Why is that (it's a two-node cluster with one node on a different vm)?

<?xml version="1.0" encoding="UTF-8"?>
<hazelcast xsi:schemaLocation=
  "http://www.hazelcast.com/schema/config hazelcast-config-3.7.xsd"
  xmlns="http://www.hazelcast.com/schema/config"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <network>
        <port auto-increment="true" port-count="20">5701</port>
        <join>
            <multicast enabled="false">
        </multicast>
        <tcp-ip enabled="true">
            <member>172.105.66.xx</member> 
        </tcp-ip>
        </join>
    </network>

    <queue name="test">
        <statistics-enabled>false</statistics-enabled>
        <max-size>0</max-size>
        <backup-count>0</backup-count>
        <async-backup-count>1</async-backup-count>
        <empty-queue-ttl>-1</empty-queue-ttl>
    </queue>
</hazelcast>

Solution

  • The async-backups are not blocking your calls, so there should be a minimal difference in setting 0 or 1. Setting another value is meaningless on the 2 nodes cluster.

    What makes the difference is the fact if the owner of the partition with your data structure is a local one or a remote one. The performance issues are in such case usually caused by the network latency between the caller (your test) and data structure owner (remote Hazelcast instance).

    HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
    IQueue<String> configs = hazelcastInstance.getQueue("test"); 
    for(int i = 0; i<1000;i++) {
        configs.add("Some string"+i);
    }
    Member localMember = hazelcastInstance.getCluster().getLocalMember();
    Member partitionOwner = hazelcastInstance.getPartitionService().getPartition(configs.getName()).getOwner();
    boolean localCall = localMember.equals(partitionOwner);
    System.out.println("Local calls to IQueue: " + localCall);