OptimalBits / bull

Premium Queue package for handling distributed jobs and messages in NodeJS.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Redis Scaling Issue with Redisson Client

Alok-Kumar-9 opened this issue · comments

Hi @manast !
We are running a delayed queue in redis using redisson client. We are using a t3.small elastcache instance and our application has redisson version 3.23.5 with Spring boot 3.x and Java 17.
We are not setting any TTL for our records. Our records go to a blocking queue once its delay period is over. We are seeing high CPU spikes when there is increase in traffic to Redis. How can we mitigate this?
I tried using replicas and clustered mode but apparently they are not working here.

My redis config-

CommandsLoadBalancer loadBalancer = new CommandsLoadBalancer();
    loadBalancer.setAddress("redis://test-0001-002.qqqq.0001.aps1.cache.amazonaws.com:6379");
    loadBalancer.setCommands(
        List.of(RedisCommands.READONLY.getName(), RedisCommands.LPOP.getName(), RedisCommands.BLPOP_VALUE.getName()));
    redisConfig
        .useClusterServers()
        .setScanInterval(2000)
        .setConnectTimeout(5000)
        .setIdleConnectionTimeout(5000)
        .setTimeout(10000)
        .setFailedSlaveReconnectionInterval(1000)
        .setRetryAttempts(5)
        .setRetryInterval(2000)
        .setLoadBalancer(loadBalancer)
//        .setLoadBalancer(new WeightedRoundRobinBalancer())
        .setReadMode(ReadMode.SLAVE)
        .addNodeAddress("redis://test-0001-001.qqqq.0001.aps1.cache.amazonaws.com:6379")
        .addNodeAddress("redis://test-0001-002.qqqq.0001.aps1.cache.amazonaws.com:6379");

    redisConfig
        .setTransportMode(TransportMode.NIO)
        .setThreads(64)
        .setNettyThreads(128);
    return Redisson.create(redisConfig);

My redis code-

public TestRedisDelay(RedissonClient managedClient, String queuePrefix, ObjectMapper objectMapper) {
    this.destinationQueue = managedClient.getBlockingQueue(queuePrefix + "test");
    this.delayedQueue = managedClient.getDelayedQueue(this.destinationQueue);

    this.objectMapper = objectMapper;
  }

public void pushToDelayedQueue(TestRequest testRequest) {
      try {
        String jsonTestRequest = objectMapper.writeValueAsString(testRequest);
        this.delayedQueue.offer(jsonTestRequest, 5L, TimeUnit.MINUTES);
      } catch (Exception e) {
        log.error("ERR_CONVERTING_TO_JSON_NODE :: {} :: REQ- {}", e.getMessage(), testRequest);
      }
  }

public TestRequest fetchRequests() {
      TestRequest testRequest = null;
      try {
        String revampedQueueRequest = destinationQueue.poll();
        if(!Strings.isEmpty(revampedQueueRequest)) {
          testRequest = objectMapper.readValue(revampedQueueRequest, TestRequest.class);
        }
      } catch (Exception e) {
        log.error("ERR_FETCHING FROM QUEUE :: {}", e.getMessage());
      }

    return testRequest;
  }

Can someone suggest anything?

Originally posted by @Alok-Kumar-9 in #1941 (comment)

Hello,
I am a bit confused, how can you run Bull using Java?

commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.