`
eimhee
  • 浏览: 2113966 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

heritrix 提高抓取速度

阅读更多

最近一直用heritrix爬取网站,  晚上heritrix一直运行着, 但奇怪的是heritrix 抓取速度非常慢, 抓取一个网站, 用了8个多小时, 竟然没有运行完。 于是根据LOG 分析了一下慢的原因

 

 -----===== SNOOZED QUEUES =====-----
SNOOZED#0:
Queue us,imageshack,img245,+2 (p1)
  1 items
   wakes in: 99m19s74ms
    last enqueued: http://img245.xxx.us/img245/596/193183637x01ss500sclzzzbx0.jpg
      last peeked: http://img245.xxxx.us/img245/596/193183637x01ss500sclzzzbx0.jpg
   total expended: 12 (total budget: -1)
   active balance: 2988
   last(avg) cost: 1(1)
   totalScheduled fetchSuccesses fetchFailures fetchDisregards fetchResponses robotsDenials successBytes totalBytes fetchNonResponses
   2 1 0 0 1 0 59 59 12
   SimplePrecedenceProvider
   1

 SNOOZED QUene 里面有一些图片一直在那里, 并且运行时间相当长,

用浏览器打开, 那图片不存在,于是那图片一直在QUENE当中。

 

接着我分析了一下heritrix 中代码:

 

workQueneFrontier 有下面代码, 由于图片不存在会进入needsRetrying代码块中。

      
        if (needsRetrying(curi)) {
            // Consider errors which can be retried, leaving uri atop queue
            if(curi.getFetchStatus()!=S_DEFERRED) {
                wq.expend(curi.getHolderCost()); // all retries but DEFERRED cost
            }
            long delay_sec = retryDelayFor(curi);
            curi.processingCleanup(); // lose state that shouldn't burden retry

                wq.unpeek(curi);
                // TODO: consider if this should happen automatically inside unpeek()
                wq.update(this, curi); // rewrite any changes
                if (delay_sec > 0) {
                    long delay_ms = delay_sec * 1000;
                    snoozeQueue(wq, now, delay_ms);
                } else {
                    reenqueueQueue(wq);
                }

            // Let everyone interested know that it will be retried.
            appCtx.publishEvent(
                new CrawlURIDispositionEvent(this,curi,DEFERRED_FOR_RETRY));
            doJournalRescheduled(curi);
            return;
        }

 

 

 

 retryDelayFor方法是用来抓取失败, 计算等待的时间, 代码于如下

 

    /**
     * Return a suitable value to wait before retrying the given URI.
     * 
     * @param curi
     *            CrawlURI to be retried
     * @return millisecond delay before retry
     */
    protected long retryDelayFor(CrawlURI curi) {
        int status = curi.getFetchStatus();
        return (status == S_CONNECT_FAILED || status == S_CONNECT_LOST ||
                status == S_DOMAIN_UNRESOLVABLE)? getRetryDelaySeconds() : 0;
                // no delay for most
    }

    public int getRetryDelaySeconds() {
        return (Integer) kp.get("retryDelaySeconds");
    }

 

由于heritrix 默认是等待900秒, 也就是15分钟, 如果抓取失败一个小时也只能运行4次, 8 个小时也就是32次, 难怪一直在运行啊

 

  /** for retryable problems, seconds to wait before a retry */
    {
        setRetryDelaySeconds(900);
    }

 知道原因后就好办了, 修改一下配置文件:

 

 <!-- FRONTIER: Record of all URIs discovered and queued-for-collection -->
 <bean id="frontier" 
   class="org.archive.crawler.frontier.BdbFrontier">
  <!-- <property name="holdQueues" value="true" /> -->
  <!-- <property name="queueTotalBudget" value="-1" /> -->
  <!-- <property name="balanceReplenishAmount" value="3000" /> -->
  <!-- <property name="errorPenaltyAmount" value="100" /> -->
  <!-- <property name="precedenceFloor" value="255" /> -->
  <!-- <property name="queuePrecedencePolicy">
        <bean class="org.archive.crawler.frontier.precedence.BaseQueuePrecedencePolicy" />
       </property> -->
  <!-- <property name="snoozeLongMs" value="300000" /> -->
   <property name="retryDelaySeconds" value="90" /> 
  <!-- <property name="maxRetries" value="30" /> -->
  <!-- <property name="recoveryDir" value="logs" /> -->
  <!-- <property name="recoveryLogEnabled" value="true" /> -->
  <!-- <property name="maxOutlinks" value="6000" /> -->
  <!-- <property name="outboundQueueCapacity" value="50" /> -->
  <!-- <property name="inboundQueueMultiple" value="3" /> -->
  <!-- <property name="dumpPendingAtClose" value="false" /> -->
 </bean>

 

这是heritrix3的配置, 把时间改成90秒, 也就是只等待1分半钟,

如果是H1的配置, 那可以用管理界面进行配置。

改了一下速度一下提高了很多, 原来8小时才能爬完一个网站, 现在2个小时就行了。

如果再用一下heritrix

增量抓取, 那下次再抓取这个网站时, 速度又会增加很多。这样问题解决了

 

 

4
0
分享到:
评论
1 楼 lanxueren458 2013-06-26  
朋友,可以交流一下么,我是用了一个固定的oder.xml来抓取,新浪搜狐网易都能抓取的到的,但是别的网站就抓取不到了,请问下怎么生成一个万能的oder.xml,我只抓取网页内容,而且由于效率,只抓取10M,就是列表页面,然后再匹配标题关键字,来进行二次抓取,用自己写的程序来二次抓取

相关推荐

    heritrix抓取指南

    heritrix抓取指南heritrix抓取指南 heritrix抓取指南

    heritrix抓取的操作和扩展

    对heritrix抓取的操作和扩展 里面有MirrorWriterProcessor扩展的类文件修改

    web爬虫Heritrix.zip

    Heritrix是按多线程方式抓取的爬虫,主线程把任务分配给Teo线程(处理线程),每个Teo线程每次处理一个URL。Teo线程对每个URL执行一遍URL处理器链。URL处理器链包括如下5个处理步骤。整个流程都在图2.1中。 (1)预取链...

    Heritrix3手册翻译

    Heritrix User Manual https://webarchive.jira.com/wiki/display/Heritrix/Heritrix3 Heritrix3(或简称H3)指Heritrix的3.0发布。 目前官方的Heritrix 3.0.0版已经发布(2009年12月)。 后续的发行H3将是3.0.1...

    heritrix正确完整的配置heritrix正确完整的配置

    heritrix正确完整的配置heritrix正确完整的配置heritrix正确完整的配置heritrix正确完整的配置heritrix正确完整的配置

    Heritrix安装详细过程

    按照这个步骤安装绝对会让你安装成功的。步骤非常的清晰。Heritrix是一个不错的选择。网络爬虫,更快更好的帮你捕捉到你想要的网页

    heritrix 配置

    Heritrix 是一个由 java 开发的、开源的网络爬虫,用户可以使用它来从网上抓取想要的资源。其最出色之处在于它良好的可扩展性,方便用户实现自己的抓取逻辑。本文详细介绍了 Heritrix 在 Eclipse 中的配置、运行。

    网络爬虫Heritrix1.14.4可直接用

    在/Heritrix1/src/org/archive/crawler/Heritrix.java启动之后,访问https://localhost:8089登录admin密码admin直接用

    heritrix系统使用.ppt

    heritrix系统使用、一个ppt 介绍heritrix的基本概念、以及原理知识

    Heritrix(windows版)

    包含: heritrix-3.1.0-dist.zip heritrix-3.1.0-src.zip 官网下载地址。

    heritrix网络爬虫

    Heritrix是一个开源,可扩展的web爬虫项目。用户可以使用它来从网上抓取想要的资源。Heritrix设计成严格按照robots.txt文件的排除指示和META robots标签。其最出色之处在于它良好的可扩展性,方便用户实现自己的抓取...

    heritrix-3.4.0-SNAPSHOT-src.zip

    Heritrix 是一个由 java 开发的、开源的网络爬虫,用户可以使用它来从网上抓取想要的资源。官网下载好像要翻墙,我下下来方便大家使用,这是3.4版本,配合heritrix-3.4.0-SNAPSHOT-dist.zip使用

    Heritrix爬虫框架 完整版

    Heritrix 是一个由 java 开发的、开源的网络爬虫,用户可以使用它来从网上抓取想要的资源。其最出色之处在于它良好的可扩展性,方便用户实现自己的抓取逻辑

    heritrix-3.1.0 最新jar包

    heritrix-3.1.0 最新官网jar包。包括heritrix-3.1.0-dist.zip包与heritrix-3.1.0-src.zip包。是爬虫神器

    heritrix1.14.4源码包

    heritrix1.14.4的源码包,包含heritrix1.14.4.zip和heritrix1.14.4-src.zip。heritrix是一种开源的网络爬虫,用于爬去互联网中的网页。如何配置和使用heritrix爬虫,请移步:...

    Heritrix—开发自己的搜索引擎

    开发自己的搜索引擎,Heritrix是一种网页抓取的有效工具

    heritrix源码

    heritrix学习源码和资料

    Heritrix使用详解与高级开发应用

    Heritrix使用详解与高级开发应用 Heritrix开发应用详细

    heritrix1.14.0jar包

    爬虫时我们会使用heritrix,搭建工程时要导入这些jar包,该jar包是1.14.0版本的。

    heritrix-1.14.2.zip

    heritrix-1.14.2.zip是一个开源项目

Global site tag (gtag.js) - Google Analytics