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.
GP007 source share