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:


浙公网安备 33010602011771号