Storm调研

流计算: 将⼤规模流动数据在不断变化的运动过程中实现数据的实时分析,捕捉到可能有⽤的信息,并把结果发送到下⼀计算节点。

 

 StormTwitter开源的分布式实时大数据处理框架,被业界称为实时版Hadoop。随着越来越多的场景对HadoopMapReduce高延迟无法容忍,比如网站统计、推荐系统、预警系统、金融系统(高频交易、股票)等等,大数据实时处理解决方案(流计算)的应用日趋广泛,目前已是分布式技术领域最新爆发点,而Storm更是流计算技术中的佼佼者和主流。

 

Storm的作业拓扑是个死循环,而MapReduce的作业执行完自动结束。

 

推荐系统(实时推荐,根据下单或加入购物车推荐相关商品)、金融系统、预警系统、网站统计(实时销量、流量统计,如淘宝双11效果图)、交通路况实时系统等等。

 

 

mvn exec:java -Dexec.mainClass="TopologyMain" -Dexec.args="src/main/resources/words.txt"

 

java -jar target/storm-analytics-0.0.1-jar-with-dependencies.jar

 

node webapp/app.js

例子:比如一群人在讨论美国大选,我想从这群人的交谈中统计每个候选人名字出现的次数。

 

首先我们需要将输入的语音流转化为文本文件,然后将一行一行的句子,分割为一个一个的单词,

这些单词流传递到下一个bolt时,会逐个统计这些领导人名字的出现次数。

 

Spout the entry point for a topology (a spout)

 

Bolts are created on the client machine, serialized into the topology, and submitted to the master machine of the cluster. The cluster launches workers that deserialize the bolt, call prepare on it, and then start processing tuples.

本地模式:Storm topologies run on the local machine in a single JVMit’s important to make sure that all components are thread safe,其中本地模式,需要下载一系列的storm依赖。

 

远程模式:usually running on different machines. Remote Mode doesn’t show debugging information

 

storm相关概念

Streams消息流

       消息流是一个没有边界的tuple序列,而这些tuples会被以一种分布式的方式并行创建和处理。 每个tuple可以包含多列,字段类型可以是: integer, long, short, byte, string, double, float, booleanbyte array。 你还可以自定义类型 — 只要你实现对应的序列化器。

Spouts消息源

      Spoutstopology消息生产者。Spout从一个外部源(消息队列)读取数据向topology发出tuple。 消息源Spouts可以是可靠的也可以是不可靠的。一个可靠的消息源可以重新发射一个处理失败的tuple, 一个不可靠的消息源Spouts不会。

      Spout类的方法nextTuple不断发射tupletopologystorm在检测到一个tuple被整个topology成功处理的时候调用ack, 否则调用fail

      storm只对可靠的spout调用ackfail

Bolts:消息处理者

      消息处理逻辑被封装在bolts里面,Bolts可以做很多事情: 过滤, 聚合, 查询数据库等。

      Bolts可以简单的做消息流的传递。复杂的消息流处理往往需要很多步骤, 从而也就需要经过很多Bolts。第一级Bolt的输出可以作为下一级Bolt的输入。而Spout不能有一级。

      Bolts的主要方法是execute(死循环)连续处理传入的tuple,成功处理完每一个tuple调用OutputCollectorack方法,以通知storm这个tuple被处理完成了。当处理失败时,可以调fail方法通知Spout端可以重新发送该tuple

     流程是: Bolts处理一个输入tuple, 然后调用ack通知storm自己已经处理过这个tuple了。storm提供了一个IBasicBolt会自动调用ack

     Bolts使用OutputCollector来发射tuple到下一级Blot

 

Hadoop处理这种情况,以批处理的方式,而storm基于该方法将展示结果的更新以一种实时的方式刷新

 

该例子组成:

Node.js web应用,去测试系统。

Redis服务器,持久化数据

Storm拓扑,用于实时分布式数据处理

The Product Stats Page This page shows the information computed by the Storm cluster, which is collected as users navigate the website. It can be summarized as follows: users that viewed this Product looked at Products in those Categories n times. The URL for this page is http://localhost:3000/product/:id/stats.

 

productstats页面这个页面显示了由Storm集群计算的信息,这些信息是在用户浏览网站时收集的。可以总结如下:看过这个产品的用户看了n次这些类别的产品。此页面的URL

 

The goal of the Storm topology in this system is to update the product stats in real time while users navigate the website.

 

Our Storm Topology has five components: one spout to feed it and four bolts to get the job done.

UsersNavigationSpout Reads from the users navigation queue and feeds the topology

GetCategoryBolt Reads the product information from the Redis Server and adds its category to the stream

UserHistoryBolt Reads the products previously navigated by the user and emits Product:Category pairs to update the counters in the next step

ProductCategoriesCounterBolt Keeps track of the number of times that users viewed a product of a specific category

NewsNotifierBolt Tells the web application to update the user interface immediately

 

 Nimbus 负责在集群分发的代码,topo只能在nimbus机器上提交,将任务分配给其他机器,和故障监测。

     Supervisor,监听分配给它的节点,根据Nimbus 的委派在必要时启动和关闭工作进程。 每个工作进程执行topology 的一个子集。一个运行中的topology 由很多运行在很多机器上的工作进程组成。

Storm中有对于流stream的抽象,流是一个不间断的无界的连续tuple,注意Storm在建模事件流时,把流中的事件抽象为tuple即元组

 

Storm认为每个stream都有一个源,也就是原始元组的源头,叫做Spout(管口)

     处理stream内的tuple,抽象为Boltbolt可以消费任意数量的输入流,只要将流方向导向该bolt,同时它也可以发送新的流给其他bolt使用,这样一来,只要打开特定的spout再将spout中流出的tuple导向特定的boltbolt又对导入的流做处理后再导向其他bolt或者目的地。

      可以认为spout就是水龙头,并且每个水龙头里流出的水是不同的,我们想拿到哪种水就拧开哪个水龙头,然后使用管道将水龙头的水导向到一个水处理器(bolt),水处理器处理后再使用管道导向另一个处理器或者存入容器中。

 

 Storm将流中元素抽象为tuple,一个tuple就是一个值列表value listlist中的每个value可以是任意可序列化的类型。拓扑的每个节点都要说明它所发射出的元组的字段的name,其他节点只需要订阅该name就可以接收处理。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值