如果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. 【itclx面向对象一】tcl基础语法:过程、作用域、以及itcl面向编程回顾

    学习熟悉编程的最好方法就是动手,有点面向编程思维的话,直接练习就可以.直接看demo 1.过程.作用域 #全局变量:过程外定义的变量#局部变量: 过程内部定义的变量 set a 100proc tes ...

  2. php的传值和传址

    有些情况下,可能希望在函数体内对参数的修改在函数体外也能反映; 使用引用传递参数要在参数前加上&符号; 例子: <?php $a=5; function show(&$a){   ...

  3. ServletContext中的转发

    客户端向服务器发送请求,服务器将请求进行转发,获得响应信息,客户端只发送一次请求,地址栏信息不变. 服务器接收类,进行转发 package com.itheima.zhuanfa; import ja ...

  4. Apache Mesos总体架构

    http://developer.51cto.com/art/201401/426507.htm 1. 前言 同其他大部分分布式系统一样,Apache Mesos为了简化设计,也是采用了master/ ...

  5. ASP多行多列又一个方法

    <table border=1 width="200"> <% col=4 '列数 i=1 Do While i<=100 If i Mod col=1 T ...

  6. linux时间自动同步

    1,修正本地时区及ntp服务 #yum -y install ntp#rm -rf /etc/localtime#ln -s /usr/share/zoneinfo/Asia/Shanghai /et ...

  7. Linux下如何查看哪些端口处于监听状态

    查看某一端口的占用情况: lsof -i:端口号 前提:首先你必须知道,端口不是独立存在的,它是依附于进程的.某个进程开启,那么它对应的端口就开启了,进程关闭,则该端口也就关闭了.下次若某个进程再次开 ...

  8. Js替换地址栏参数

    开了博客竟然有9个月没在来写过了.真是惭愧.今天需要用到一个用js替换地址栏参数的的功能.就自己用JS自己写了一个简单的函数.贴出来仅供大家参考.代码都写了注释.如下: /* js替换URL参数值,无 ...

  9. 将多维数组转换为支持curl提交的一维数组格式

    /** * @desc 多维数组转化为支持curl提交数组 * @author lytian 2013-06-29 */ public function toPost(array $params = ...

  10. HW--自守数

    package testcase; import huawei.Demo; import junit.framework.TestCase;//加入测试框架,不需要写Main函数 public cla ...