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

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.

主站蜘蛛池模板: 叶城县| 益阳市| 金塔县| 浦县| 西城区| 太和县| 寿宁县| 阜城县| 句容市| 攀枝花市| 南汇区| 乐安县| 叙永县| 泸西县| 吉隆县| 西和县| 河西区| 界首市| 河西区| 荃湾区| 定西市| 金华市| 湛江市| 民乐县| 洛隆县| 沈阳市| 泾阳县| 遂昌县| 娱乐| 昭通市| 阜宁县| 米林县| 濮阳县| 左云县| 江达县| 镇赉县| 红桥区| 象山县| 宜兰市| 拜城县| 星子县|