当前位置:网站首页>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 ~
边栏推荐
猜你喜欢
以飞地园区为样本,看雨花与韶山如何奏响长株潭一体化发展高歌
【智能QbD风险评估工具】上海道宁为您带来LeanQbD介绍、试用、教程
One of the basic learning of function
leetcode刷题:二叉树02(二叉树的中序遍历)
从MLPerf谈起:如何引领AI加速器的下一波浪潮
杰理之蓝牙耳机品控和生产技巧【篇】
GCC编译
I received a letter from CTO inviting me to interview machine learning engineer
pytest合集(2)— pytest運行方式
leetcode刷题:栈与队列06(前 K 个高频元素)
随机推荐
leetcode刷题:栈与队列07(滑动窗口最大值)
Getting started with the lockust series
leetcode刷题:二叉树02(二叉树的中序遍历)
BlocProvider 为什么感觉和 Provider 很相似?
js如何获取集合对象中某元素列表
杰理之、产线装配环节【篇】
能升职加薪?PMP证书含金量浅析
leetcode刷题:栈与队列01(用栈实现队列)
[deep learning] use deep learning to monitor your girlfriend's wechat chat?
Introduction and download of the latest version of airserver2022
杰理之烧录上层版物料需要【篇】
Classify boost libraries by function
想请教一下,券商选哪个比较好尼?本人小白不懂,现在网上开户安全么?
Wechat applet, continuously playing multiple videos. Synthesize the appearance of a video and customize the video progress bar
PMP证书真的有用吗?
【opencv】train&test HOG+SVM
杰理之关于长按开机检测抬起问题【篇】
PCB线路板塞孔工艺的那些事儿~
杰理之蓝牙耳机品控和生产技巧【篇】
函数基本学习之一