上图的时间窗口大小为4s,他会在4s的窗口时间到达以后才将窗口中的内容一起扔给UpdateListener来进行处理,性能相对节约很多,特别是大数据量的情况下。长度批量窗口的处理模式也是类似。
上述窗口模式下内存使用情况又是如何呢?经过本人测试和研究代码发现,它会保留两个窗口的内存使用量,一个保存当前窗口的Events,一个保存上一个窗口的Events,因此在估算一个数据分析程序占用多少内存要看上面监听的EPL语句开的窗口的大小以及数据的TPS,防止内存OOM。
掌握了上面的窗口的概念,后面其他的内容都很好理解了
d) 过滤
where过滤
select avg(price) from test.OrderEvent.win:time_batch(3 sec) where price>10having过滤
select avg(price) from test.OrderEvent.win:time_batch(3 sec) having price>10
似曾相识啊,执行方式也基本和SQL里的where 和 having差不多。
在EPL里where 是在incoming Events到window之间进行过滤,having是在window到New Eventing之间进行过滤
e)聚合
count
select count(price) from test.OrderEvent.win:time_batch(3 sec) where price>10
sum
select sum(price) from test.OrderEvent.win:time_batch(3 sec) where price>10
group by
select itemName,sum(price) from test.OrderEvent.win:time_batch(3 sec) where price>10 group by itemName
都很简单,了解SQL的都狠容易上手
f) 函数
ESPER默认加载
• System
• System.Collections
• System.Text
支持这些包下的函数方法,例如
select Math.round(sum(price)) from test.OrderEvent.win:time_batch(3 sec) where price>10
它还支持自定义函数,举个例子,做个计算百分比的函数
public class MyUtilityClass{
public static double computePercent(double amount, double total) {
return amount / total * 100;
}
}
配置一下
<esper-configuration
<plugin-singlerow-function name="percent"
function-class="mycompany.MyUtilityClass" function-method="computePercent" />
</esper-configuration>
OK了,可以用了
select percent(price,total) from OrderEvent
总体来说,ESPER的EPL功能非常强大,而且基本和SQL类似,入门容易,构造一个实时数据分析系统比较简单,且维护成本低,新应用进来只需要简单配置一下EPL语句就可以了,方便快捷,对大部分的系统还是比较适合的。
优质内容筛选与推荐>>
1、Caused by: java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactoryt 异常解决2、C#项目转php工作记录3、【BZOJ】1007: [HNOI2008]水平可见直线(凸包)4、WPF相关开源项目5、数据库排名函数(Rank)