【发布时间】:2015-07-12 03:43:34
【问题描述】:
看起来MessageQueue应该是构建Web Crawler的一个很好的架构方案,但是我还是不明白怎么做。
让我们考虑第一种情况共享数据库,它很漂亮 明确如何做到这一点,该算法将是经典的Graph Traversal:
There are multiple Workers and shared database.
- I manually put the first url into the database
while true
- worker get random discovered url from database.
- worker parses it and gets list of all links on the page.
- worker updates the url in the database as processed.
- worker lookup into the database and separates the found links
into processed, discovered and the new ones.
- worker add the new ones links to database as discovered.
让我们考虑第二种情况,使用 MessageQueue
There are MessageQueue containing urls that should be processed
and multiple Workers.
- I manually put the first url in the Queue.
while true
- worker takes next discovered url from the Queue.
- worker parsers it and gets list of all links on the page.
- what it does next? How it separates found links into
processed, discovered and the new ones?
- worker puts the list of new urls into the Queue as discovered.
问题:
- 可以将所有发现的 url 保留在 MessageQueue 中吗?如果有数千个网站和数千个页面,那么队列中将有数百万条消息在等待。
- 如何将页面上找到的链接分为已处理、已发现和新链接?很清楚如何在 DB 的情况下执行此操作 - 只需在 DB 中查找并检查每个链接,但在 MessageQueue 的情况下如何执行?
【问题讨论】:
标签: architecture web-crawler message-queue