Redis several common use

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/weixin_44018338/article/details/102740284

Common use

 

Redis several common use include:

  • Redis single copy

  • Redis multiple copies (master and slave)

  • Redis Sentinel (Sentinel)

  • Redis Cluster

  • Redis self-development

 

 

The advantages and disadvantages of various ways of using

 

 

 

Redis single copy

 

 

Redis single copy, Redis using a single node deployment architecture, there is no real-time synchronization of data backup node, do not provide data persistence and backup strategy for data reliability of less demanding cache pure business scenarios.

 

 

advantage:

 

  • Simple structure, easy to deploy.

  • Cost-effective: no spare node (single instance or supervisor can use crontab availability guarantee) when using the cache, of course, in order to meet the high availability of business can also sacrifice a spare node, but at the same time there is only one instance of external services.

  • high performance.

 

Disadvantages:

 

  • It does not guarantee the reliability of the data.

  • Use the cache, restart the process after the data is lost, even if there is a spare node address high availability, but still can not solve the problem of cache warming, and therefore not suitable for high data reliability requirements of the business.

  • High performance is limited by the processing capability of a single-core CPU (the Redis is single threaded mechanism), the main CPU bottleneck, so for simple operation command, ordering, less computation scene. You may also consider an alternative use Memcached.

 

 

Redis multiple copies (master and slave)

 

 

Redis multiple copies, using the master deployment from (replication) structure, compared to the single copy of the terms of the biggest feature is the master synchronization between instances from real-time data and provides data persistence and backup strategy.

 

Master-slave instances deployed on separate physical servers, according to the company's foundation environment configuration can be achieved at the same time provide services and separate read and write policies.

 

advantage:

 

  • High Reliability: In one aspect, the use of dual-standby architecture can be performed when the primary database fails automatic switchover, from the library to a primary library provides services to ensure smooth operation of the service; on the other hand, data persistence feature is turned on and configure a reasonable backup strategy, can effectively solve the abnormal data misuse and data loss problems.

  • Separate read and write strategies: the ability to read from a node can expand the master database node, to effectively deal with a large amount of concurrent reads.

 

Disadvantages:

 

  • Recovery complex, if not Redis HA system (Development needs), when the primary database node fails, the need to manually a promoted to master node from the node, and the need to inform the business side configuration changes, and need to let others to copy from the library node new main library node, the whole process requires human intervention, more complicated.

  • The ability to write stand-alone main library is limited, consider fragmentation.

  • Main library storage capacity is limited stand-alone, consider Pika.

  • Original copy of the shortcomings will be more prominent in earlier versions, such as: Redis replication after interruption, Slave initiates psync, at this time if the synchronization is not successful, the whole amount will be synchronized, the main library to perform full backup at the same time may cause milliseconds or second level of Caton.

Also, because COW mechanisms leading to the main library memory overflow in extreme cases, the program quit unexpectedly or down; the main library node generates a backup file causes the server disk IO and CPU (compression) resource consumption; send several GB in size causes the server to export a backup file the bandwidth surge, block the request, it is recommended to upgrade to the latest version.

 

 

Redis Sentinel (Sentinel)

 

 

Redis Sentinel is a community version of the launch of native high-availability solution, the deployment architecture consists of two parts: Redis Sentinel Redis data clusters and clusters.

 

Wherein the Redis Sentinel Sentinel cluster is composed of several nodes of a distributed cluster can achieve fault detection, fault auto-transfer, distribution center, client notification. Redis Sentinel node number to satisfy 2n + 1 (n> = 1) is an odd number.

 

 

advantage:

  • Redis Sentinel cluster deployment simple;

  • Redis master switch can solve the problem of high availability mode;

  • Linear expansion is easy to achieve Redis data node, easily break Redis own single-threaded bottleneck, can greatly satisfy Redis large-capacity or high-performance business requirements;

  • You can achieve a Sentinel Redis monitor a data node or set of data nodes.

 

Disadvantages:

  • Redis master-slave mode relative to deploy more complex, more complicated understanding of the principles;

  • Waste of resources, Redis data node slave node as the backup node does not provide services;

  • The Sentinel Redis Redis mainly for high availability switching data node of the master node, a node of the Redis data offline to do failure determination of subjective and objective offline into two kinds, for Redis node from the node has to make a subjective operation offline not failover.

  • Separate read and write can not solve the problem, it is relatively complex to implement.

 

