debop / hibernate-redis

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

We use cluster mode, but always have a cache hit rate of 50%. Do you know why? #136

Open huaism opened 5 years ago

huaism commented 5 years ago

image

huaism commented 5 years ago

Even if we visit the same KEY multiple times, this result is

4fath commented 4 years ago

@huaism how did you get that fancy output?

huaism commented 4 years ago

@4fath link : https://github.com/junegunn/redis-stat

NitinK91 commented 4 years ago

Hi @huaism , can you please provide the config to implement redis cache using redis-cluster.

huaism commented 4 years ago

HI @NitinK91

hibernate redis

hibernate.cache.region.factory_class=org.hibernate.cache.redis.hibernate52.SingletonRedisRegionFactory hibernate.cache.region_prefix=hibernate hibernate.cache.use_structured_entries=true hibernate.cache.use_query_cache=false hibernate.cache.use_second_level_cache=true hibernate.cache.provider_configuration_file_resource_path=hibernate-redis.properties

hibernate-redis.properties

redisson-config=classpath:redisson.yaml redis.expiryInSeconds.default=0

redisson.yaml

clusterServersConfig: idleConnectionTimeout: 10000 pingTimeout: 1000 connectTimeout: 10000 timeout: 3000 retryAttempts: 3 retryInterval: 1500 reconnectionTimeout: 3000 failedAttempts: 3 password: null subscriptionsPerConnection: 5 clientName: null loadBalancer: ! {} slaveSubscriptionConnectionMinimumIdleSize: 1 slaveSubscriptionConnectionPoolSize: 50 slaveConnectionMinimumIdleSize: 10 slaveConnectionPoolSize: 64 masterConnectionMinimumIdleSize: 10 masterConnectionPoolSize: 64 readMode: "MASTER_SLAVE" nodeAddresses:

NitinK91 commented 4 years ago

Thanks @huaism for sharing.

I am facing an issue. Can you help. It is giving following error::

java.lang.IllegalArgumentException: port out of range:-1 at java.net.InetSocketAddress.checkPort(InetSocketAddress.java:143) at java.net.InetSocketAddress.(InetSocketAddress.java:224) at org.redisson.client.RedisClient.(RedisClient.java:93) at org.redisson.connection.MasterSlaveConnectionManager.createClient(MasterSlaveConnectionManager.java:310) at org.redisson.cluster.ClusterConnectionManager.connect(ClusterConnectionManager.java:150) at org.redisson.cluster.ClusterConnectionManager.(ClusterConnectionManager.java:81) at org.redisson.config.ConfigSupport.createConnectionManager(ConfigSupport.java:172) at org.redisson.Redisson.(Redisson.java:103) at org.redisson.Redisson.create(Redisson.java:133)

Actually it not generating ClientPartition.getMasterAddress() properly. Address is //127.0.0.1:8001@18001 as recorded by CLUSTER_NODES, but it reads it as host: 18001 and port=-1.

Cluster config deom CLUSTER_NODES:: [ClusterNodeInfo [nodeId=4317f285b359ddc3ac08bb85239924509146e475, address=//127.0.0.1:8003@18003, flags=[SLAVE], slaveOf=4118a348827e6107d7e35522a251fd39c5a8f82b, slotRanges=[]], ClusterNodeInfo [nodeId=2f7b93c80d3721b3fb26fe87bc28ed04a63fe0ec, address=//127.0.0.1:8005@18005, flags=[SLAVE], slaveOf=8b81c3e1acb4e1959a83267540058d1a6bffa12f, slotRanges=[]], ClusterNodeInfo [nodeId=4118a348827e6107d7e35522a251fd39c5a8f82b, address=//127.0.0.1:8001@18001, flags=[MASTER], slaveOf=null, slotRanges=[[5461-10922]]], ClusterNodeInfo [nodeId=a0770863d893a5b8106a83e247cea2544f99ef36, address=//127.0.0.1:8004@18004, flags=[SLAVE], slaveOf=6b9da1bbe38b978a3017406e5c1e310f4706cfc8, slotRanges=[]], ClusterNodeInfo [nodeId=8b81c3e1acb4e1959a83267540058d1a6bffa12f, address=//127.0.0.1:8000@18000, flags=[MYSELF, MASTER], slaveOf=null, slotRanges=[[0-5460]]], ClusterNodeInfo [nodeId=6b9da1bbe38b978a3017406e5c1e310f4706cfc8, address=//127.0.0.1:8002@18002, flags=[MASTER], slaveOf=null, slotRanges=[[10923-16383]]]]

My code is :: Config config = new Config(); config.useClusterServers() .addNodeAddress("redis://127.0.0.1:8000"); RedissonClient redisson = Redisson.create(config);

    RMap<String, String> map = redisson.getMap("simpleMap");
    map.put("mapKey", "This is a map value");
    String mapValue = map.get("mapKey");
    System.out.println("stored map value: " + mapValue);
    redisson.shutdown();