官术网_书友最值得收藏!

Configure parallelism at the code level

Storm provides an API to set the number of worker processes, number of executors, and number of tasks at the code level. The following section shows how we can configure parallelism at the code level.

We can set the number of worker processes at the code level by using the setNumWorkers method of the org.apache.storm.Config class. Here is the code snippet to show these settings in practice:

Config conf = new Config(); 
conf.setNumWorkers(3); 

In the previous chapter, we configured the number of workers as three. Storm will assign the three workers for the SampleStormTopology and SampleStormClusterTopology topology.

We can set the number of executors at the code level by passing the parallelism_hint argument in the setSpout(args,args,parallelism_hint) or setBolt(args,args,parallelism_hint) methods of the org.apache.storm.topology.TopologyBuilder class. Here is the code snippet to show these settings in practice:

builder.setSpout("SampleSpout", new SampleSpout(), 2); 
// set the bolt class 
builder.setBolt("SampleBolt", new SampleBolt(), 4).shuffleGrouping("SampleSpout"); 

In the previous chapter, we set parallelism_hint=2 for SampleSpout and parallelism_hint=4 for SampleBolt. At the time of execution, Storm will assign two executors for SampleSpout and four executors for SampleBolt.

We can configure the number of tasks that can execute inside the executors. Here is the code snippet to show these settings in practice:

builder.setSpout("SampleSpout", new SampleSpout(), 2).setNumTasks(4); 

In the preceding code, we have configured the two executors and four tasks of SampleSpout. For SampleSpout, Storm will assign two tasks per executor. By default, Storm will run one task per executor if the user does not set the number of tasks at the code level.

主站蜘蛛池模板: 府谷县| 泰州市| 淳化县| 鄂托克前旗| 新宾| 海南省| 万年县| 昭通市| 新竹县| 桐乡市| 池州市| 永安市| 谷城县| 光山县| 博罗县| 广元市| 赤壁市| 冷水江市| 玛多县| 新竹市| 恭城| 齐齐哈尔市| 资源县| 绍兴市| 高邮市| 麻阳| 襄汾县| 抚松县| 绥芬河市| 汉沽区| 屏东县| 吉木乃县| 前郭尔| 尉氏县| 郑州市| 班玛县| 台北县| 通化市| 鲁甸县| 乐安县| 宁德市|