当前位置:网站首页>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-1311It 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 ~
边栏推荐
- 分离字符串中的字母和数字并使得字母在前数组在后
- Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud
- 辅音和声母的区别?(声母与辅音的区别)
- [monomer] recommended configuration of streaming information i-bpsv3 server
- 统计字符中每个字符出现的个数
- 【单体】流辰信息I-BPSv3服务器推荐配置
- NIO与传统IO的区别
- BC35&BC95 ONENET MQTT(旧)
- [NOIP2013]积木大赛 [NOIP2018]道路铺设 贪心/差分
- 杰理之、产线装配环节【篇】
猜你喜欢
随机推荐
基础—io密集型计算和cpu密集型计算
PHP 读取ini或env类型配置
require与import的区别和使用
JS how to get a list of elements in a collection object
杰理之、产线装配环节【篇】
MIT|256KB 内存下的设备上训练
杰理之蓝牙耳机品控和生产技巧【篇】
burpsuite简单抓包教程[通俗易懂]
BC35&BC95 ONENET MQTT(旧)
ngnix基础知识
旁路由设置的正确方式
二叉树的基本操作
Pytest Collection (2) - mode de fonctionnement pytest
从20s优化到500ms,我用了这三招
leetcode刷题:栈与队列03(有效的括号)
测试撤销1
What is the difference between consonants and Initials? (difference between initials and consonants)
物联网rfid等
《QTreeView+QAbstractItemModel自定义模型》:系列教程之三[通俗易懂]
人才近悦远来,望城区夯实“强省会”智力底座









