Home  >  Article  >  Database  >  Let’s take a look at the Redis cluster architecture and comparison

Let’s take a look at the Redis cluster architecture and comparison

coldplay.xixi
coldplay.xixiforward
2021-03-12 11:17:052052browse

Let’s take a look at the Redis cluster architecture and comparison

##1、Redis3.0

· advantage

a. No central node

b. Data is stored according to slot Distributed on multiple Redis instances

c. Smooth expansion/ Shrink node

d. Automatic failover(pass between nodes Gossip Protocol exchange status information,The voting mechanism is completed Slave to Master Role improvement)

e. Reduces operation and maintenance costs and improves system reliability Scalability and high availability

(Recommended (free): redis)

·      Disadvantages

##a.

Severely relies on external Redis- Trib

b.

Lack of monitoring and management

c.

Requires dependencies Smart Client(Connection maintenance, Cache routing table, MultiOp and Pipeline Support)

d. Failover

The detection of the node is too slow, not as good as " Central Node ZooKeeper”Timely##e. Gossip

Message overhead f.

Unable to distinguish hot and cold data based on statisticsg. Slave "

Cold Standby, cannot relieve reading pressure

2,

Proxy Redis Cluster

·

advantageSmart Client

a.

Compared with using a proxy, one layer of network is reduced The transmission consumption is high and the efficiency is high. ;b. Adjust at any time.

Proxy

a. Provide a set of

HTTP Restful interface, isolates the underlying storage. Completely transparent to the client, cross-language calls.

b. Upgrade and maintenance are relatively easy. To maintain Redis Cluster, you only need to smoothly upgrade Proxy.

c. Hierarchical storage, the underlying storage is hot and cold heterogeneous storage.

d. Permission control, Proxy can control the whitelist through the secret key and block some illegal requests All filtered out. And you can also control and filter the extremely large Value requested by the user.

e. Security, you can block some dangerous commands, such as Keys, Save, Flush All , etc.

f. Capacity control, capacity limit based on different user capacity applications.

g. Resource logical isolation, based on different users' Key plus prefix, to isolate resources.

h. Monitor buried points and monitor buried points and other information for different interfaces.

· Disadvantages

Smart Client

a. The immaturity of the client affects the stability of the application and increases the difficulty of development.

b. MultiOp and Pipeline have limited support.

c. Connection maintenance, Smart Client pair is connected to each node in the cluster Socket Maintenance.

Proxy

a. The proxy layer has one more forwarding, and the performance is improved. loss.

b. Expansion/When scaling down, operation and maintenance requirements are high, and it is difficult to achieve smooth scaling

3 ,Technical Selection

redisThe official document contains the following passage:

The redis-cli cluster support is very basic so it always uses the fact that Redis Cluster nodes are able to redirect a client to theright node. A serious client is able to do better than that, and cache the map between hash slots and nodes addresses, to directly use the right connection to the right node. The map is refreshed only when something changed in the clusterconfiguration, for example after a failover or after the system administratorchanged the cluster layout by adding or removing nodes.

The general idea is that the current redis cluster official client has simple functions and relies on the redis node Redirect to the redis instance in the cluster where the data is found. There is a need for a more complete client that can achieve consistency hash, failover and cluster management functions. Therefore, using the official redis cluster client is not a wise choice. This article provides 3 solutions for your reference. If there is any problem Wherever it makes sense, everyone is welcome to discuss it with me.

Scheme 1 UsingnginxDeveloped(OpenRestymethod)

The reasons are as follows:

a. SingleMasterMultipleWork mode, each Work follows Redis is also a single-process single-thread mode, and is based on the Epoll event-driven mode.

b. Nginx adopts an asynchronous and non-blocking way to process requests, an efficient asynchronous framework.

c. It takes up less memory and has its own set of memory pool management methods. Gathering a large number of small memory applications together can be faster than Malloc. Reduce memory fragmentation and prevent memory leaks. Reduce memory management complexity.

d. In order to improve the access speed of Nginx , Nginx Uses its own set of connection pools.

e. The most important thing is to support custom module development.

f. In the industry, for Nginx, Redis## The reputation of # can be regarded as two great artifacts. Performance is very good.

Scheme 2 codis(Agent-based redis## adopted by Wandoujia #Cluster scheme)##Reference

codisOfficial Documenthttps:/ /github.com/CodisLabs/codisCodis

is a complete set of caching solutions, including high availability, data sharding, monitoring, and dynamic expansion etc.. is using

Apps->Agent->rediscluster, definitely This method is basically used after scale.

Plan

3 Independent developmentredisSmart client Mainly implements

redis slots management, failover, consistency hash Function.

4、

Redis 3.0Cluster

Redis 3.0The cluster adopts the P2P model, which is completely decentralized. Redis divides all Key into 16384slot, each Redis instance is responsible for part of the slot. All information in the cluster (nodes, ports, slot, etc.), All are updated through regular data exchange between nodes.

RedisThe client makes a request in any Redis instance. If the required data is not in the instance, Guide the client to the desired instance via a redirect command.

Redis 3.0The workflow of the cluster is shown in the figure below.

RedisMachines in the cluster regularly exchange data. The workflow is as follows:

1 Redis The client is in Redis2Access a certain data on the instance;

2In Redis2 found that this data is in the Redis3 instance, sending a redirect to the Redis client Command;

3 Redis After the client receives the redirection command , access the Redis3 instance to obtain the required data.

The cluster solution of Redis 3.0 has the following two problems:

1)       One RedisThe instance has "data storage"andRoute redirection, completely decentralized design. The advantage of this is that deployment is very simple. Just deploy Redis directly, unlike Codis which has so many components and dependencies. But the problem is that it is difficult to upgrade the business painlessly. If one day something serious happens to the RedisBug, you can only roll back the entire Redis cluster.

2)          The protocol has been significantly modified, and the corresponding Redis client also needs to be upgraded. Who can ensure that there are no Bug after upgrading the Redis client? And for businesses that are already running on a large scale online, upgrading the Redis client in the code is also a very troublesome thing.

5、Redis4.0

## (1)Allredisnodes are interconnected with each other(PING-PONGmechanism ), using binary protocol internally to optimize transmission speed and bandwidth;

(2)Fail## of the node #It takes effect only when more than half of the nodes in the cluster detect failures;

(3)

Client and redisNodes are directly connected, no intermediate proxy layer is needed. The client does not need to connect to all nodes in the cluster, just connect to any available node in the cluster;

(4)redis-cluster

maps all physical nodes to [0-16383]slot( slot), cluster is responsible Maintainnode<->slot<->value.

The above is the detailed content of Let’s take a look at the Redis cluster architecture and comparison. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete