In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
For the performance optimization of Redis, we mainly start from the following aspects:
First and foremost, make sure that Redis is not asked to execute time-consuming commands
Use pipelining to combine execution of continuously executed commands
When using pipelining, you only need to send multiple commands from the client to Redis at a time (separated by\ r\ n), and Redis will execute these commands in turn and assemble the returns of each command in order, such as:
$(printf "PING\ r\ nPING\ r\ nPING\ r\ n"; sleep 1) | nc localhost 6379+PONG+PONG+PONG
The Transparent huge pages (large memory pages) feature of the operating system must be turned off, or it may cause redis latency and memory usage problems:
Echo never > / sys/kernel/mm/transparent_hugepage/enabledecho never > / sys/kernel/mm/transparent_hugepage/defrag
If you run Redis in a virtual machine, there may be inherent delays in the virtual machine environment. You can see the inherent delay with the. / redis-cli-- intrinsic-latency 100command. At the same time, if there are high requirements for the performance of Redis, Redis should be deployed directly on the physical machine as far as possible.
Check the data persistence policy
Consider introducing read-write separation mechanism
Replace keys with scan because keys blocks redis's single thread
Cluster fragmentation
Why do you want to do cluster fragmentation:
The amount of data stored in Redis is so large that the physical memory of a host can no longer be accommodated.
Redis has a large number of write requests concurrently, and a Redis instance cannot be hosted.
When the above two problems arise, it is necessary to fragment the Redis.
There are many kinds of sharding schemes for Redis. For example, many Redis clients implement sharding function on their own, and there are also Redis sharding schemes implemented in a proxy way such as Twemproxy. However, the preferred solution should also be the Redis Cluster fragmentation scheme officially launched by Redis in version 3.0.
This article will not introduce the specific installation and deployment details of Redis Cluster, focusing on the benefits and disadvantages of Redis Cluster.
The ability of Redis Cluster
Ability to automatically distribute data across multiple nodes
When the accessed key is not on the current shard, the request can be automatically forwarded to the correct shard
Services can still be provided when some nodes in the cluster fail.
The third point is based on master-slave replication. Each data fragment of Redis Cluster adopts the structure of master-slave replication, and the principle is completely the same as the master-slave replication described above. The only difference is that the extra component of Redis Sentinel is omitted, and Redis Cluster is responsible for node monitoring and automatic failover within the fragment.
Redis Cluster slicing principle
A total of 16384 hash slot,Redis in Redis Cluster will calculate the CRC16 of each key, and compare the result with 16384 to determine which hash slot the key is stored in. At the same time, you need to specify the number of Slot for each data shard in the Redis Cluster. The allocation of Slot can be reassigned at any point in time.
When the client reads and writes to the key, it can connect to any shard in the Cluster. If the operating key is not within the Slot range for which the shard is responsible, the Redis Cluster will automatically redirect the request to the correct shard.
Data elimination mechanism
Redis provides five data elimination strategies:
Volatile-lru: use the LRU algorithm for data elimination (eliminate the key with the earliest last use and the least), and only eliminate the key with the validity period set
Allkeys-lru: using LRU algorithm for data elimination, all key can be eliminated.
Volatile-random: random phase-out data. Only key with a validity period is eliminated.
Allkeys-random: random elimination data, all key can be eliminated
Volatile-ttl: phase out the remaining key with the shortest validity period
It is best to specify an effective data elimination strategy for Redis to match the maxmemory settings to avoid write failures after memory is full.
In general, the recommended strategy is volatile-lru and recognize the importance of the data stored in Redis. For those important data that can never be discarded (such as configuration data, etc.), the validity period should not be set, so that Redis will never eliminate the data. For data that is relatively less important and can be hot loaded (such as caching recently logged-in user information, and the program will read it in DB when it cannot be found in Redis), you can set the validity period so that Redis will eliminate this data when there is not enough memory.
Configuration method:
Maxmemory-policy volatile-lru # defaults to noeviction, that is, no data elimination
Reference material https://www.cnblogs.com/276815076/p/7245333.html for this article
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.