Never explain to your girlfriend what "herd effect" is

Don't tell your girlfriend about technology in any way, you just don't know if you ask, the secret of longevity~

My daughter-in-law suddenly loves to study recently. I have no idea that I have the energy to bring my baby around day and night with all kinds of questions about algorithms and architecture. It seems to be thriving, but long-term survival experience tells me that this is not a good thing, and there will be monsters when things go wrong~

insert image description here

A tester keeps looking for bugs, starts to study the code and wants to create bugs. He is a little eager to turn around, but anyway, eager to learn is a good thing. I'm fooling her at this level, it's not the same as bullying elementary school students.

Suddenly asked me that day: "What is zookeeperthe herd effect?", I was a little surprised, and the question was very in-depth. It seems that this time I have learned it seriously. That has to be said quickly that it can't dispel people's enthusiasm for learning.

In fact, this is a very simple concept. The herd effect often zookeeperoccurs in the scenario of implementing distributed locks. It is recommended that ZKstudents who have not come into contact with them first remediate the basic knowledge "One article thoroughly understand the core knowledge points of zookeeper" , and analyze the zookeeperrealization of distributed locks . The principle is easier to understand, see the following figure:

Ordinary distributed lock

Using zookeepera unique file system-like data structure, nodes can be created at will like a folder, my_locksub-nodes can be created under nodes, nodes can also store data and generate orderly and self-incrementing node IDs my_lock_00000001 .... my_lock_0000000N, etc. In this way, the node ID created first will be smaller, and whoever has the smallest node ID will be deemed to have obtained the lock. The node that has obtained the lock will delete the corresponding node and release the lock after processing the business.

The thread that does not get the lock can set the watchermonitoring node my_lock. Once it is found that there is a thread under the node that releases the lock and deletes the child node, all threads re-acquire whether allmy_lock the child nodes are the smallest. until all threads have acquired the lock.

In this way, a phenomenon occurs. In the entire distributed lock competition process, there are a large number of repeated operations, and most of them are invalid operations. It is judged that it is not the node with the smallest serial number, so it continues to wait for the next notification. This is called " 羊群效应".

If the number of nodes is large enough, when a node is deleted and a large number of clients listen at the same time and compare whether its own node is the smallest, a large amount of network overhead will be generated, which will greatly reduce zookeeperthe performance of the entire cluster, so the existing distributed locks must be implemented. Optimization, as shown below:

Optimized distributed lock

Since you only want to judge whether you are the smallest node, then every time you compare, for example, after my_lock_00000002finding that you are not the smallest node, you only need to find the previous node my_lock_00000001and watchermonitor it. When you my_lock_00000001release the lock to delete the node, it will notify the node my_lock_00000002that you should take the lock, and other nodes will follow the same analogy, so the orderly monitoring will solve the " 羊群效应".

For a long time, I said hi to myself. I asked people if they understood, and she said: I understand a little bit, why don't you say it again?

For this kind of contestant whose appearance is higher than IQ, I decided to change the way of explaining and impress her with a story~

cough~ cough~ cough~ start

Apply what you have learned

One day in the future, Fu Zai ( ZK) opens his eyes and suddenly finds that he has traveled back to the university days, lying on the bed in a dormitory of a normal college, his face has been changed to Wu Moufan's. This made the originally barren appearance reach the peak all of a sudden, and there is no need to feel inferior because he is the only boy in the class, but he is not liked by girls.

The Shuaiguishuai class is still to be attended. Unfortunately, he was late for class this day. Fu Tsai just pushed open the door of the lecture hall when suddenly a beautiful woman screamed and shouted: "Look, Fu Tsai is so handsome today!" There was a commotion, and everyone looked left and right, looking at each other.

Flock, baa, baa, baa

Suddenly, all the beauties rushed towards him. At this time 线程1, a beautiful woman named Yang Moumi ( ) had quick eyes and fast hands. She grabbed his hand and asked if she could accompany her to the playground for a walk ( 处理业务). Fu Tsai was soft-hearted. , seeing her pitiful appearance, she agreed, and Yang Moumi immediately took his hand and ran to the playground. The other beauties returned to their seats slightly disappointed.

Ten minutes later, after finishing what he had to do, Fu Tsai was still thinking about his studies and insisted on going to class. He returned to the door of the classroom and let go of Yang Moumi's hand, ready to go to his seat.

At this time, all the beauties swarmed up again, this time it was a beauty named Tang Mouyan ( ) 线程2who succeeded, and asked if Fu Tsai could accompany her for a walk . 不是最小.

Zheng Moushuang ( 线程3) at the back pushed away Tang Mouyan and grabbed Fu Tsai's hand, asking if he could accompany her. Fu Tsai saw that this girl looked good and agreed decisively~

After a few times like this, the instructor ( ZK集群服务) couldn't stand it anymore, and negotiated with Fuzi sternly. Although your appearance is amazing, you can't affect the discipline in the classroom. It's not good for the students to practice the 100-meter sprint in the classroom every day. Concentrate on studying.

After thinking about it, Fu Tsai thought it was very reasonable, and told the girls not to stare at themselves every day, but to concentrate on their studies.

So I assigned a number for the whole class and arranged a schedule. Whoever gets the higher number will have priority to get the right to go to the rich boy. The person behind only needs to keep an eye on ( watcher) the person who gets her previous number. After the people strolled around, the people behind quickly followed, and in this way, the rich boy started his university time without shame and shame.

Me: Do you understand this time?

Slap~ A big slap fell on my head

Grumpy Girlfriend: What are you doing in the playground?

I:......

Grumpy Girlfriend: Did you already have this idea, you want to be the emperor, ah! ?

I:......

The above stories are purely fictitious, if there are any similarities, you will be considered a bull

Hundreds of various technical e-books have been sorted out and given to friends. Follow the official account to reply [ 666 ] to get it by yourself. We have established a technical exchange group with some friends to discuss technology and share technical information, aiming to learn and progress together. If you are interested, join us!

insert image description here

{{o.name}}
{{m.name}}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324074005&siteId=291194637