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

RedisClusterClient default connection congestion #252

Closed
pcchan opened this issue May 29, 2016 · 3 comments
Closed

RedisClusterClient default connection congestion #252

pcchan opened this issue May 29, 2016 · 3 comments
Labels
type: feature A new feature
Milestone

Comments

@pcchan
Copy link

pcchan commented May 29, 2016

Following up from my question in the Google Group.

As mentioned in the documentation, connections created with RedisClusterClient will always create a default connection to the node with the lowest latency. However, this may cause congestion when one node has a lower latency. If all clients experience the lowest latency with a particular node, then all clients will pick that node for its default connection.

In my case I'd be happy to use randomly selected nodes. That gives me a more predictable distribution of connections. Perhaps some environments prefer selecting by latency, but maybe lettuce could expose the choice as a client configuration?

@mp911de mp911de added the type: feature A new feature label May 29, 2016
@mp911de mp911de added this to the Lettuce 4.2.0 milestone May 29, 2016
@mp911de
Copy link
Collaborator

mp911de commented May 29, 2016

Thanks for the ticket. The default connection is created to the first node able to connect. RedisClusterClient starts to its connection attempts with the first entry of the Partitions collection (ordered by latency). Randomly selected nodes will work, but it's not a deterministic approach.

There are two other options which both seem reasonable to me:

  1. Sticking to the order of seed nodes: The connection attempts are performed in the order the seed nodes are provided. This approach gives full control to the user.
  2. Using the client count: Lettuce obtains the client connection count for each cluster node while topology discovery (can be disabled) and Partitions is ordered by the client count. Obtaining the number of client connections beyond the seed nodes can be disabled with the upcoming 4.2 version which is useful when running large clusters.

@mp911de
Copy link
Collaborator

mp911de commented Jun 1, 2016

The default will be to connect to the node with the least clients. For now RedisClusterClient will expose getSocketAddressSupplier(Function<Partitions, Collection<RedisClusterNode>> sortFunction) which can be overriden to specify an own function. lettuce ships with TopologyComparators that expose predefined sorting methods (sortByUri, sortByClientCount and predefinedSort). Applying a sorting function requires to subclass RedisClusterClient for now as this is the least invasive approach.

predefinedSort allows to use the initial seed nodes as predefined ordering and apply it to the dynamic topology results from Partitions. Nodes that are not found in the initial seed nodes are ordered by the URI (lexicographical comparison of the host and port string, i.e. 127.0.0.1:6379 < 127.0.0.1:6380). The block of nodes not found in the predefined order comes after the block of nodes with a predefined order.

mp911de added a commit that referenced this issue Jun 1, 2016
lettuce now exposes getSocketAddressSupplier to control the order of connection points when attempting to connect the default connection. The order can be influenced by subclassing RedisClusterClient and overriding getSocketAddressSupplier.

 TopologyComparators provides a predefinedSort that allows sorting the connection points by the order of a list of RedisURI (e.g. the initial seed nodes). These changes give flexibility to implement custom ordering.
mp911de added a commit that referenced this issue Jun 1, 2016
Switch the connection point ordering to client count ordering instead of latency ordering. This change reduces connection congestion of the default cluster connection by using the nodes with the lowest client counts.

The view of client counts is cached and is refreshed upon topology refresh.
@mp911de
Copy link
Collaborator

mp911de commented Jun 6, 2016

Implemented.

@mp911de mp911de closed this as completed Jun 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature A new feature
Projects
None yet
Development

No branches or pull requests

2 participants