Imagine a social network that users can share links. Design a system that is able to present the top 100 shared links within the last 5 minutes, top 100 shared links within the last 10 minutes, and so on。
Imagine a social network that users can share links. Design a system that is able to present the top 100 shared links within the last 5 minutes, top 100 shared links within the last 10 minutes, and so on。
|
laoyuanMar 28, 2015
1
每分钟查数据库统计这一分钟内 share数前500的 link,作为增量存到一个表里,然后查这个表就行了,要几分钟查几分钟
|
|
laoyuanMar 28, 2015
2
PHP站长拍脑袋解答
|
|
binuxMar 28, 2015
3
如果你要精确的,将 link 带个时间戳放个队列,要的时候先去掉超过 10 分钟的数据,然后 merge 一下。
如果要实用的,每5秒打个包,同上。 |
|
laoyuanMar 28, 2015
4
5秒一包应该不会出什么岔子了
|
|
smalldirectorMar 28, 2015
5
|
|
6
借助 Redis:
1) 通过 hash 结构存储链接被分享的次数,key 为时间 (单位为 min),field 为 link,value 为 link 在该分钟被分享的次数 2) 通过 sorted sets 结构计算过去 5min、10min 内被分享的前 TOP N 的链接 |
|
mahone3297Mar 28, 2015
7
这个,让我想起了最近看的书
编写可读代码的艺术,最后一张,讲的基本上就是这个题 随着这本书不是讲算法的,但是lz可以看看这整个解的过程,蛮赞的。。。 |
|
liuhaotianMar 28, 2015
8
@Livid 为什么要word-break: break-all啊,留着word-wrap不是看起来比较赏心悦目吗...
|
|
monkeymonkeyMar 29, 2015 via Android
9
|
|
laoyuanMar 29, 2015
10
|