Storm:Apache Storm is a free and open source distributed realtime computation (實時計算)system. Storm makes it easy to reliably process unbounded streams of data(海量數(shù)據(jù)流的可靠的處理), doing for realtime processing what Hadoop did for batch processing. Storm is simple, can be used with any programming language, and is a lot of fun to use!
Twitter開發(fā) 類似于Hadoop的實時處理框架
storm的官網(wǎng) storm.apache.org
storm核心代碼是由Clojure語言寫的,Clojure語言既能面向?qū)ο缶幊?,也能面向函?shù)式編程,也是基于JVM。
Storm的應用場景
Storm has many use cases: realtime analytics(實時分析), online machine learning(在線機器學習), continuous computation(持續(xù)的計算), distributed RPC(分布式RPC), ETL(數(shù)據(jù)清洗), and more.
?Storm is fast: a benchmark(標桿) clocked(時控) it at over?a million tuples processed per second per node. It is scalable(可擴展), fault-tolerant(容錯), guarantees your data will be processed, and is easy to set up and operate(保證數(shù)據(jù)被處理,易于被設(shè)置和操作).
1)交通部門,監(jiān)控高速路上超速車輛
2)電商網(wǎng)站,類似于淘寶的大屏(順序累加)
3)京東/一號店的實時推薦(協(xié)同算法,用戶標簽(畫像))
4)告警系統(tǒng)
5)金融:實時去判斷交易不是欺詐行為(涉及機器學習)
6)實時監(jiān)測網(wǎng)站有沒有遭受攻擊
storm實時,吞吐量小
Hadoop離線,吞吐量大
處理過程:Hadoop是Map和reduce階段,Storm分為Spout和bolt兩個階段。
是否結(jié)束:Hadoop最終會結(jié)束,storm沒有結(jié)束狀態(tài)
處理速度:Hadoop處理TB級別數(shù)據(jù),處理速度慢;Storm處理的是某一筆新增的數(shù)據(jù)即可,處理速度快。
使用場景:Hadoop使用的是批處理,主要用于不講究時效性的項目;storm適合講究時效性的項目。
Storm與Mapreduce1對比
MapReduce:主要用來處理高延遲的作業(yè),主節(jié)點叫做JobTracker,從節(jié)點叫做TaskTracker;運行時作業(yè)分兩種類型:Map,Reducer
Storm主要用來處理低延遲的作業(yè),主節(jié)點叫做Nimbus,從節(jié)點叫做SuperVisor。用戶提交作業(yè)給Nimbus,Nimbus把任務分配給SuperVisor,這些提交的任務叫做Topology(拓撲)。運行時作業(yè)分兩種類型:Spout,bolt
Storm運送數(shù)據(jù)依靠stream(水流)
5號線地鐵->stream
車廂->tuple
乘客->數(shù)據(jù)
乘客要上下車->topo任務
起始站->spout
中間站和終點站->bolt

第一個案例:需求:求數(shù)字1-9累加和
Spout的任務:生成數(shù)字1-9并發(fā)射(emit)
bolt的任務:根據(jù)fields名稱獲取數(shù)字,進行累加
運行:main方法:new TopologyBulider(),setSpout,setBolt
nohup storm nimbus > ?/dev/null ?2>&1 &:表示將標準輸出和錯誤輸出都輸出到/dev/null目錄中進行回收,1表示標準輸出,2表示錯誤與輸出,默認是1:標準輸出
storm的UI界面地址:host:8080
ps -ef | grep java | awk '{print $1, $2}'