debop / hibernate-redis

hibernate 2nd level cache privder using redis
Apache License 2.0
357 stars 184 forks source link

Which Redis maxmemory policy eviction is appropraite #59

Closed vchau closed 8 years ago

vchau commented 8 years ago

Hello, Thank you for this great library. I have a question regarding redis configuration.

I'm trying to fine tune my setup and one of the thing which I need to configure is the redis maxmemory eviction policy. I noticed that hibernate-redis/redisson is not setting the ttl value on cache regions in Redis. What is the recommended eviction policy? Right now, I think allkeys-lru and allkeys-random are the only options since those would be the only ones which make sense. I was hoping to use volatile-ttl but there is no ttl on any of these redis keys.

johnou commented 8 years ago

@debop looks like the old expiration thread has been removed, did you have some thoughts on how this could be improved?

old code

    protected synchronized void startExpirationThread(final JedisClient redis) {
        if (expirationThread != null && expirationThread.isAlive()) {
            return;
        }

        expirationThread = new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    try {
                        Thread.sleep(1000L);
                        Set<String> regions = regionNames.clone();
                        for (final String region : regions) {
                            if (redis != null) {
                                try {
                                    redis.expire(region);
                                } catch (Exception ignored) {
                                    log.warn("Error occurred in expiration management thread. but it was ignored", ignored);
                                }
                            }
                        }
                    } catch (InterruptedException ignored) {
                        break;
                    } catch (Exception ignored) {
                        log.warn("Error occurred in expiration management thread. but it was ignored", ignored);
                    }
                }
            }
        });
        expirationThread.setDaemon(true);
        expirationThread.start();
    }
debop commented 8 years ago

First, I'm not good at English^^

You can set expiration time per region name.

Redisson implement this ttl in Lua code itself.

johnou commented 8 years ago

@debop sounds like this issue could be closed as not a bug then if expiration for region is handled by Redisson.

debop commented 8 years ago

Yes exactly ^^