This is a creation in Article, where the information may have evolved or changed.
Golang distributed concurrency---group hotspot elimination algorithm
In the traditional algorithm, in order to calculate the hot spot, the general use, collects all the task list, then sorts, obtains the first n hot spot data. The bad places of this algorithm are:
1, need to collect all the task list. Collection is a problem when the number of tasks is too large
2. Sort the list of tasks. In this procedure, if the list is too large, the sort time is too long.
In addition, if synchronization is required, there will be a pause in this algorithm.
Then we build a scene, an internet café has n locations, everyone can go to the Internet cafes, but the rules, each time can only make an appointment for 1 hours, if the time is up, you can renew for one hours, if not required to give up the location.
Now there are m people to internet cafes.
1, M < n, then m individuals can access to the Internet location
2, when M>n, there are n individuals can get to the Internet location, the remaining people, is waiting
There are two kinds of scheduling algorithms
1, each person, will regularly check their own time, is not to 1 hours, if it is, to determine whether they need to continue to use, the preferential renewal of 1 hours, if not required to give up the location. Wait for the person, then randomly get to this position.
2, everyone, will regularly check their own time, is not to 1 hours, if it is, then give up the position. If you still need to continue to use it in the wait queue and do not need to use it, exit directly.
In this algorithm, it is important to note where there are
1, each user is self-disciplined. Judge yourself whether you need to continue to use, judge whether you have time to expire, etc.
2, it is very important to judge whether to continue to use the standard. For example, when personal contribution to a certain degree, can continue to use.
The simple usage is to sort the contributions of n individuals and eliminate the tail
After a period of time, hot spots are automatically formed.
The advantage of this algorithm is that each individual has a fair and equal opportunity to compete, and only the person with the greater contribution will be able to use the time. This algorithm does not need to be synchronized, which improves the concurrency efficiency.
Hao Haohua
QQ 29185807
November 27, 2014 11:14:01