Nepxion / Aquarius

🔱 Nepxion Aquarius is a list of distribution components based on Redis + Zookeeper with Nepxion Matrix AOP framework, including distribution lock, cache, id generator, limitation 分布式锁、缓存、全局唯一主键、限流
http://www.nepxion.com
Apache License 2.0
405 stars 149 forks source link

RedisLockExecutorImpl 获取锁的实现,可不用作缓存 #8

Open ihenjoy opened 2 years ago

ihenjoy commented 2 years ago

image 这里可以不用作本地缓存,因为Redission 内部的重入本身就是按客户端id+线程id来判断的,这里加了本地缓存,如果业务key很多的话,就可能这里的内存占用会很大

HaojunRen commented 1 year ago

如果不做缓存,Redission每次去获取锁,都会new Redission Lock对象,对于吞吐量很大的服务,一秒几千上万次调用,那岂不是一秒也要创建出成千上万个对象出来?数据应该都正确的,重入锁应该需要重复利用,缓存起来吧?

HaojunRen commented 1 year ago

参考源码,每次getLock都是new RedissonLock

public class Redisson implements RedissonClient {
...
    @Override
    public RLock getLock(String name) {
        return new RedissonLock(commandExecutor, name);
    }
...
}