如何实现Spark Streaming滑动窗口的相同效果,该窗口以最后Y窗口长度的X滑动间隔运行。
关注Esper,它应该是win:time
和win:time_batch
,其中win:time> = win:time_batch。
答案 0 :(得分:0)
在esper中,等价物是声明一个上下文。 创建上下文BucketOf10Sec在10分钟后开始@now结束; Context BucketOf10Sec从MyEvent中选择sum(price);
答案 1 :(得分:0)
我设法通过win:time
与OUTPUT EVERY x
SELECT value
FROM Entry.win:time(10 sec)
OUTPUT EVERY 5 sec
以更少可自定义但更简单的方式解决此问题(至少对我而言)
public TaskThrottle(int maxTasksToRunInParallel)
{
_semaphore = new SemaphoreSlim(maxTasksToRunInParallel);
}
public void TaskThrottler<T>(IEnumerable<Task<T>> tasks, int timeoutInMilliseconds, CancellationToken cancellationToken = default(CancellationToken)) where T : class
{
// Get Tasks as List
var taskList = tasks as IList<Task<T>> ?? tasks.ToList();
var postTasks = new List<Task<int>>();
// When the first task completed, it will flag
taskList.ForEach(x =>
{
postTasks.Add(x.ContinueWith(y => _semaphore.Release(), cancellationToken));
});
taskList.ForEach(x =>
{
// Wait for open slot
_semaphore.Wait(timeoutInMilliseconds, cancellationToken);
cancellationToken.ThrowIfCancellationRequested();
x.Start();
});
Task.WaitAll(taskList.ToArray(), cancellationToken);
}
按照我的预期工作 - 每隔5秒我就会得到最后10秒的结果。