netgen / TagsBundle

Netgen Tags Bundle is an eZ Platform bundle for taxonomy management and easier classification of content, providing more functionality for tagging content than ezkeyword field type included in eZ Platform kernel.
https://netgen.io
GNU General Public License v2.0
48 stars 43 forks source link

Missing expire/TTL on Redis keys #131

Open fredriktid opened 3 years ago

fredriktid commented 3 years ago

When inspecting Redis keys from this bundle they're missing expiration/TTL:

$ redis-cli -n 1
> TTL namespace:tag-content-15681
(integer) -1

To avoid maxing out Redis memory with the "volatile-lru" eviction strategy one can define a "default_lifetime" in app/config/cache_pool/cache.redis.yml.

services:
    cache.redis:
        class: Symfony\Component\Cache\Adapter\TagAware\RedisTagAwareAdapter
        parent: cache.adapter.redis
        tags:
            - name: cache.pool
              clearer: cache.app_clearer
              provider: 'redis://%cache_dsn%?timeout=5&read_timeout=10'
              namespace: '%cache_namespace%'
              default_lifetime: 36000 # 10 hours

volatile-lru states that:

evict keys by trying to remove the less recently used (LRU) keys first, but only among keys that have an expire set, in order to make space for the new data added.

Expected behaviour would be that cache items are given a TTL when defined in Symfony.

Would be great to have some feedback on this. We could possibly provide a PR.

emodric commented 3 years ago

Hi!

Thanks for the issue and the research!

However, Tags Bundle only reuses configuration from eZ Platform/Ibexa kernel and does not control cache pool at all. So any changes to default config should be done on eZ repos, not here.

I hope this makes sense to you?

fredriktid commented 3 years ago

Thanks for the quick reply. Your description would be the expected behaviour but we're experiencing something else.

redis:6379[1]> TTL namespace:ez-content-info-27475
(integer) 29159
redis:6379[1]> TTL namespace:netgen-tag-2466-0-1
(integer) 29101
redis:6379[1]> TTL namespace:tag-tag-6161
(integer) -1
redis:6379[1]> TTL namespace:tag-content-14291
(integer) -1

It seems to me that eZ-keys (prefixed with ez:) all have a TTL, but some keys from this bundle don't. When I run the following command to list all keys without a TTL, only keys named tag-* are returned.

redis-cli -n 1 keys  "*" | while read LINE ; do TTL=`redis-cli -n 1 ttl "$LINE"`; if [ $TTL -eq  -1 ]; then echo "$LINE"; fi; done;

Though I haven't dived into your code enough to point out any bugs yet.

emodric commented 3 years ago

It might be that eZ made some modifications to their caching layer since the last time anyone touched the cache layer here in Tags Bundle. That seems to me the most reasonable asumption.

If you have time, it would be appreciated if you can look into it. I will try to find some time too.

fredriktid commented 3 years ago

Absolutely, I'll try to find some time in the following days.