0
Not a bug

Serialisation order when trigger is activated

Paul G 3 years ago in bOS Configurator updated 3 years ago 16

Hi,


We're facing some challenges on variable values due to the unknown approach BOS takes when executing programmes triggered by the same variable. It woudl be good to understand the approach to parallelisation and serialisation BOS follows


Let's say you have 5 programmes, A,B,C,D,E that are only executed when Sun changes position changes to "DAY". How does BOS decide which programme is executed first?  There is a first, the five programmes do not start in parallel at the same time, that is a fact based on the tests I have done which are proving the troublesome issued being faced. What I mean by the latter is that A might be halfway executed by the time E starts the execution, so if you have variables used as input of those 5 programmes then there is an issue if some of those variables are not yet updated for the reasons we're calling out.


Can the BOS team shed some light on how 

1) Execution order is decided at the time of triggering the trigger that activates the programme

2) How does BOS decides the order, is it alphabetical?

Answer

+1
Answer
Not a bug

Hello all,

if bOS would be using serial / synchronous execution in drivers / tasks / themes, than nothing would work :) Of course bOS is handing every program task as async (multithreading) and the underlying OS is in charge for managing those threads and deploying CPU time to each individual thread. We also cannot talk in ms precision here (also I don't think it is required in HA) because of multiple factors:

- underlaying OS is not a Real Time OS

- protocols for HA are usually slow

- response time of physical devices

- ...


Anyway I also did some test and they were all executed without any delays. However this were just simple tasks to log message. In your case, there might be other issues in the individual task itself if it is more complex, if you are running other tasks from the original task... 

Of course there will be delays, but in general we did not receive any concerns about speed of execution so far from any of our customers. 

But as I mentioned earlier the delay is not always related to us, e.g. if you try to control 50 KNX lights at once you will see that they will not turn on at the same moment, because KNX TP speed is 9600 bit/s, which means it can transfer 20-40 packets per second, so the main bottle neck here is a speed of KNX bus and there is nothing we can do and in my opinion that is not even a issue. 

Best regards,

Matic

BAD, I'M UNSATISFIED

No answer provided

Satisfaction mark by Paul G 3 years ago

BoS team shed some light pls?

+2

Hi,

Are you sure about that?

I've created 4 different program tasks.

Each one, with exactly the same trigger. In this case, a specific time.

In each program task, a different light set to true.

Every light turned on exactly at the time I specified.

So, can you check your program tasks?

+1

And when I mean exactly, I really mean miliseconds...

You need to check your program tasks, probably there might be something there slowing down or sucking the execution of some other program tasks.

As for my tests, they ran perfectly at the same time

+2

Why do you have 5 different programs with exactly the same trigger?

Probably my approach would be something like:

Creating the different programs (as you wish, probably for organization), create a main one, set the trigger only to the main one, and inside the main program task call the other programs when needed, to ensure that all the variables used are "aligned" (if you're using dynamic variables between program tasks).

But without knowing what your programs are doing, it's difficult to help you further than this, so you need to show us some more details.

As I said, I've created different programs with the same trigger and they all ran at the same time.

So if your program tasks are more complex, you need to redo you logic first, and understand what's being stuck or run before the others.

Best regards

-1

hi, thanks Ricardo, but yes, 100% sure. Serialisation is a way computers work to execute tasks in parallel, normally the operating systems are capable of executing serialisation because it can understand the programming done at machine level when code is executed, under which severe rules are put in place, for example if a variable is being changed by more than one process the OS pauses the other..ect. It is far more complex but that, but hopefully you get the point.

BoS is not capable of handling serialisation at all, it just executes tasks, or programmes or routines, without any validation of variables used nor memory usage to avoid overflows, so effectively one you have 4 or 5 processes triggered by the same variable the difference is milliseconds is very important, the issues I have identified, which I was surprised, and I was hoping BoS had a set of rules coded into the BoS to drive for such, but it seem sit is not.

The basic example where you would use that is for example when a home changes from state "Absence" to "Presence", at that point you would normally, if basic structure programming has been done, trigger different set of tasks, a task to deal with shades, a task to deal with radiators, a task to deal with lights, a task to deal with devices...ect. All those tasks are ALWAYS executed when the trigger of the same variable changes status, this is very basic programming to achieve clean and structured code, as opposed to monolithic pieces of code. When those programmes triggered by the same variable, change of home state, are triggered, they might or not rely on common variables, sharing is the norm because otherwise you end up creating hundreds of hardcodes or variables unmanageable to deal with. In my case I have couple of variables, one for example to be able to differentiate when you are at home but not cooking time, so for example between 11 and 13 all kitchen devices are switched on if you are on PRESENCE state and NORMAL sub-state, but after that you can say you are PRESENCE state but SUPERLOW sub-state, the later would still identify you as PRESENCE but less devices and less consumption would be at home, and furthermore you can have a presence detector than triggers that if you are in the kitchen at certain time then it is likely you are about to cook so BoS would trigger the NORMAL sub-state...ect, you see endless innovative ideas, which can if not implemented then home automation means nothing -i.e. home automation is not the ability to have shades that go up and down when I press a button.

So, without understanding the rule used by BOS, you effectively are limited very significantly to really squeeze the power of BoS, which is a surprise to me, though I have seen too many junior mistakes done in the BoS code, like very basic automation testing to ensure a bug fixed in previous releases is not introduced again, which I have discovered and reported a few times in the latest 4+ releases from BoS.

So, BoS team, Can you share how you have coded serialisation of taks when more than one programme is triggered by the same variable please?

+1
Answer
Not a bug

Hello all,

if bOS would be using serial / synchronous execution in drivers / tasks / themes, than nothing would work :) Of course bOS is handing every program task as async (multithreading) and the underlying OS is in charge for managing those threads and deploying CPU time to each individual thread. We also cannot talk in ms precision here (also I don't think it is required in HA) because of multiple factors:

- underlaying OS is not a Real Time OS

- protocols for HA are usually slow

- response time of physical devices

- ...


Anyway I also did some test and they were all executed without any delays. However this were just simple tasks to log message. In your case, there might be other issues in the individual task itself if it is more complex, if you are running other tasks from the original task... 

Of course there will be delays, but in general we did not receive any concerns about speed of execution so far from any of our customers. 

But as I mentioned earlier the delay is not always related to us, e.g. if you try to control 50 KNX lights at once you will see that they will not turn on at the same moment, because KNX TP speed is 9600 bit/s, which means it can transfer 20-40 packets per second, so the main bottle neck here is a speed of KNX bus and there is nothing we can do and in my opinion that is not even a issue. 

Best regards,

Matic

-1

Thanks Matic, I do not believe I have referred in any time to a delay, but to the fact that serialisation does not cater for common variables scenario. This is CPU and OS programming 101. Sync and Async, refers to communications, and hence nothing to do with how an operating system orders and executes instructions whilst handing the variables used in such execution.


The main question, and issue for this, continues without response, on the basis How does BoS serialises and hence orders execution of tasks when a common trigger kicks the execution of the same trigger for multiple programmes?


As per the example provided, which is the one that confirms the issues I am trying to resolve, if there are 15 programmes triggered to execution by the same variable (i.e. change of state from Sleep to Absence), How does BoS serialises, hence orders the execution of those 10 programmes -It is a serialisation because BoS does not execute tasks in parallel in any shape of form, those it might run concurrent tasks, but I am not gonna waste time checkingthe I/O of the processor. 


The order in which BoS decides to execute those 15 tasks is important, as it impacts the way common variables are used within those programmes, because there is no pallalelisation of tasks but serialisation, and no handling of variables by BoS, there will be start times differences in which programmes execute the tasks (e.g. programme 4 will start to execute 3ms after programme1), hence the order in which the programmes runs affects the common variable used, because such variable changes value (as per example a Substate variable used to squeeze far more value out of BoS) - there might be people that believe that pressing a key on smarphone for the shadeto go up is domotics. 


If we know which is the order in which BoS decides the execution of the tasks then I can cater for forcing "artificial delays" on the programmes I am interested. In your example, if you have 15 programmes, that are triggered by the same trigger (sun mode change), check the log and validate the execution order please, do that more than once, you will see the order is different at different times, I have no clue why, but that's the questions, there must be a rule built in upon BOS that decides the execution order, I woudl find almost impossible leaving that to randomness. 

-1

So, the team does not know how the BoS programme serialises execution order then?

+1

Hey,

Show us the problem you are having. I did some tests too, 1 trigger and 15 programs with two outputs, didnt notice any lag or wrong orders. https://drive.google.com/file/d/1dZudkWkcseJL-y72sHlnxrrw7iMePh9F/view?usp=sharing

If you want you can use delay option in programs or retriggering on or off. If you have devices that boot up slow etc.
But those kitchen modes you were talking about a week ago, i think you should do them with Scenes... and then trigger them as you like, with time, presence detectors or voice commands... Without knowing more info about what devices and the end goal, its hard to understand what's exactly wrong. Post some pictures of you programs/scenes.

Best regards

-1

Hi Jurgen, this is very simple, pls check my first item and the items after reported, looks like the BoS has unfortunately no clue how some basic item like serialisation execution takes place in BoS, which is concerning, but no surprise bearing in mind the recurring bugs being introduced, like the one whereby the screens do not get updated, or the one with translation errors...ect. Please check and read before asking for any more details, this is very very simple, serialisation 101, and therefore the implication it has on variables commonly used by programmes executed in parallel when the variable value changes, again this is 101 in any OS CPU design and coding.


Going back to my question, 15 programmes triggered by the same variable, which is the execution order for those 15 programmes -it is clearly the case that BoS cannot execute in parallel 15 programmes because it's code it's not programmed for such-? If no one can answer that then BoS and its CEO has basic issue which would warrant the continuous errors being reintroduced after each sw release and the reason whereby details on fixes are not provided. maybe for the avergae user the above does not have any impact, but for the professionals that squeeze the value of domotic and a pwerful tool like BoS it does.

-1

And yet no answer......

And yet more issues, variable value not updated immediately, BOS requires a 2 seconds delay, not even 1 second to reflect the actual value of a variable in the log after it has been changed

Programme ( I am always forcing moving from Schedule to OFF)

Only when a delay of 2 seconds to write the log is introduced the variable shows the actual value in the log

2 secs delay, variable in log shows the right value

1 sec delay, variable in log does NOT show the right value, but the old one despite it has changed already

0 sec delay, variable in log does NOT show the right value, but the old one despite it has changed already

-1

No answer yet, or simply it is unknown how BOS orders the execution of several tasks triggered by the same event? Maybe the tasks are executed in alphabetical order? maybe executed in the order in which the tasks appear in BoS? Maybe it is just random?

Weird no can can answer such a simple question.

-1

And yet no answer, starting to believe the team does not know how BoS serialises the tasks, which is is probably no surprise

-1

An yet no answer, shame

-1

Yet another day and no answer on how BOS orders execution when multiple tasks are triggered by the same activation

And yet no response, come on guys, you can