News Feed---how to solve the disadvantage of Pull or Push model?

Pull model:
the whole procedure:
getNewsFeed+Merge k sort array
core function:

getNewsFeed(request)
• followings = DB.getFollowings(user=request.user) //get the following
• news_feed = empty
• for follow in followings: //iterate the following
• tweets = DB.getTweets(follow.to_user, 100) //get the tweets of each one of them
• news_feed.merge(tweets) //merge them
• sort(news_feed) //merge k sort arrays them by time stamps
• return news_feed

从上面的流程和代码中可以看出来Pull model的bottleneck何在:最慢的部分发生在用户读请求上。解决的方法:加入cache

push Model:
在这里插入图片描述

posted @ 2020-10-22 04:43  EvanMeetTheWorld  阅读(19)  评论(0)    收藏  举报