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

Introduce MasterReplicaClient to reuse performance-intensive resources #1256

Open
Tracked by #2924
grzechum opened this issue Apr 1, 2020 · 5 comments
Open
Tracked by #2924
Labels
for: team-attention An issue we need to discuss as a team to make progress type: feature A new feature
Milestone

Comments

@grzechum
Copy link

grzechum commented Apr 1, 2020

Bug Report

Each connection created using sentinel MasterReplica.connectAsync() creates new sentinel topology provider and refresher. This heavily degrades performance when used together with connections pool.

Current Behavior

Current SentinelConnector.connectAsync() implementations create a new instance of sentinel topology provider and refresher for every connection.

    @Override
    public CompletableFuture<StatefulRedisMasterSlaveConnection<K, V>> connectAsync() {

        TopologyProvider topologyProvider = new SentinelTopologyProvider(redisURI.getSentinelMasterId(), redisClient, redisURI);
        SentinelTopologyRefresh sentinelTopologyRefresh = new SentinelTopologyRefresh(redisClient,
                redisURI.getSentinelMasterId(), redisURI.getSentinels());

        MasterSlaveTopologyRefresh refresh = new MasterSlaveTopologyRefresh(redisClient, topologyProvider);
        MasterSlaveConnectionProvider<K, V> connectionProvider = new MasterSlaveConnectionProvider<>(redisClient, codec,
                redisURI, Collections.emptyMap());

        Runnable runnable = getTopologyRefreshRunnable(refresh, connectionProvider);

        return refresh.getNodes(redisURI).flatMap(nodes -> {

            if (nodes.isEmpty()) {
                return Mono.error(new RedisException(String.format("Cannot determine topology from %s", redisURI)));
            }

            return initializeConnection(codec, sentinelTopologyRefresh, connectionProvider, runnable, nodes);
        }).onErrorMap(ExecutionException.class, Throwable::getCause).toFuture();
    }

Expected behavior/code

Create single sentinel topology provider and refresher for all connections created from same client and URI.

Environment

  • Lettuce version(s): 5.2.2.RELEASE
  • Redis version: 5.0.x
@grzechum grzechum added the type: bug A general bug label Apr 1, 2020
@mp911de
Copy link
Collaborator

mp911de commented Apr 1, 2020

We currently have no way to reuse these facilities as the factory exposes static methods only. We didn’t add a stateful object such as RedisClusterClient to avoid yet another client object.

@grzechum
Copy link
Author

grzechum commented Apr 1, 2020

Would it be possible to create external SentinelConnector instance (that will encapsulate single sentinel topology and refresher) and pass it to MasterReplica.connectAsync() as optional parameter?
This way backward compatibility may be preserved.

SentinelConnector requires same arguments as MasterReplica.connectAsync() so it can be created upfront and used to create connections in connection pool.

@mp911de
Copy link
Collaborator

mp911de commented Apr 1, 2020

These resources may be associated with state and disposable resources (e.g. the sentinel variant maintains connections to Redis sentinels to capture topology changes via pub/sub). We’ve a few tickets that as for master replica extensions that do not play well with the static factory methods.

We will eventually have to add a something like a MasterReplica client and deprecate the MasterReplica factory. One of the items is the ability to use topology refresh on demand and a single connection isn’t the right place to do so.

@mp911de mp911de changed the title Each connection created using sentinel MasterReplica.connectAsync() creates new topology provider and refresher. Introduce MasterReplicaClient to reuse performance-intensive resources Apr 2, 2020
@mp911de mp911de added status: help-wanted An issue that a contributor can help us with type: feature A new feature and removed type: bug A general bug labels Apr 2, 2020
@grzechum
Copy link
Author

grzechum commented Apr 2, 2020

Do you see any workaround which we may apply, that will work with 5.2.x ?

@mp911de
Copy link
Collaborator

mp911de commented Apr 2, 2020

No, we cannot do anything for 5.2.x and 5.3. The earliest version with such support could be Lettuce 6 and even for Lettuce 6 it's unclear whether it's going to be 6.0 or 6.1. Given the current Corona impact I have even less time to build features myself.

@tishun tishun added this to the Backlog milestone Jun 12, 2024
@tishun tishun added status: good-first-issue An issue that can only be worked on by brand new contributors for: team-attention An issue we need to discuss as a team to make progress and removed status: help-wanted An issue that a contributor can help us with status: good-first-issue An issue that can only be worked on by brand new contributors labels Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: team-attention An issue we need to discuss as a team to make progress type: feature A new feature
Projects
None yet
Development

No branches or pull requests

3 participants