Introduction to Storm - Initial Storm

 

1. What is Storm

       Strom is a Hadoop-like real-time data processing framework open sourced by Twitter. Strom is a distributed streaming data processing system. Powerful distributed cluster management, convenient programming model for streaming data, and high fault tolerance guarantee are the first choice for streaming real-time data processing.

 

Second, Storm features and advantages    

       1) Easy to use: Provides rich services and programming interfaces for complex stream computing models, which are quick to develop and easy to learn and use. (rapid development, easy to use)

       2) Fault tolerance: adaptive fault tolerance. When the worker process (worker) fails, Storm can automatically restart these processes; when a node goes down, all the above worker processes will be restarted on other nodes; for Storm's daemons, nimbus and supervisor are designed to be no status or quick recovery. (daemon stateless, worker failover)

      3) Scalability: Storm jobs are inherently parallel and can be executed across machines or clusters. Various components (Spout and Bolt) in the topology can be configured with different degrees of parallelism. When the cluster performance is insufficient, you can add physical machines at any time to balance parallel tasks. (linear expansion)

     4) Integrity: Provides integrity operations on data: at least once, at most once, and only once. Users can choose according to their needs. (Data is not lost, accuracy)

 

 

3. Application scenarios of Storm

    At present, Storm is widely used in famous companies such as Twitter, Yahoo, Tencent, Ali, and Sina.

     Sina's real-time analytics platform

     Tencent's real-time computing platform

     Qihoo 360's real-time platform

     Baidu's real-time system

     Ali's Jstorm

     ......

Fourth, the system architecture of Storm

      

      1. Master node (Nimbus): The node running Nimbus is the master node of the system, that is, the master node; the Nimbus process is the center of the Storm system and is responsible for receiving jobs submitted by users (Storm is the topology code saved in the form of a jar package) , assign tasks (process level and thread level) and transfer job copies to worker nodes; and rely on the coordinator node's service to monitor the running status of the cluster and provide a status acquisition port. Nimbus is currently deployed separately.

 

      2. Slave node (Supervisor): The node running the supervisor is the slave node, that is, the worker node; the supervisor monitors the node where it is located, and starts, stops, revokes or closes the worker process of the task according to the delegation of nimbus. Worker nodes are nodes where real-time data processing jobs run. Among them, the physical unit of calculation on the node is the worker, that is, the worker process; the logical unit of calculation is the executor, that is, the calculation thread. The job logical unit of computation is topology, that is, topology; the logical unit of computing task is task, that is, task. Each worker executes a subset of the topology-specific executors, and each executor executes one or more tasks. A topology mainly has two components: spout and bolt, which are the starting unit and processing unit of streaming data in the topology, respectively. Components can be configured in parallel, each of which is a task that runs in an executor.

 

     3、Web节点(Storm UI): 运行Storm UI后台服务的节点;Storm UI在指定端口提供网页服务。用户可以根据浏览器访问web页面,通过web页面提交、暂停和撤销作业,也可以以只读的方式获取系统配置、作业以及各个组件的运行状态。web节点在逻辑 上是独立的,可以被安装在系统的任意节点实现监控;但是如果需要实现作业的管理,Storm UI必须和Storm nimbus部署在一台机器上,这是因为Storm UI进程会检查本机是否存在nimbus的连接,是否存在可导致UI部分功能无法正常工作。

 

     4、协调节点(Zookeeper):运行Zookeeper进程的节点;Zookeeper并不是Storm专用的,可以作为一类通用的分布式状态协调服务。nimbus和supervisor之间的所有协调,包括分布式状态维护和分布式配置管理都是通过协调节点实现的。为了实现服务的高可用性,Zookeeper往往是以集群形式提供服务的,即在Storm系统中可以存在多个协调节点。

 

 

 五、Storm的工作流

       

        1、Topology:storm中运行的一个实时应用程序,因为每个组件间的消息流动形成逻辑上的一个拓扑结构。

        2、Spout:在一个topology中产生源数据流的组件。通常情况下spout会从外部数据源中读取数据,然后转化为topology内部的源数据。Spout是一个主动的角色,其接口中有一个nextTuple()函数,storm框架会不停地调用此函数,用户只要在其中生成源数据即可。

        3、Bolt:是在一个topology中接受数据然后执行处理的组件。Bolt可以执行过滤、函数操作、合并、写数据库等操作。Bolt是一个被动的角色,其接口中有execute(Tuple input)函数,在接受到消息后会调用此函数,用户可以在其中执行自己想要的操作。

       4、Tuple:一次消息传递的基本单元。本应该是一个key-value的map,但是由于各个组件间传递的tuple的字段名称已经事先定义好,所以tuple中只要按序填入各个value就行了,所以就是一个value list。

       5、Stream:源源不断传递的tuple就组成了stream。

 

 

