0

I am trying to implement a basic window on an input stream in siddhi. This is the window query

executionPlan = "" +
                "define stream inputStream (height int); " +
                "" +
                "@info(name = 'query1') " +
                "from inputStream #window.length(5) " + 
                "select avg(height) as avgHt " + 
                "insert into outputStream ;";

And this is how I am giving data to the input Stream.

    Object[] obj1 = {10};
    Object[] obj2 = {5};
    for (int i=0;i<10;i++) {
        try {
            inputHandler.send(obj1);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    for (int i=0;i<20;i++) {
        try {
            inputHandler.send(obj2);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

Am I wrong in supposing that the the query should give a callback after each input to the inputHandler. So for this example the initial output should be 10 and then It should gradually decrease and become 5. At a point where I have sent all the 10's and 2 5's then I should get a callback with average as (10+10+10+5+5)/5= 8. But this is not happening currently. For this implementation I get two callback with average 10 and 5 respectively. Why isn't there a gradual decrease from 10 to 5?

This is how I add the callback

executionPlanRuntime.addCallback("query1", new QueryCallback() {
        @Override
        public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
            // printing inEvents
            EventPrinter.print(inEvents);

    });

What am I missing here?

shshnk
  • 1,621
  • 14
  • 26

1 Answers1

1

Since you are sending events in a burst it's batching events within. But if you add Thread.Sleep(100) in between the events you send then it will output as you expected.

suho
  • 912
  • 6
  • 12
  • 2
    Thanks for answering. It works as expected after putting Thread.Sleep(). But is there any way to avoid this batching of events. I am ok if the output rate is slower than the input rate. – shshnk Dec 15 '15 at 06:47
  • Is there any way to avoid this batching? Nothing is mentioned regarding this batching in the documentation. https://docs.wso2.com/display/CEP300/Windows – shshnk Jan 13 '16 at 07:43
  • As you can see in https://github.com/wso2/siddhi/blob/master/modules/siddhi-core/src/main/java/org/wso2/siddhi/core/stream/input/SingleStreamEntryValve.java#L133 we are batching the outputs of disrupter and when we do aggregations in windows. This is done in several places in siddhi to give high throughput in realtime without compromising latency. This process also reduces the number of events outputted which will also help to improve the performance. Currently in Siddhi 3.0.4 we don't have a way to change this behaviour. Is there a valid scenarios which required this to be fixed ? – suho Jan 15 '16 at 08:16