1, increase memory;
2,Use memory phasing strategy.
3,RedisCluster.
Focus on introduction23;
The2point:
We know,redisSet the configuration filemaxmemoryParameters that can control its maximum available memory size (bytes).
Then when the memory required, more thanmaxmemorywhat to do?
At this time, the configuration filemaxmemory-policyAppeared.
Its default value isnoeviction。
Below I will list the deletes when the available memory is insufficientredisKeys have elimination rules.
Rule name |
Rule description |
volatile-lru |
useLRUThe algorithm deletes a key (only for keys that have set the survival time) |
allkeys-lru |
useLRUThe algorithm deletes a key |
volatile-random |
Randomly delete a key (only for keys whose survival time is set) |
allkeys-random |
Randomly delete a key |
volatile-ttl |
Delete the last key of survival time |
noeviction |
No key is deleted, only errors are returned |
LRUalgorithm,least RecentlyUsed,Algorithms are used recently. That is to say, the keys that are least recently used are deleted by default.
butBe sure to pay attention!redisThe key that is least recently used among all keys is not accurately deleted, but is randomly selected.3One key, delete the least recently used key of these three keys.
So3This number can also be set, the corresponding position is in the configuration filemaxmeory-samples.
The3point:
3.How to do a cluster
RedisOnly support single instances, the memory is generally up to 10~20GB. For systems with 100~200GB memory, they need to be supported through clusters.
RedisThere are three ways to cluster:Client sharding、Agent sharding、RedisCluster(I will explain it in detail in the following article. )
· Client sharding
Implement your own routing through business code
Advantages: You can control the sharding algorithm yourself, and the performance is better than that of the proxy
Disadvantages: high maintenance cost, expansion capacity/ShrinkageAll operations require your own research and development
· Agent sharding
The agent receives data requests from the business program and distributes these requests to the correct one according to the routing rules.RedisThe instance is returned to the business program. Use similarTwemproxy、Codismiddleware implementation.
Advantages: Easy to operate and maintain, and you don’t have to worry about how to link the programRedisExample
Disadvantages: It will cause performance consumption (approximately20%), cannot be smoothExpand capacity/Shrinkage, script migration data needs to be executed, which is inconvenient(CodisexistTwemproxyBased on the optimization and pre-slicing is implemented to achieveAuto Rebalance)。
· Redis Cluster
Advantages: Official cluster solution, no center nodes, direct connection with the client, good performance
Disadvantages: The solution is too heavy and cannot be smoothExpand capacity/Shrinkage, the corresponding script needs to be executed, which is inconvenient and too new, and there are no corresponding mature solutions.