I want to use Jedis for Redis cluster or just for Redis servers. I wonder to know how to enable Round Robin for read operations. Doesn't matter what I will use Redis cluster or Redis servers with Sentinel. I will have several masters and each master will have it's own slaves. How to distribute read operations among all slaves for a particular hash slot (or for a particular shard)?
Load balancing is a very significant problem in Redis. One consideration is to define what load balancin means.
Load balancing mechanisms in IMKVS can be examined under three lenses if we only consider the intrinsic factors of uneven load distribution:
load balancing based on key popularity: The frequency that specific items are invoked seems to be related to the performance of the IMKVS node and system.
load balancing based on key distribution: In many systems the distribution of the keys in the available nodes are inherently posing a load balancing challenge. The examination of the problem in isolation from the previous as well as from the capabilities of the underlying nodes can be risky, however it is far more simple in terms of implementation, even though based on mere statistics.
load balancing based on query volume: The amount of keys requested concurrently from a IMKVS deployment and consequently from a node seems to be a metric of interest in some load balancing deployments.
So to summarize, investigation of the load balancing problem requires the examination of at least these factors:
frequency of incoming queries
volume of incoming queries
the way the keys are distributed in the system
key length and value length
According to my experiments:
The distribution of the keys plays an important role in the load balancing factor. Thus, in the last experiment my aim was to observe how response time changes through the migration of keys from one node to another in Redis Cluster. For the needs of my experiment i loaded 33000 in one master (M1) node and 0 in the other master (M2). I made 4 concurrent client calls in M1 and i started migration at time 7 and stopped at time 36.
Ι observed that the RT for 4 concurrent client calls averaged a 25 ms. In the beginning of the migration process the response times present a sudden increase while at the end of the process we notice a reduction in the order of magnitude of 9ms. This improvement indicates a 3x speedup. The spikes are due to the overhead of the migration command. This command actually executes a DUMP+DEL operation in the source instance, and a RESTORE operation in the target nstance. So, it is clear that with the migration of keys from one heavy loaded node to another the response time is significantly reduced.
From the above, it is clear that with the distribution of read requests among nodes, it is no certain that you will have a load distirbution (balancing) in Redis because the results show that:
factors such as key popularity and value volume seem to have a minor effect
key distribution and key length are contributing factors to the load balancing problem and impact the cluster’s RTs
Thus, you need to create a mechanism that combines all these factors. You can start with an algorithm that distirbutes the keys among the nodes.
The steps of the algorithm are as follows:
Find the crowd of masters
Obtain the total number of keys they hold
For each master node store the hostname, port and number of keys
Calculate the keys that each master must hold so that the distribution of keys to be balanced (total keys of cluster / number of masters)
Find which master nodes must take or give keys and the total amount of keys that they must give/take
Characterize masters as source or target nodes depending on whether they are receiving or giving away keys respectively
Start migrating from source node to target nodes, first the hashslots and then the relevant keys and iterate until all the masters have the same amount of keys
And then you can create the next algorihms in order to create a mechanism that provides LB in order to minimize the RT.
Note: further information i will add in half a month in my paper as well as a link to Github with my algorithm implementation.