Suggest:

  • If the same service monitor can select a plurality of sets of program Sentinel Redis cluster monitor data node, otherwise choose a program Redis Sentinel monitor a data node.

  • sentinel monitor <quorum> configuration <quorum> <master-name> <ip> <port> recommendations provided Sentinel node plus a half, when the plurality of IDC Sentinel deployed, the number of single IDC Sentinel deployment is not recommended more than (number of Sentinel - quorum).

  • Reasonable set parameters, to prevent accidental cut, the control switch sensitivity control:

    a. the

    b. down-after-milliseconds 30000

    c. failover-timeout 180000

    d. maxclient

    e. timeout

  • Each node server deployment time to be synchronized as much as possible, otherwise the timing of the logs will be chaos.

  • Redis recommended multi-keys and pipeline operations, reducing the number of RTT, improve the efficiency of the request.

  • Get their own distribution center (zookeeper), to facilitate client access to the link instance.

     

 

Redis Cluster

 

 

Redis Cluster Community Edition is launched Redis distributed cluster solutions, mainly to address the needs of distributed aspect of Redis, for example, when faced with a stand-alone memory, concurrency and flow bottlenecks, Redis Cluster can play a good load balancing purpose.

 

Redis Cluster minimum configuration of the node cluster node 6 or more (the third main 3), wherein the master node provides read and write operations, the node as a backup node, the request is not available, use only as a failover.

 

Redis Cluster virtual partition grooves, all keys are mapped to an integer of from 0 to 16,383 slot hash function, each node is responsible for maintaining a portion of the key groove and the groove data is mapped.

 

advantage:

  • None center architecture;

  • Slot in accordance with the data stored a plurality of distributed nodes, sharing of data between nodes, may be dynamically adjusted data distribution;

  • Scalability: 1000 linearly extended to multiple nodes, the nodes may be dynamically added or deleted;

  • High availability: partial node is not available, the cluster is still available. By increasing the Slave do standby copies of data, failure to achieve automatic failover, between nodes exchange status information through gossip protocol to complete the Master Slave to enhance the role by voting mechanism;

  • Reduce operating costs, improve scalability and availability of the system.

 

Disadvantages:

  • Client achieve complex drive requirements to achieve Smart Client, the cache slots mapping information and to update and improve the difficulty of developing, immature affect the stability of the client's business. Currently only JedisCluster relatively mature, exception handling part is not perfect, such as the common "max redirect exception".

  • Node blocking occurs for some reason (blocking time is greater than clutser-node-timeout), it is determined offline, such failover is unnecessary.

  • Asynchronous data replication, does not guarantee strong data consistency.

  • When multiple business using the same set of clusters, can not distinguish between hot and cold data based on statistics, resource isolation is poor, the situation is prone to influence each other.

  • Slave in the cluster acts as "cold standby" and can not read relieve the pressure, of course, possible to improve the utilization of resources through rational design Slave SDK.

  • Key restriction batch operations, such as the use mset, mget currently only supports Key slot value is performed with the same batch operation. For mapped to a different slot values ​​due Keys Key does not support cross-slot query, so execution mset, mget, sunion and other operations support unfriendly.

  • Key Operational Support Services limited, only supports multi-key affairs operations on the same node, when multiple Key distributed on different nodes can not use the transaction functions.

  • Key as minimum particle size of the data partition can not be an object such as a large key hash, list, etc. mapped to different nodes.

  • Does not support multi-database space, redis in stand alone can support up to 16 databases, can only use a spatial database clustered mode, namely db 0.

  • Copy the structure supports only one, can only be copied from the master node node, replication does not support nested tree structure.

  • Avoid hot-key, resulting in the master system database node becomes short board.

  • Avoid big-key, resulting in network card explode, slow queries and so on.

  • Retry time should be greater than cluster-node-time time.

  • Redis Cluster not recommended multi-keys and the pipeline operation, reducing max redirect generated scene.

     

 

Redis self-development

 

 

Redis self-development of high-availability solutions, mainly in the central configuration, fault detection and failover handling mechanism, usually need to be customized according to the actual environment of their business online.

 

 

 

advantage:

  • High reliability and high availability;

  • High self-control;

  • Bonded to the actual needs of the business, yieldable resistance, good compatibility.

 

Disadvantages:

  • Implement complex, high development costs;

  • The need for the support of neighboring facilities, such as monitoring, domain name service database to store metadata information such as;

  • High maintenance costs.

     

 

Guess you like

Origin blog.csdn.net/weixin_44018338/article/details/102740284