Popular Weibo sorting algorithms

Source: Internet
Author: User
I have a Weibo table that records the likes, forwards, and comments. Now I want to optimize popular sorting algorithms. Q: saved hot values: I used to have a field _ hot in the Weibo table to indicate the heat, which is updated every 60 minutes. In this way, the field is directly sorted by _ ho... I have a Weibo table that records the likes, forwards, and comments. Now I want to optimize popular sorting algorithms.

Q: How to save the hot value: I used to have a field in the Weibo table _ hot to indicate the heat, which is updated every 60 minutes, in this way, you can directly sort by the _ hot field. In this way, time decay can be achieved to a certain extent.
You can also share the updated algorithm with us:

UPDATE microblog as v SET _hot = LOG10((_zan*2+_com*5+ _tran*3))+(unix_timestamp(v._createtime)-unix_timestamp(\'2008-12-01 00:00:00\'))/100000;

The problem is also obvious:
Every 60 s, we perform complex calculations on each record of a 4 W + record table, which consumes too much CPU.

A: the solution I want to achieve is to SELECT the data, put the calculation in the code, and then UPDATE it back.

I wonder if there is any better way? How can I implement it in my own way?

Reply content:

I have a Weibo table that records the likes, forwards, and comments. Now I want to optimize popular sorting algorithms.

Q: How to save the hot value: I used to have a field in the Weibo table _ hot to indicate the heat, which is updated every 60 minutes, in this way, you can directly sort by the _ hot field. In this way, time decay can be achieved to a certain extent.
You can also share the updated algorithm with us:

UPDATE microblog as v SET _hot = LOG10((_zan*2+_com*5+ _tran*3))+(unix_timestamp(v._createtime)-unix_timestamp(\'2008-12-01 00:00:00\'))/100000;

The problem is also obvious:
Every 60 s, we perform complex calculations on each record of a 4 W + record table, which consumes too much CPU.

A: the solution I want to achieve is to SELECT the data, put the calculation in the code, and then UPDATE it back.

I wonder if there is any better way? How can I implement it in my own way?

Conclusion:

The intensive computation is reduced to make full use of the Failover performance.

Statement:

First, you can merge your algorithms. Computation is entirely feasible.x*10^yWherex = _zan2+_com*5+ _tran*3,y = unix_timestamp(v._createtime)/100000.

Of course, I think 100000 should be changed to 604800 (that is7 * 24 * 60 * 60), Or change "10" to "2" to make the test easier.

So you accept my suggestion and usex*2^y. I'm not familiar with this formula. It's not just a floating point... Of course, we still need to adjust the area of x. At this time, as long as the other x corresponds to [1, 10) (in actual operation, you only need to take the first digit, and then add the digit ). Add/Remove Multiple shards/non-shards to y-grams.

So, how do you sort floating point data. Root does not need to calculate the x * 2 ^ y.

First of all, you don't need to take an exam on the positive question. Then, it means that the binary progressive representation of a number is larger, and the floating point value is larger, that is, the larger y value.

Y is similar to limit x. (Note that x y in this example is not the first one ).

Of course, the reason is that, when the original y-foot conference was large, x's influence on it could be ignored. Therefore, Weibo does not need to take an exam for a certain period of time.

So the only thing you must know is x and y. Y does not conform to the requirements. Y matches the condition and then adds the number of x (in Binary Notation. If the ratio is y and y is equal, the exact calculation is x and the ratio is x. (That is to say, at the beginning, the calculation of x only determines the number of digits... You do not need to know the exact value at all ).

So now, only y, a part of x digits, and a specific x exact value must be known.

So how can we quickly calculate the number of digits of x? Let us go to bed and tell you again.

In fact, there is no need to calculate the speed of the x-digit number, because the calculation of x is very simple and simple... You only need to update x when using the cursor, forum, and Forum. Hey, just upgrade y... In fact, you don't need to store x at all. You just need to store a y + (number of digits of x. The precision value of x is very low. Let's talk about it later...

And so on. In fact, all of the above can be destroyed.

You only need to update it when _ hot is possible. The intensive computation is reduced to make full use of the Failover performance. However, it was a waste of time, but it was avoided.

So it is better to extend the renewal and update? Every time the last update is over 60 s, it will be updated again. Or is it possible to submit the computation _ hot task to the client-side js for a classified computation? In order to ensure the availability of the product, we can calculate the name of the product before it is listed.

I remember a post about popular algorithms some time ago. If the data volume is very large, it is inappropriate to directly sort and perform other operations,

You can create a table to save Hot data. Each time you obtain data from the master table, the number of accesses to the master table is updated, and the obtained data is compared with the minimum value in the hot data table, if the value is smaller than, no operation is performed. If the value is greater than, hot tables are inserted and sorted.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.