Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read request is not dispatched to slave nodes evenly when ReadFrom.slave #1148

Closed
ldwnt opened this issue Oct 14, 2019 · 3 comments
Closed

Comments

@ldwnt
Copy link

ldwnt commented Oct 14, 2019

Bug Report

I have a redis cluster of 3 master nodes & 6 slave nodes. There is a key named "a" on 1 master node and 2 slave nodes. I set ReadFrom = SLAVE and try to read the "a" key from both of the 2 slave nodes in concurrently rest calls. However, when I use jmeter to call the "test" API with 10 threads, only one of the 2 slave processes has high cpu rate while the other one seem to be idle. Am I missing some config here, or is lettuce designed to read from only one slave node, even when the ReadFrom.SLAVE option is used?

Current Behavior

Only one slave node has high cpu rate.

Input Code

    private RedisClusterClient client;
    private StatefulRedisClusterConnection<String, String> connection;
    private GenericObjectPool<StatefulRedisClusterConnection<String, String>> pool;

    @RequestMapping("/lettuce-init/{ip}/{port}")
    public void lettuceOpen(@PathVariable String ip, @PathVariable int port) throws Exception {
        client = RedisClusterClient.create(RedisURI.create(ip, port));
        connection = client.connect();
        connection.setReadFrom(ReadFrom.SLAVE);
        pool = ConnectionPoolSupport.createGenericObjectPool(() -> connection, new GenericObjectPoolConfig());
    }

    @RequestMapping("/test")
    public String lettuce() throws Exception {

        StatefulRedisClusterConnection<String, String> conn = pool.borrowObject();
        String result = conn.sync().get("a");
        conn.close();
        log.debug(result);
        return result;
    }

Expected behavior/code

All slave nodes receive roughly equal amount of requests.

Environment

  • Lettuce version(s): 5.1.7
  • Redis version: 5.0.5
@ldwnt ldwnt added the type: bug A general bug label Oct 14, 2019
@mp911de mp911de added status: works-as-designed and removed type: bug A general bug labels Oct 15, 2019
@mp911de
Copy link
Collaborator

mp911de commented Oct 15, 2019

Works as designed. See #834 for details. Once #1145 is fixed, you can create your own ReadFrom implementations that can randomize load. Use ReadFrom.ANY until then.

@mp911de mp911de closed this as completed Oct 15, 2019
@bhavikambani
Copy link

@mp911de Is this feature available now ? I am using 5.2.2.RELEASE, can't see there at least. I also have same usecase where I have multiple SLAVES and I want to distribute read between those nodes.

@mp911de
Copy link
Collaborator

mp911de commented Jul 10, 2020

#834 is in place since version 5.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants