4

I am using Redisson's RMapCache to handle some distributed collections in my application.

The keys in these collections, should expire after some time, so when adding keys I set the TTL:

RMapCache<String, MyClass> cacheMap = GetMap("test");
cacheMap.put("DTO1", myClassInstance, 20, TimeUnit.SECONDS);

So after 20 seconds the Key should expire. This works perfectly, if the process is not terminated before the expiration timestamp. However, if for any reason the process dies, then the key is never cleared, which means that the eviction is handled by Redisson within the Java process and not by Redis itself.

Is there any way to make redisson use the Redis' built-in EXPIRE feature? So that the process that inserts in the Map is not responsible for the keys eviction.

I find the current redisson implementation to be extremely fragile.

1 Answers1

3

Once you create the same RMapCache object after crash it starts evictionScheduler which in turn clears expired entries in Redis.

If you want to rely on Redis eviction process only then use RBucket object. Redis doesn't provide map entry expiration by TTL or idleTime.

Nikita Koksharov
  • 10,283
  • 1
  • 62
  • 71
  • It's not very clear here! Do you mean the TTL per entry in RMapCache shouldn't be used ? Should RMapCache should be used as a singleton ? RMap has map level TTL does it mean that if it is used as a singleton it can't be resurrected after ttl ? Though Redisson is great it's confusing here ! – Giri Mar 24 '21 at 00:13
  • 1
    @Giri Once you create the same MapCache object after crash it will start evictionScheduler which will clear expired entries from Redis. But if you want to rely on Redis TTL only then you can use RBucket object. RMap can't resurrect it's TTL set for whole instance. – Nikita Koksharov Mar 24 '21 at 05:27
  • Do we need to use RBucket object as a singleton or it's fine if we get the RBucket from client everytime for usage ? Whats the recommendation here ? – Giri Mar 31 '21 at 17:30
  • 1
    @Giri RBucket object is state less. You can get it each time. – Nikita Koksharov Apr 01 '21 at 06:58
  • @NikitaKoksharov currently I observed one issue, by using RMapCache its not getting deleted from redis which is set to 5 min and its very slow when its has large amount of record more than 5GB... is there any way to make it faster ? – Bhargav Patel May 22 '23 at 06:44
  • 1
    @BhargavPatel you can try to increase [cleanUpKeysAmount](https://github.com/redisson/redisson/wiki/2.-Configuration#cleanupkeysamount) and reduce [maxCleanUpDelay](https://github.com/redisson/redisson/wiki/2.-Configuration#maxcleanupdelay) params – Nikita Koksharov May 22 '23 at 10:22
  • @NikitaKoksharov thanks for the quick reply. what is the recommended value for both parameters in production? any documents which can help to gather values based on hardware-config? We have an average of 4.7 to 6 million entries everyday and expired time for each key is 5 mins – Bhargav Patel May 22 '23 at 12:56
  • 1
    @BhargavPatel that depends on many factors. Try 1000, 10K, 100K value for cleanUpKeysAmount parameter – Nikita Koksharov May 22 '23 at 14:12
  • @NikitaKoksharov I kept maxCleanUpDelay as 30 seconds but it's taking 1 and a half minutes to clean up. is it taking exact value or its have some additional delays? or how does that params works ? – Bhargav Patel May 22 '23 at 14:21
  • 1
    @BhargavPatel if it takes a lot of time, then try to reduce cleanUpKeysAmount value. – Nikita Koksharov May 22 '23 at 16:11
  • @NikitaKoksharov what is difference between maxCleanUpDelay and minCleanUpDelay ? seems confusing which one would be taken and in which scenario ? – Bhargav Patel May 24 '23 at 06:18
  • 1
    @BhargavPatel they control a delay between each cleanup method invocation – Nikita Koksharov May 24 '23 at 07:00
  • @NikitaKoksharov So if i keep minCleanUpDelay=5 and maxCleanUpDelay=60 then first cleanup would be consider minCleanUpDelay and next would be at ? want to see the when would happen next cleanup cycle ? so I can adjust rate of cleanup in production. Currently its seems unpredictable of next cycle – Bhargav Patel May 24 '23 at 07:25