六、Storm的并发机制

           

       1、服务器(Nodes):Strom集群可以包含多台服务器,即可以扩展多个Nodes.

      2、JVM虚拟机(worker):每台Storm服务器可以起多个JVM虚拟机,即可以扩展为多个worker。

      3、线程(executor):每个worker可以运行一个或多个executor。每个executor可以运行同一个component(spout/bolt)的一个或多个task。

            

       4、Spout/Bolt实例(task):task就是一个spout/bolt实例,是真正执行数据处理的地方。

 

            

          一个正在运行的拓扑由很多worker进程组成,这些worker进程在storm集群的多台机器上运行。一个worker进程属于一个特定的拓扑并且执行这个拓扑的一个或多个component(spout/bolt)的一个或多个executor。一个worker进程就是一个java虚拟机(JVM),它执行一个拓扑的一个子集。

 

         一个executor是由一个worker进程产生的一个线程,它运行在worker的java虚拟机里。一个executor为同一component

(spout/bolt)运行一个或多个任务。一个executor总会有一个线程来运行executor所有的task,这说明task在executor内部是串行执行的。

 

         真正的数据处理是在task里面执行的,在父executor线程执行过程中会运用task。在代码中实现每个spout或bolt是在全集群中以很多task的形式运行的。一个component的task数量在这拓扑的生命周期是固定不变的,但是一个component的executor(线程)数量是随着时间推移发生变化的。说明:threads数量<=task数量。默认情况下task数量被设置成跟executor的数量是一样的,即Storm会在每个线程上执行一个任务。

   

        注意:executor线程的数量在拓扑已经启动后可以发生变化,但是拓扑的task数量是固定不变的了。

 

 

七、Storm的数据流

     

         Storm的核心概念是“流”(stream),一个stream相当于一个无限的元组(tuple)序列。Storm提供基用来做流转换的基件是spout和bolt。spout和bolt提供了接口,可以实现这些接口来处理应用程序相关的逻辑。

         

         spout是流的来源。例如:spout可以从一个Kestrel队列来读tuple并且发射(emit)他们从而形成一个流,或者spout可以连接到twitter api来发射一个推文的流。

 

         一个bolt消费任意数量的流,做一些处理,然后可能会发射出新的流。对于复杂的流转换,例如:从一个推文的流计算出一个热门话题的流需要多个步骤、多个bolt。bolt可以通过运行函数来做任何事,如、过滤元组、做流聚合、做流连接、和数据库之间交互等。

 

       storm使用tuple做数据模型。一个tuple是一个被命名过的值列表,一个tuple中的字段可以是任何类型的对象。是开箱即使用的,storm支持所有的简单数据类型,如字符串、字节数组作为tuple的字段值。如果使用另外一种类型的对象,只需要为这个类型实现一个serializer。topology中的每一个节点都应该为它要发射的元组输出字段。

 

       为拓扑中的每一个bolt确定输入数据流定义一个拓扑的重要环节。数据流分组定义了在bolt的不同任务(tasks)中划分数据流的方式。在storm中有八种内置的数据流分组方式,而且可以通过customstreamgrouping接口实现自定义的数据流分组模型。

     

        八组数据流分方式

       1、随机分组(shuffle grouping):这种方式下元组会被尽可能的随机地分配到bolt的不同任务(tasks)中,使得每个任务所处理的元组数量能够保持基本一致,以确保集群的负载均衡。

 

       2、域分组(fields grouping):数据流根据定义的“域”来分组。如:若某个数据流是基于一个名为“user-id”的域进行划分的,那么所有包含相同“user-id”的元组都会被分配到同一个任务中,这样来确保消息的一致性。

 

       3、部分关键字分组(partial key grouping):这种方式与域分组类似,根据定义的域来对数据流进行分组,不同的是,这种分组方式会考虑下游bolt数据处理的均衡性问题,再输入数据源关键字不平衡时会有更好的性能。

 

      4、完全分组(all  grouping):这种方式会将数据流同时发送到bolt的所有任务中(即同一个元组会被复制多份然后发送到所有的任务处理)。使用这种方式要格外谨慎。

 

      5、全局分组(global grouping):这种方式下所有的数据流都被发送到bolt的同一个任务中,也就是id最小的那个任务。

 

     6、非分组(none grouping):不关心数据流如何分组,目前这种方式的结果和随机分组完全等效,不过在未来storm社区可能考虑通过非分组方式来让bolt和它所订阅的spout或bolt在同一个线程中执行。

 

     7、直接分组(direct grouping):是一种特殊的分组方式,这种方式使得元组的发送者可以指定下游的哪个任务可以接收这个元组

。只有在数据流被声明为直接数据流时才能使用直接分组。

  

    8、本地或随机分组(local or shuffle grouping):如果在源组件的worker进程里目标有一个或更多的任务线程,元组会被随机分配到那些同进程的任务中。

 

 

七、Storm的数据流    

       1、更能性保障:多粒度的并行化

       2、非功能性保障:多级别的可靠性

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324780393&siteId=291194637