Search code examples
javaignite

Does affinity colocation work with Ignite Thin client?


In the docs I could find examples of the affinity colocation config only for thick client. Does this feature works with thin client? Any config examples, please?

In my app I use key-value API to work with Ignite Cache.

I tried to simply make AffinityKey as a key of for my put/get operations (see code below). I used clientId to store values of a particular client on the same node. But performance testing didn't show any improvements with getAll timings.

I suspect that something is wrong with my configuration:

@Bean
    ClientConfiguration igniteThinClientConfiguration(IgniteProperties igniteProperties) {
        ClientConfiguration clientConfiguration = new ClientConfiguration();
        clientConfiguration.setTimeout(igniteProperties.getTimeout());
        clientConfiguration.setAddresses(igniteProperties.getAddresses());
        clientConfiguration.setPartitionAwarenessEnabled(igniteProperties.isPartitionAwareness());
        return clientConfiguration;
    }
private static ClientCacheConfiguration cacheConfig(String cacheName, String cacheGroup, String dataRegion) {
        ClientCacheConfiguration cfg = new ClientCacheConfiguration();
        cfg.setName(cacheName);
        cfg.setCacheMode(CacheMode.PARTITIONED);
        cfg.setBackups(0);
        cfg.setExpiryPolicy(new TouchedExpiryPolicy(new Duration(TimeUnit.HOURS, 6)));
        cfg.setStatisticsEnabled(true);
        cfg.setDefaultLockTimeout(3000L);
        cfg.setGroupName(cacheGroup);
        cfg.setDataRegionName(dataRegion);
        return cfg;
    }
IgniteClient igniteClient = Ignition.startClient(igniteConfiguration);
ClientCache<AffinityKey<Long>, PaymentReceiptResponse> receiptCache = igniteClient.getOrCreateCache(cacheConfig(...));
...
receiptCache.put(new AffinityKey<>(123L, "clientId"), value)
...
Set<AffinityKey<String>> keys = ...;
receiptCache.getAll(keys)

Solution

  • Yes, affinity colocation works in Ignite Thin Client the same way it does in thick client.

    Thin client also supports Partition Awareness - sends requests directly to the primary node for the given cache entry. It is enabled by default.

    I tried to simply make AffinityKey as a key of for my put/get operations, but performance testing didn't show any improvements with timings.

    AffinityKey does not improve the performance of put operation. AffinityKey controls data distribution and allows things like "put all orders for the client on the same node where the client entry is stored", so that related data can be processed together (with Compute or SQL) - this is where you can achieve performance improvement.