简体   繁体   中英

variables across tasks in Storm bolt

Field grouping can direct tuples with certain fields to the same task. One executor can contain several tasks.

If I declare a bolt with a private variable integer to count tuples.

public static class CountBolt implements IRichBolt {
    OutputCollector _collector;
    private int count;

    public void prepare(Map conf, TopologyContext context, OutputCollector collector) {
        _collector = collector;
        count = 0;
    }

    public void execute(Tuple tuple) {
        count = count + 1;
        _collector.ack(tuple);
    }

    public void cleanup() {
    }

    public void declareOutputFields(OutputFieldsDeclarer declarer) {
    }

    public Map getComponentConfiguration() {
        return null;
    }
}

Does this count show the total count of inputs of the same task or of the same executor?

The count will be per task. Each task has its own instance of your Spout/Bolt class.

It would be per worker, if the variable is declared static . (Not per executor because a worker might run multiple executors of the same Spout/Bolt.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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