Don’t tell your girlfriend about technology in any way. You just don’t know the secret of longevity~
Recently, my daughter-in-law suddenly loves to learn. I didn’t expect that she could brush up all kinds of algorithms and architecture problems, and take care of her children day and night. It seems to be booming, but long-term survival experience tells me that this is not a good thing. If things go wrong, there will be demons~
A tester does not change his pattern to find bugs. He starts to study the code and wants to make bugs. He’s a little anxious. However, it’s good to be eager to learn anyway. I cheat her at this level, which is not the same as bullying primary school students.
That day, he suddenly asked me, “what is it
zookeeper“Herding behavior in China, I’m a little surprised. The question is very thorough. It seems that I’ve learned it seriously this time. We have to speak quickly. We can’t stop people’s enthusiasm for study.
In fact, it’s a very simple concept. Herding is very common
zookeeperIt occurs in the scene of implementing distributed lock, and it is recommended that I have never touched it
ZKThe students in the class will learn the basic knowledge firstUnderstanding the core knowledge of zookeeper, analyze it
zookeeperThe principle of implementing distributed lock is easier to understand. See the figure below:
zookeeperThe unique data structure similar to the file system can create nodes at will just like creating a folder
my_lockNode can also store data and generate ordered self increasing node ID
my_lock_00000001 .... my_lock_0000000NAnd so on. In this way, the smaller the node serial number ID created first, and whose node ID is the smallest is regarded as getting the lock. After the node getting the lock processes the business, delete the corresponding node and release the lock.
The thread that didn’t get the lock passed the setting
my_lockOnce it is found that there is a thread release lock under the node, the child node is deleted, and the rest nodes are deletedAll threadsRecapture
my_locklowerAll child nodesCompare whether its own node is the smallest, and the smallest node will get the lock. Repeat this until all threads get the lock.
In this way, there is a phenomenon. In the whole process of distributed lock competition, there are a large number of repeated actions, and most of them are invalid operations. It judges that it is not the node with the smallest serial number, so it continues to wait for the next notification. This is the so-called“
Herd Effect ”。
If the number of nodes is enough, when a node is deleted, a large number of clients listen at the same time and compare whether their own nodes are the smallest, a lot of network overhead will be generated, which will greatly reduce the cost of the whole network
zookeeperTherefore, the existing distributed locks must be optimized, as shown in the following figure:
Since you only want to judge whether you are the smallest node, when comparing, for example
my_lock_00000002When you find that you are not the smallest node, you only need to find the previous node
watcherMonitor it. When
my_lock_00000001Release the lock to delete the node, the node is notified
my_lock_00000002It’s your turn to take the lock, and so on. In this way, orderly monitoring is solved“
Herd Effect ”。
Let’s talk to myself for a long time. I asked people if they understood. She said, “if you understand, why don’t you say it again?”?
For this kind of player whose face value is higher than intelligence quotient, I decided to change a way of explaining and move her with a story~
Cough, cough, cough, here we go
Some day in the future, rich boy（
ZK）When I opened my eyes, I suddenly found that I had gone through the university days, lying on the dormitory bed of a normal university, and my face was changed into Wu’s. This makes the original barren face suddenly reach the peak, no longer because he is the only boy in the class, but no girl likes and inferiority.
Shuai guishuai class still has to be held. Unfortunately, he was late for class that day. As soon as Fu Zai opened the door of the ladder classroom, a beautiful woman suddenly screamed, “look, Fu Zai is so handsome today!”, Suddenly there was a commotion in the house, and everyone looked around and looked at each other.
All of a sudden, all the beauties rushed at him in a swarm. At this time, there was a man named Yang（
Thread 1）The beautiful woman is quick in eyes and hands. She grabs his hand and asks if she can go for a walk on the playground with her（
Handling business）Fu Zai is a soft hearted person. He agrees as soon as he looks pitiful. Yang immediately takes him by the hand and runs to the playground. The other beauties returned to their seats with a slight loss.
Ten minutes later, after finishing what he had to do, Fu Zai was still absorbed in his studies and insisted on going to class. He went back to the door of the classroom, released Yang’s hand and was ready to go to his seat.
At this time, the beauties swarmed up again. This time, it was a girl named Tang Yiyan（
Thread 2）The beautiful woman got it. She asked Fu Zai if he could also accompany her for a walk. Fu Zai saw that she was not so good-looking and politely refused（
Not the smallest）。
Zheng Mou Shuang behind（
Thread 3）A push away Tang Yiyan hold rich son’s hand, ask can accompany her, rich son looked at this sister face value is good, decisively agreed~
After several times like this, the instructor（
ZK cluster service）I can’t see it any more. I negotiate with Fu Zi severely. Although your appearance is amazing, you can’t affect the classroom discipline. Students can’t practice 100 meter sprint in the classroom every day. They can’t concentrate on their study.
Rich boy thought it was very reasonable, told the girls not to stare at themselves every day, or to concentrate on learning.
So I put the number for all the girls in the class, and arranged the duty table. Who gets the number in the front has the priority to get the rich boy’s right to walk, and the people behind just have to keep an eye on it（
watcher）Just take the one in front of her. The one in front of her walks around, and the one in the back keeps up. In this way, the rich boy begins his shameless college days.
Me: do you understand this time?
Pop~A bus slapped me in the head
Grumpy girlfriend: what did you do on the playground?
Irritable girlfriend: do you have this idea for a long time? Do you want to be an emperor, ah!?
The above stories are purely fictional. If they are similar, they will be regarded as your criticism
Several hundred e-books have been sorted out, and students in need can pay attention to the official account.Something inside the programmer]ReplyTake it from yourself. And if you want to add technology group, you can add my friends, talk about technology with big guys, push from time to time, and do some internal things for programmers.
This work adoptsCC agreementReprint must indicate the author and the link of this article