redis-rb icon indicating copy to clipboard operation
redis-rb copied to clipboard

Prioritize replica node

Open vladimir-stornest opened this issue 3 years ago • 1 comments

When there are multiple replica nodes per master (in a cluster mode), is there an option to prioritize which replica node to be used?

Let's say I have three master nodes: A, B, C. Each master node has two replicas: A1, A2, B1, B2, C1, C2.

The replica: true option is used. When a key needs to be read from the A slot, which node will be used between A1 and A2? Is there an option where I can prioritize the A1 node? I'm asking because A1 would be nearest to the application, so reading from it would have the lowest latency.

vladimir-stornest avatar Feb 07 '22 11:02 vladimir-stornest

There is no way to do so in the current implementation for cluster mode. https://github.com/redis/redis-rb/blob/4e76b035a98ce2c7bd7666a1553fc4394279ca83/lib/redis/cluster/slot.rb#L29

It seems that there is a similar issue for sentinel mode.

  • https://github.com/redis/redis-rb/pull/588

There might be indeed a performance issue by balancing across regions or availability zones. The more number of queries is, the more total latency is. But I'd say that it might be a bit over responsibility if the client care about it. The client just fetch server connection information.

It seems that Redis cluster v2 will be able to proxy requests and aware placement of servers.

  • https://github.com/redis/redis/issues/8948

Request proxying: The idea here is that Redis server nodes could proxy incoming requests to the desired node instead of relying on heavy client side logic to know the cluster topology. Simplifies some of the work for workloads that don’t want to maintain a heavy client. This would be an optional configuration.

Placement awareness: Today the individual nodes have no concept of how they are placed compared to each other, and will happily allow all the primaries to exist in the same zone. This also may include the notion of multi-region awareness.

supercaracal avatar Feb 08 '22 00:02 supercaracal

@vladimir-stornest I added :replica_affinity option. If you would like, you can use.

https://github.com/redis/redis-rb/tree/master/cluster

Redis::Cluster.new(nodes: nodes, replica: true, replica_affinity: :latency)

FYI:

  • The redis gem was decoupled to redis and redis-clustering gems.
  • The redis gem now depends on the redis-client gem.
  • The redis-clustering gem now depends on the redis-cluster-client gem.
  • https://github.com/redis-rb

supercaracal avatar Sep 08 '22 01:09 supercaracal