之前一直对窗口操作不太理解。认为spark streaming本身已经是分片计算,还需要窗口操作干啥。
窗口操作最为简单易懂的场景就是,在M时间间隔计算一次N时间内的热搜。当M=N的时候,就像上述所说,窗口操作本身没什么优势;但当在M!=N的时候,窗口计算优势就体现出来了。
之前用storm的窗口计算,实在是麻烦。而spark streaming则要简单许多。
借用官网提供的图以及例子:
简来说就是10秒钟计算30秒内的单词数。
两个参数
window length - The duration of the window (3 in the figure). -> N sliding interval - The interval at which the window operation is performed (2 in the figure). -> M
在每一次十秒分别输入:
1: sdf sdfsd sdf 2: sdf sdfsd sdf 3: sdf sdfsd sdf sdf sdfsd sdf 234