如果topN 设置为1000万 ,不会这1000万都放到QueueFeeder(内存)中,而是从文件系统中(hdfs)中迭代不断填充QueueFeeder。
队列中默认存放 threadcount * 50 。 这个类的作用是从文件系统读文件填充队列。 /**
* This class feeds the queues with input items, and re-fills them as
* items are consumed by FetcherThread-s.
*/
private static class QueueFeeder extends Thread {
private final Context context;
private final FetchItemQueues queues;
private final int size;
private Iterator<FetchEntry> currentIter; //FetchEntry实现了 org.apache.hadoop.io.Writable
boolean hasMore;
private long timelimit = -1; public QueueFeeder(Context context,
FetchItemQueues queues, int size)
throws IOException, InterruptedException {
this.context = context;
this.queues = queues;
this.size = size;
this.setDaemon(true);
this.setName("QueueFeeder");
hasMore = context.nextKey();
if (hasMore) {
currentIter = context.getValues().iterator();
}
// the value of the time limit is either -1 or the time where it should finish
timelimit = context.getConfiguration().getLong("fetcher.timelimit", -1);
} @Override
public void run() {
int cnt = 0;
int timelimitcount = 0;
try {
while (hasMore) {
if (System.currentTimeMillis() >= timelimit && timelimit != -1) {
// enough .. lets' simply
// read all the entries from the input without processing them
while (currentIter.hasNext()) {
currentIter.next();
timelimitcount++;
}
hasMore = context.nextKey();
if (hasMore) {
currentIter = context.getValues().iterator();
}
continue;
}
int feed = size - queues.getTotalSize();
if (feed <= 0) {
// queues are full - spin-wait until they have some free space
try {
Thread.sleep(1000);
} catch (final Exception e) {};
continue;
}
if (LOG.isDebugEnabled()) {
LOG.debug("-feeding " + feed + " input urls ...");
}
while (feed > 0 && currentIter.hasNext()) {
FetchEntry entry = currentIter.next();
final String url =
TableUtil.unreverseUrl(entry.getKey());
queues.addFetchItem(url, entry.getWebPage());
feed--;
cnt++;
}
if (currentIter.hasNext()) {
continue; // finish items in current list before reading next key
}
hasMore = context.nextKey();
if (hasMore) {
currentIter = context.getValues().iterator();
}
}
} catch (Exception e) {
LOG.error("QueueFeeder error reading input, record " + cnt, e);
return;
}
LOG.info("QueueFeeder finished: total " + cnt + " records. Hit by time limit :"
+ timelimitcount);
context.getCounter("FetcherStatus","HitByTimeLimit-QueueFeeder").increment(timelimitcount);
}
}

nutch 生产者队列的大小如何控制 threadcount * 50的更多相关文章

  1. RabbitMQ五:生产者--队列--多消费者

    一.生成者-队列-多消费者(前言) 上篇文章,我们做了一个简单的Demo,一个生产者对应一个消费者,本篇文章就介绍 生产者-队列-多个消费者,下面简单示意图 P 生产者    C 消费者  中间队列 ...

  2. RabbitMQ四:生产者--队列--消费者

    AMQP协议的梳理和名词解析  建议先把上篇AMQP协议先看一遍,理解一下,由于用XMind绘图,电脑屏幕比较小,不能截取全部,如果想要全图和源代码,请下面留言....... 可以点击图片,打开到新的 ...

  3. Kivy主窗体大小的控制

    1. 引入依赖模块 主窗体大小的控制,需要使用到kivy.core.window中的Window模块 from kivy.app import App from kivy.core.window im ...

  4. Java -- 使用阻塞队列(BlockingQueue)控制线程通信

    BlockingQueeu接口是Queue的子接口,但是它的主要作用并不是作为容器,而是作为线程同步的工具. 特征: 当生产者线程试图向BlockingQueue中放入元素时,如果该队列已满,则该线程 ...

  5. unity spine 对翻转和大小的控制

    spine-unity怎么决定我的Spine模型的大小? Spine使用 1像素:1单位.意思是,如果你只是包含图像在你的骨架中,并且没有任何旋转和缩放,在Spine中该图像的1个像素就对应1个单位高 ...

  6. JQuery获取图片大小并控制图片文件上传大小以及上图片文件时如何预览图片

    首先我们来看效果图: 点击上传之后如下: 在这里我获取到文件的大小,并且如果超出我设定的大小,则禁止上传! 不多说,上代码:先看div布局: <div class="imageCont ...

  7. 消息中间件kafka+zookeeper集群部署、测试与应用

    业务系统中,通常会遇到这些场景:A系统向B系统主动推送一个处理请求:A系统向B系统发送一个业务处理请求,因为某些原因(断电.宕机..),B业务系统挂机了,A系统发起的请求处理失败:前端应用并发量过大, ...

  8. 并发编程.md

    操作系统基础 人机矛盾: CPU利用率低 磁带存储+批处理:降低数据的读取时间,提高CPU的利用率 多道操作系统------在一个任务遇到IO的时候主动让出CPU,给其他任务使用 由操作系统完成 切换 ...

  9. python — 进程

    目录 1. 进程 1.进程就是一个运行中的程序(是对正在运行程序的一个抽象). 2.程序和进程之间的区别: 程序只是一个文件 进程是这个文件被CPU运行起来了 程序是永久的,进程是暂时的. 3.进程- ...

随机推荐

  1. [未完成]关于枚举(Enum)

    今天总结一下枚举相关的知识.先附一段关于枚举的代码: package org.talend.core.model.param; import org.talend.core.i18n.Messages ...

  2. Lua - 基础语法

    Hello World 交互式编程 Lua 交互式编程模式可以通过命令 lua -i 或 lua 来启用: [huey@huey-K42JE lua]$ lua Lua 5.1.4 Copyright ...

  3. 2015年校园招聘12家IT公司面试体验

    背景 2015年注定是一个不平凡的年头,作为一个应届毕业生,我也算是经历了工作上的大起大落.下面我先简单讲述一下自己的遭遇,然后根据自己亲身的面试经历,从一个学生的角度去谈谈自己对面试过的公司的一些看 ...

  4. ACM——Quicksum

    Quicksum 时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte总提交:615            测试通过:256 描述 A chec ...

  5. Android 百度地图开发之一(Hello BaiDu Map)

    之前也接触过百度地图的开发,但那是在网上找的案例或代码,而且是比较老的版本.打算重新学习一下百度地图的开发. 本次使用的百度地图的版本是 Android SDK v3.0.0 本篇文章主要讲述百度地图 ...

  6. Java_Web_request.setAttribute("result",username);

    request.setAttribute("result",username); 在request对象中加入名为result的属性并附值为username,因为request对象是 ...

  7. 在有大量数据时 少用In(数据会丢失) 用left join 代替

    select @From, @To, EffectiveDate, GETDATE(), Rate from Config_Currency_ExchangeRate_Temp where Effec ...

  8. 使用SQL Server 2005 新的语法ROW_NUMBER()进行分页的两种不同方式的性能比较

    相比在SQL Server 2000 中使用的分页方式,在SQL Server 2005中使用新的语法ROW_NUMBER()来分页效率要高出很多,但是很多人在使用ROW_NUMBER()这种分页方式 ...

  9. 常用终端及git命令

    终端常用命令 1,打开终端,git version 查看版本 2,pwd 打印工作目录 3,ls(list简写)查看当前目录的所有文件 4,clear 清掉屏幕 5,cd (change direct ...

  10. Basic MSI silent install

    Articles and post about silent install for Basic MSI, InstallScript, InstallScript MSI: Silent-mode ...