Skip to content

RedisLockRegistry improvement, using pub-sub for lock to without spinlock #3690

@Meteorkor

Description

@Meteorkor

Expected Behavior

Remove spinlock for used by RedisLockRegistry
So, I thought about how to improve this part through redis pub-sub.

Current Behavior

Currently, spinlock is used to acquire redis-lock.

https://github.com/spring-projects/spring-integration/blob/main/spring-integration-redis/src/main/java/org/springframework/integration/redis/util/RedisLockRegistry.java#L231-L233

while (!obtainLock()) {
    Thread.sleep(100); //NOSONAR
}

https://github.com/spring-projects/spring-integration/blob/main/spring-integration-redis/src/main/java/org/springframework/integration/redis/util/RedisLockRegistry.java#L291-L298

long expire = now + TimeUnit.MILLISECONDS.convert(time, unit);
boolean acquired;
while (!(acquired = obtainLock()) && System.currentTimeMillis() < expire) { //NOSONAR
    Thread.sleep(100); //NOSONAR
}


If a vm instance acquires a lock and persists for a long time, or if multiple vm instances try to acquire a lock, I think the part where obtainLock() is called continuously is wasteful.

Context

I would like to contribute to the project.
If it's okay with you, I'd like to write a PR and get a review.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions