简体   繁体   English

风暴不屈服最大喷口支出

[英]Storm not hounoring max spout spending

I have created a sample topology to test set the max spout spending property. 我创建了一个示例拓扑,以测试设置最大喷口支出属性。 It is a simple toplogy with 1 spout and a bolt. 这是一个带有1个喷嘴和一个螺栓的简单拓扑。 The spout emits 100000 tuples and the bolt acks after sleeping for a second. 睡觉一秒钟后,喷口发出10万个元组,并且螺栓固定。 I have set the max spout spending property to 10. I assume this means that a spout will not emit any tuples if the non acked messages count is 10 for that spout. 我已将“最大喷口支出”属性设置为10。我认为这意味着,如果该喷口的未确认消息计数为10,则喷口将不会发出任何元组。 But when I run the topology, I can see the spout emitting 2160 messages and then waits. 但是当我运行拓扑时,我可以看到喷口发出2160条消息,然后等待。 Is my understanding correct or am I missing some thing. 我的理解正确吗,还是我错过了一些东西。 I am using storm 0.9.5. 我正在使用风暴0.9.5。 Below is the code 下面是代码

public static void main(String[] args) {

    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("spout", new TestSpout(), 1);
    builder.setBolt("bolt", new TestBolt(),1).shuffleGrouping("spout");
    Config conf = new Config();
    conf.setNumWorkers(1);
    conf.setMaxSpoutPending(10);
    try {
        StormSubmitter.submitTopology("test", conf, builder.createTopology());
    } catch (AlreadyAliveException e) {
        e.printStackTrace();
    } catch (InvalidTopologyException e) {
        e.printStackTrace();
    }
}


public class TestSpout extends BaseRichSpout {
private SpoutOutputCollector collector;
private int count = 1;

@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
    declarer.declare(new Fields("spoutData"));
}

@Override
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
    this.collector = collector;
    System.out.println(context.maxTopologyMessageTimeout());
}

@Override
public void nextTuple() {

    if(count <= 100000) {
        System.out.println("Emitting : " + count);
        collector.emit(new Values(count++ + ""));
    }
}

} }

public class TestBolt extends BaseRichBolt {
private OutputCollector collector;

@Override
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
    this.collector = collector;
}

@Override
public void execute(Tuple input) {
    try {
        System.out.println(input.getString(0));
        Thread.sleep(1000);
        collector.ack(input);
    } catch (InterruptedException e) {
        e.printStackTrace();
        System.out.println("Exception");
    }
}

@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {

}

} }

You need to assign message IDs to the tuples you emit in your Spout.nextTuple() method. 您需要为在Spout.nextTuple()方法中发出的元组分配消息ID。 Otherwise, parameter max.spout.pending is ignored. 否则,将忽略参数max.spout.pending For example, you can use your count variable as ID (Basically, anything can be used as an ID. It must only be unique.) 例如,您可以将您的count变量用作ID(基本上,任何东西都可以用作ID。它只能是唯一的。)

@Override
public void nextTuple() {
    if(count <= 100000) {
        System.out.println("Emitting : " + count);
        collector.emit(new Values(count++ + ""), count);
    }
}

Otherwise, Storm cannot link output tuples to the tuples that are acked in your bolt, ie, Storm cannot count how many tuples are pending. 否则,Storm无法将输出元组链接到螺栓中确认的元组,即,Storm无法计算待处理的元组数。 Only tuple with an ID can be tracked by Storm. Storm只能跟踪具有ID的元组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM