当前位置:网站首页>A debugging to understand the slot mechanism of redis cluster
A debugging to understand the slot mechanism of redis cluster
2022-07-01 21:57:00 【mariolu】
Once I was testing redis colony ( The redis The cluster uses a batch intel Performance hardware aep), In order to find out the upper limit of performance before going online . So there is the following story .
Under normal circumstances , Because I don't have so many machines to fight redis colony , So I went to seek the help of the pressure testing platform of the testing department , To get large traffic ( In order to simulate the real online , The traffic recorded by bypass is used for playback ), But because the pressure test platform is for business services ( request pb The format is customized by business ), Without this redis Read write pressure measurement function . So we still have to rely on service , But there are not many service machines in our bypass test environment . So there are big data students' suggestions , Can your data all reach the same slot.
Well, this redis Of slot I heard , But I don't know much about , Because I only need one connection at ordinary times url+ The port is done . For example, the following configuration
So , Use gdb Open the service process , Go inside and spy slot How it works
gdb --args ./SearchUserFeatureServer --flagfile=conf/gflags.conf
Set breakpoints , Can press r, Start exploring
First of all, I found that when initializing the connection ,redis Will respond to , Return connection information like this
f2a9484ec91a9007863d015e2f72146940477efb 10.194.88.141:[email protected] master - 0 1656591917000 33 connected 656-1311
It describes
<id><ip:port><flags><master><ping-sent><pong-recv><config-epoch><link-state><slot><slot>...<slot>
So my code will look for this slot, Then proceed slot Of redis node Mapping of nodes . In the end, I'll put this 16384 The array of elements is full .
It's in the code int slot_ipport_index_vec[16384].
First of all, the cluster I connected has 24 individual node, One of them node The information is as follows : His beginning slot yes 656, End slot yes 1311
Each paragraph slot The interval is 656, This 656 It's based on 16384 individual slot Count /24 individual node Got . Look at this 16384 An array , He is evenly distributed 24 individual node. Every node Monopolize a period slot.
First of all, I will go and redis Connect , Then he'll tell you redis How many node
And then this node The quantity will be used as the divisor ,16384/node Count =slot Section
Then each slot Intervals are all connected by the same node . Put this 16384 Divided into 0-655,656-1311,…
Subsequent requests will be based on key Of crc32 Figure out one. hash value , Project to this hash On the ring , Decide which node to use
This is a request key Come in , according to crc16 Do simple hash value calculation
The request will be based on hash Calculate to fall in 16384 The final node of an array of elements , It's like a hash Ring ,node Project once , request key Project once , Then find the intersection
But what I see is and redis establish init The process of , I don't know if it will be added or reduced later node How did you handle it , This needs further study ~
边栏推荐
- [monomer] recommended configuration of streaming information i-bpsv3 server
- 天气预报小程序源码 天气类微信小程序源码
- I received a letter from CTO inviting me to interview machine learning engineer
- Fundamentals - IO intensive computing and CPU intensive computing
- 一次调试去了解redis集群的slot机制
- 薛定谔的日语学习小程序源码
- leetcode刷题:栈与队列03(有效的括号)
- Manually implement function isinstanceof (child, parent)
- Halcon知识:三维重构的一个尝试
- 个人炒股怎样开户?安全吗。
猜你喜欢
随机推荐
在技术升级中迎合消费者需求,安吉尔净水器“价值战”的竞争之道
焱融看 | 混合云时代下,如何制定多云策略
基于K-means的用户画像聚类模型
统计字符中每个字符出现的个数
AIDL基本使用
游览器打开摄像头案例
使用闭包实现点击按钮切换 toggle
MySQL清空表数据
浏览器tab页之间的通信
List announced | outstanding intellectual property service team in China in 2021
手动实现function isInstanceOf(child,Parent)
最近公共祖先(LCA)在线做法
BlocProvider 为什么感觉和 Provider 很相似?
PMP与NPDP之间的区别是什么?
Difference and use between require and import
Simple interactive operation of electron learning (III)
leetcode刷题:栈与队列03(有效的括号)
News classification based on LSTM model
MIT|256KB 内存下的设备上训练
An operation tool used by we media professionals who earn 1w+ a month