【问题标题】:Increase number of threads in crawler增加爬虫中的线程数
【发布时间】:2011-07-13 18:30:56
【问题描述】:
This is the code taken from http://code.google.com/p/crawler4j/ and the name of this file is MyCrawler.java


public class MyCrawler extends WebCrawler {

        Pattern filters = Pattern.compile(".*(\\.(css|js|bmp|gif|jpe?g"
                + "|png|tiff?|mid|mp2|mp3|mp4"
                + "|wav|avi|mov|mpeg|ram|m4v|pdf"
                + "|rm|smil|wmv|swf|wma|zip|rar|gz))$");

        /*
         * You should implement this function to specify
         * whether the given URL should be visited or not.
         */
        public boolean shouldVisit(WebURL url) {
                String href = url.getURL().toLowerCase();
                if (filters.matcher(href).matches()) {
                        return false;
                }
                if (href.startsWith("http://www.xyz.us.edu/")) {
                        return true;
                }
                return false;
        }

        /*
         * This function is called when a page is fetched
         * and ready to be processed by your program
         */
        public void visit(Page page) {
                int docid = page.getWebURL().getDocid();
                String url = page.getWebURL().getURL();         
                String text = page.getText();
                List<WebURL> links = page.getURLs();            
        }
}

这是调用 MyCrawler 的 Controller.java 的代码..

public class Controller {
        public static void main(String[] args) throws Exception {
                CrawlController controller = new CrawlController("/data/crawl/root");
                controller.addSeed("http://www.xyz.us.edu/");
                controller.start(MyCrawler.class, 10);  
        }
}

所以我只是想确定一下这一行在 controller.java 文件中的含义

controller.start(MyCrawler.class, 10);

这里 10 是什么意思.. 如果我们将这个 10 增加到 20 那么会有什么效果...任何建议将不胜感激...

【问题讨论】:

    标签: java web-crawler


    【解决方案1】:

    This 网站显示 CrawlController 的来源。

    从 10 增加到 20 会增加爬虫的数量(每个都在自己的线程中) - 研究该代码会告诉您这会产生什么影响。

    【讨论】:

      【解决方案2】:

      鉴于您在帖子上输入的名称,您似乎已经知道这是做什么的 - 它设置了爬虫线程的数量。至于它会产生什么影响......这在很大程度上取决于每个线程等待 I/O 的时间 - 主要是网络和一个小磁盘,以及你拥有多少 CPU 和磁盘吞吐量。当以下情况之一发生时,将出现峰值吞吐量:

      • 没有更多的 CPU 时间了
      • 没有更多的网络带宽
      • 没有更多的磁盘带宽

      对于 CPU,不要期望达到 100% - 最高 80% 左右。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-19
        • 1970-01-01
        • 2012-08-08
        • 1970-01-01
        相关资源
        最近更新 更多