Redis vs Guava Cache

I have code in which I implemented a caching mechanism. This used to be Guava-based caching, now I'm moving to Redis based on the needs of a centralized cache.

But I'm worried about its performance, as I have seen dramatically poor performance with redis compared to guave.

I measured the performance for api, which gets a class object from the cache. In the case of Guava, this was 5 ms, while in Radish it reaches 200 ms.
This is the average answer in the case of a load test, in the case of a response to one request is not much different.
I implemented Spring Redis data with cache abstraction.

The following is a Redis configuration example:

@Bean public RedisConnectionFactory redisConnectionFactory(@Value("${redis.host}") String redisHost, @Value("${redis.port}") Integer redisPort) { JedisConnectionFactory cf = new JedisConnectionFactory(); cf.setHostName(redisHost); cf.setPort(redisPort); cf.setUsePool(true); JedisPoolConfig jedisPool = new JedisPoolConfig(); jedisPool.setMaxTotal(500); cf.setPoolConfig(jedisPool); return cf; } @Bean(name = "redisTemplate") RedisTemplate<Object,Object> redisTemplate() { final RedisTemplate<Object,Object> template = new RedisTemplate<Object,Object>(); template.setConnectionFactory(applicationContext.getBean(RedisConnectionFactory.class)); return template; } @Bean public CacheManager cacheManager() { if(isRedisEnabled) { RedisTemplate<?,?> template = (RedisTemplate<?, ?>) applicationContext.getBean("redisTemplate"); RedisCacheManager redisCacheManager = new PieRedisCacheManager(template); redisCacheManager.setUsePrefix(true); try { template.getConnectionFactory().getConnection(); } catch(Exception e) { LOG.error("Unable to connect to redis Server ,closing application : "+e); SpringApplication.exit(applicationContext); } return redisCacheManager; } else { GuavaCacheManager guavaCacheManager = new GuavaCacheManager(); guavaCacheManager.setCacheBuilder(CacheBuilder.newBuilder()); return guavaCacheManager; } } 

Also, for redis server configuration, I tried to disable all persistence, as I don't need it. But still low performance.

My main request is that this particular configuration is causing this, or is Redis running very low compared to Guava?
Can other redis configuration settings compare with guava performance?
Suggest.

+5
source share
1 answer

Disclaimer: I am in no way specialist in using Guava or Redis, although I have used both.

Obvious performance loss obvious

To begin with, it seemed to me that when switching from Guava to Redis, completely normal behavior is observed.

Mainly because:

  • Guava provides caches that are in memory and local to your application running the JVM. Thus, your application can easily request without resorting to any interprocess communication.

  • Redis is a standalone key storage application that runs in its own process. As a result, you need to somehow establish a connection with him and send requests.

So, even if you were on the same machine, and even if Redis is inherent in performance, better than Guava caches (which is probably the case, to be honest, in the general case), you will surely see that performance falls in any case.

Possible improvements

In doing so, you could improve your productivity with configuration and architectural solutions:

  • Make sure you connect to Redis using your local IP address. This will help to avoid any address resolution when trying to establish connections.

  • Be sure to connect to Redis using a protocol that is as light as possible. Since I assume that you are using a local Redis server, and that you are sticking to the previous point, you do not need any calls and security protocols, etc ...

  • Any other common Redis configuration settings that may apply to your scenario.

+3
source

All Articles