Apache Storm 编程入门基础(六):Storm 并行处理的理解和配置

     经过一个简单的例子之后, 我们对 Storm 的运行有较为清晰的印象。

一、Storm 并行处理关系

     整个Storm 的工作流程如图所示:


      

           这中间会涉及到一个问题, 就是任务的分配问题,涉及到几个概念:

        1、服务器。 就是执行 SuperVisor 的机器一,机器二

         2、Worker。 我们在配置的时候,一个服务器只配置了 4台 worker,分别使用6700、6701、6702、6703端口区别。事实上,一个 worker 就是一个进程 。

         3、Executor。执行器, 从图中可以看出, 一个 worker 对应一个或者多个 Executors。 事实上,Executor 就是线程。

          4、Task。 任务,就是具体的算法逻辑对象。不管如何,最终 Task 是由线程来处理的,就是由 Executor 来处理的。

          他们的包含关系如下:


          我们可以看一下,web ui 上的Topology 的关系。如下图,exclamation 有3个 workers,有18个 executors,执行18个任务。


        再看一个具体的拓扑图 exclamation。该 topology 分别在三台物理服务器上运行,并占据每一个服务上的一个 worker。


           注意的就是: 1个 worker 进程只为1个 topology或者子集服务,不会为其它的 topology 服务。1个worker进程会启动1个或多个executor线程来执行1个topology的component(spout或bolt)。因此,1个运行中的topology就是由集群中多台物理机上的多个worker进程组成的。


二、并行数量的配置

     1、设置 Worker 数量

       前面我们提到配置 topology 的运行模式中,注意到有一行语句: Config conf = new Config()。 这个就是用来配置 topology 运行环境的。在集群运行模式中 , config.setNumWorkers(3),这个用来配置 topology 运行的 worker 的数量的。要注意的是,假设我有三台物理服务器,每台服务器有4个 worker,那么每个拓扑图使用3个 Workers,那么同时只能运行4个拓扑图。

     2、设置 Executor  

      那么设置 Executor 的数量在哪里的咧?

          在定义 spout 和 Bolt 的语句中,看下面一行语句:

           

Config conf = new Config();
conf.setNumWorkers(2); // use two worker processes,使用了2个 worker 进程

topologyBuilder.setSpout("blue-spout", new BlueSpout(), 2); // 并行度,就是 Executor,这里是2个

topologyBuilder.setBolt("green-bolt", new GreenBolt(), 2)     //并行度,就是 Executor,这里是2个

               .setNumTasks(4)   //此处设置任务数
               .shuffleGrouping("blue-spout");

topologyBuilder.setBolt("yellow-bolt", new YellowBolt(), 6) //并行度,就是 Executor,这里是6个

               .shuffleGrouping("green-bolt");

StormSubmitter.submitTopology(
        "mytopology",
        conf,
        topologyBuilder.createTopology()
    );
          setSpout 和 setBolt 后面的一个参数就是设置并行度, 这个并行度就是 Executor。

         3、设置 Tasks

             见上面代码的设置。

            我们来看看,上面代码分配2个 workers,spout 为2个 executors,greenBolt 为2个 executors,yellowBolt 为6个,他们的分配情况如下图。


         

并行概念   配置 代码设置
#worker processes   Config#TOPOLOGY_WORKERS Config#setNumWorkers
#executors (threads)   ? TopologyBuilder#setSpout() 
and TopologyBuilder#setBolt()


注意: Storm 0.8 the parallelism_hint参数
现在定义为 executors (不是tasks!) .
#tasks   Config#TOPOLOGY_TASKS ComponentConfigurationDeclarer#setNumTasks()

 Config#setMaxTaskParallelism():是配置最大任务的并行度。就是为一个组件产生的最大数量的 executors。主要是为本地模式限制线程数量。

  三、    调整正在运行的 topology 的并行度

有2种模式:

   1、用 web UI 去调整

2、用命令行的方式调整

     

# Reconfigure the topology "mytopology" to use 5 worker processes,
 # the spout "blue-spout" to use 3 executors and
 # the bolt "yellow-bolt" to use 10 executors.

 $ storm rebalance mytopology -n 5 -e blue-spout=3 -e yellow-bolt=10

发布了52 篇原创文章 · 获赞 4 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/caridle/article/details/76578143