I have a code in which i have implemented cache mechanism. Previously it was Guava based caching now i am shifting to Redis considering the needs of centralized cache.
But I am concerned about its performance as i have seen drastically low performance with redis when compared to guave.
I have measured performance for an api which gets a class object from cache
In case of Guava it was 5ms, whereas in Redis it gets 200ms.
This is average response in case of load test , in case of single request response does not differ much.
I have implemented Spring data Redis with cache abstraction.
Below is the sample Redis configuration:
@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;
}
}
Apart from that, For redis server configuration i have tried disabling all persistence as i don't need it. But still low performance.
My main query is that is it the configuration which is causing this or Redis is very low performing compared to Guava?
Can by more configuration tuning redis performance be compared to that of guava?
Please Suggest.