Hi Ian,
I've extended CHI::Driver::Redis and implemented the main approach of the fixes you've mentioned on your previous message —by keeping inventory on a sorted set in contrast to a set as there would otherwise be no way to discern which keys have already expired.
For the meantime, I've released this modification as a separate module under CHI::Driver::Redis::SortedSet <
https://metacpan.org/pod/CHI::Driver::Redis::SortedSet> but would like to check if you'd be interested to incorporate the modifications I've made into your module so the community does not to have to deal with multiple drivers which would essentially be doing the same thing.
Some implementation notes BTW:
1. Upon calling store(), instead of adding to a set to keep track of namespace members, the same key is added to a sorted set with the score set to either:
a. IF key has a finite expiration — now + $expires_at
b. ELSE — "+inf" (as key will never expire)
2. Likewise, when store() gets called, "cleanup" of expired keys via ZREMRANGEBYSCORE is executed. This can be costly for sparsely-used namespaces with blasts in between as the number of expired entries can be huge. That said, I still would not imagine this would have huge costs as sorted sets are automatically "house-kept" with every usage.
3. chinamespaces is still left intact as a set (and not migrated as a sorted set) as this should not be a concern either way. However, if it did, the same strategy can be applied.
4. For existing Redis datasets pre-populated with entries using CHI::Driver::Redis, switching the driver to using the new one will fail (albeit silently as one of the design goals of the original module) as the namespace inventory list data type is now different. A transparent "migration" schema should not be too difficult to implement as it will only involve:
a. check if TYPE "<ns>" eq "zset", if it is, no-op (i.e. bail-out)
b. foreach SMEMBERS, ZADD to "<ns_temp>", with SCORE = now + TTL
c. DEL "<ns>"
d. RENAME "<ns_temp>" to "<ns>"
I hope this provides an outline of my thoughts. Looking forward to hearing from you.
Cheers,
Arnold
On Tue Mar 08 13:58:37 2016, jsemaan@inverse.ca wrote:
Show quoted text> The scoring approach you define does seem like it will require a
> daemon
> maintaining this or will create latency on reads.
>
> We used to use the purge method when we used the file store but it
> involves code paths that we do not want to maintain anymore since one
> of
> the reasons we moved to redis was the auto expiry of keys.
>
> You are right that we never have all keys expiring so that cannot be
> used to expire the set on our side
>
> I opened a PR that uses SCAN for listing earlier today :
>
https://github.com/rentrak/chi-driver-redis/pull/7
>
> It obviously has downsides that you may not want to have in the
> library,
> but in our case the leak problem is bigger than the downsides we have
> with this new strategy as we do not list keys often.
>
> We are about to test this under a heavy load to comfort the design,
> but
> still as I said, we do not use listing extensively so we're a soft
> use-case for that change.
>
> Regards,
>
> On 03/08/2016 01:38 PM, Ian Burrell via RT wrote: