afredlyj / mynote

idea and note
1 stars 0 forks source link

Storm 相关 #8

Open afredlyj opened 8 years ago

afredlyj commented 8 years ago

TODO

Storm 滑动窗口 参考链接:http://www.michael-noll.com/blog/2013/01/18/implementing-real-time-trending-topics-in-storm/

滑动窗口常见的场景是每5秒统计最近10秒的数据。 其中,10秒是窗口大小,5秒为统计频率,10 / 5 = 2 为slot大小。 在storm的示例代码中有几个关键的类。

SlotBasedCounter

底层的计数器,保存每个slot的记数。比如不同单词在每个时间段内的频率。底层用Map<T, long[]>实现。

SlidingWindowCounter

SlidingWindowCounter 利用SlotBasedCounter 构造环形数组,是滑动窗口的核心,并由外部调用getCountsThenAdvanceWindow方法,返回总计数并滑动窗口。