当前位置:网站首页>Redis cluster mget optimization
Redis cluster mget optimization
2022-06-12 21:21:00 【ZoneTials】
Write it at the front
Ha ha ha ha ha ha ha , This time it comes again redis,redis For all of you , Must have been familiar with it , The author recently encountered a problem when doing high concurrency , It's just one. http Interface , Carry one inside list ~ a, And then through a from redis Get data in , Considering the large amount of data , Later it added redis colony , But during the visit , It uses redisTemplate Of mget, No matter how you optimize it , The performance is on the second level , For cache reads , This magnitude is basically obsolete , So start somewhere else .
Performance test background
The data provided by the project is inserted into the interface redis-cluster Insert 1000 Bar record , And then through key Set of from redis-cluster Get data in .
Effect comparison
Before optimization
redisTemplate.mget
Like a query 1000 Data 2245ms There is no problem returning , A single average is 2245ms/1000=2.245ms, Pretty good , But for a highly concurrent scenario ,http Interface , It's just rubbish , Not at all . The average Internet company is interested in , If it is To C Interface of products , Required RT All are 200 Inside , Give up this kind of .
After optimization
Rewrote jedis Of get, And join in pipeline
Return the data
Cause analysis
about redisTeplate Implementation principle of , I won't repeat it here , Next, analyze the implementation principle after the transformation from the root , before this , Let's get to know redis An important attribute of clustering slot
stay redis In the cluster , The primary storage location for data , every last key Must correspond to one slot In the middle , The specific algorithm is CRC16(key) Algorithm , The flow is as follows: , See
redis.clients.util.JedisClusterCRC16#getSlot(java.lang.String)
CRC16 Algorithm
Implement source code analysis
Ideas : First find out what key Which one is it slot in , And then through jedispool Get jedis, Every one here jedispool Corresponding to one redis example , from jedis Pass through pipeline Way to obtain , Get the results , Do it again merge
The following is a graphic representation of
1: take keys Mapping to jedispool,com.zcc.testrediscluster.jedis.SelfDefJedisSlotBasedConnectionHandler#getJedisPoolFromSlot This method works in native jedis There is no , We rewrote .
keys Mapping to jedispool
2: Rewrite native jedisHandler
Add one getJedisPoolFromSlot Method
3: Put this handler Trusteeship spring
bean trusteeship
4: Interface call
from redis Get the value
obtain jedis-pipeline
Data merging
Data collation
summary
The above results fully illustrate the importance of reading source code , When doing high concurrency , It highlights how important the source code is , If you don't go deep into the source code , When doing performance optimization , It's also a headache , The above implementation refers to Sohu open source cache-cloud design idea , While practicing , hold cache-cloud The source code of is also rolled out , Gain a lot , Will learn a lot from others , Suddenly I remembered Newton's words " If I look further , Because I stand on the shoulders of giants " Mutual encouragement ~
边栏推荐
- zgc的垃圾收集的主要阶段
- Successful transition from self-study test halfway, 10K for the first test
- EU officially released the data act, Ukraine was attacked by DDoS again, kitchen appliance giant Meiya was attacked, internal data leakage network security weekly
- Junda technology is applicable to "kestar" intelligent precision air conditioning network monitoring
- #141 Linked List Cycle
- 重排数列练习题
- Test basis: unit test
- JS deep and shallow copy
- Library cache lock brought by add trandata
- ASCII code comparison table
猜你喜欢

Risk control modeling X: Discussion on problems existing in traditional modeling methods and Exploration on improvement methods

Data visualization - histogram

Lintcode:127. Topology sorting

#141 Linked List Cycle

新品发布丨竣达智能综合环境监测终端

Leetcode: 210. Programme II

What are the disadvantages of bone conduction earphones? Analysis of advantages and disadvantages of bone conduction earphones

Vs2017 environmental issues

Junda technology is applicable to "kestar" intelligent precision air conditioning network monitoring

Design and practice of Hudi bucket index in byte skipping
随机推荐
Scope and scope chain
How to implement overloading in JS
Is it safe to open an account in flush? How to open an account online to buy stocks
Data visualization - biaxial comparison effect
二分查找
Access control system based on RFID
leetcode:207. 课程表
ASCII 码对照表
[tutorial] detailed explanation of the page rules parameter settings of cloudflare CDN
How to improve communication efficiency during home office | community essay solicitation
好数对的求解
Sorting out the knowledge points of primary and secondary indicators
Research Report on market supply and demand and strategy of China's hydraulic injection molding machine industry
Lua pattern matching
Mxnet record IO details
中小型机房动力环境综合监控解决方案
结构体知识点all in
Algorinote_ 2_ Main theorem and Akra bazzi theorem
Test basis: unit test
The salted fish has been transmitted for 5W times, and the latest spring recruit face-to-face test questions of bytes have been leaked