Redis cluster design consists of 2 parts: hash slot and Node master, this blog post through 3 map to understand the Redis cluster design.
Node Master:
Master and slave design is not a new thing, in the database we also often use the Lord never do read and write separation, directly above:
The information that can be seen on the map:
1, only 1 master, can have n slaver, and slaver can also have their own slaver, because this master-slave relationship determines that they are in the configuration phase to specify their superior and subordinate relationship, rather than zookeeper that parallel relationship is autonomous push out.
2, read and write separation, master only responsible for writing and synchronizing data to Slaver,slaver undertook the task of being read, so slaver expansion can only improve reading efficiency can not improve write efficiency.
3, slaver first to get the information from master into the disk, and then load into the memory, the client side is read from the memory of the information, so Redis is a memory database.
When a new slaver joined this cluster, will take the initiative to find master to worship the dock, Master found new brother after the full amount of data sent to the new slaver, the greater the amount of data performance consumption will be greater, so as far as possible to avoid in the run to do slaver expansion.
Briefly summarize the design of master-slave mode:
Advantages: Read and write separation, by adding slaver can improve the ability of concurrent reading.
Disadvantage: Master Write ability is the bottleneck.
While there is no theoretical limit to slaver, maintaining slaver overhead will always become a bottleneck.
The disk size of master will also be a bottleneck in the storage capacity of the entire Redis cluster.
Hash slot:
This stage name looks very literary, but it is not a new technology, his real names are called the Sub-table library, and then the previous figure:
The information you can see on the diagram:
1, the object is CRC16 hashed to a specified node before it is saved to Redis, for example, Object4 eventually hashes to Node1.
2, each node is evenly allocated a slot segment, corresponding to the 0-16384,slot can not be repeated can not be missing, otherwise it will cause the object to be repeatedly stored or unable to store.
3, node also listens to each other, once has node exits or joins, will do the data migration according to the slot. For example, if the Node1 is dropped, 0-5640 of these slot will be spread evenly over the Node2 and Node3, as Node2 and Node3 themselves will not be reassigned in their own body, Therefore, the migration process will not affect the use of the 5641-16384slot segment.
Briefly summarize the advantages and disadvantages of hashing slot:
Disadvantage: Each node undertakes to listen to each other, high concurrent data writes, high concurrency data read out, heavy workload
Advantages: The Redis write operation is distributed to a number of nodes, to improve the ability to write concurrency, simple expansion.
Double Swords Merge:
You see here, you find it, the master-slave and the hash design advantages and disadvantages just is mutually compensates, will graph one each set of master and subordinate corresponds to each node in Figure two, is the Redis cluster's ultimate form, first hash the logical node, then each logical node interior is the master and subordinate, like figure:
Want to expand concurrent read to add slaver, want to expand concurrent write to add master, want to increase the capacity is to add master, any one slaver or a few master hang is not a catastrophic failure.