[AddIn Service] Background worked - write variables

[AddIn Service] Background worked - write variables

What is the recommended way for maximizing write operation throughput within the AddIn Engine? Let's consider the following scenario:
  • Runtime Service does multiple writes based on the data received from the external system
  • The data throughput is pretty large. Let's assume that we want to do 100 writes on 100 different variables every 100ms
  • The variable state should be verified beforehand (i.e. StatusBits or the value)
  • The writes are done within the background worker (i.e. we have a background thread constantly polling for data and once we receive it we want to invoke the write operation - each writes operation shall be invoked in parallel - for instance, we could spawn a list of tasks writing the variables as needed or invoke Parallel.ForEach() and then get the results and send the acknowledgment back to the overseeing system)
For the sake of simplicity let's only consider internal variables for now. We notice significant performance drops when trying to write faster than 100ms - when we test out intervals ~250ms+ everything looks good, but as soon as we decrease the time interval between each consecutive write, the runtime seems to be freezing (if we decide to check the variable status before writing) or slowing down (if we skip checks and treat the writes as a "fire-and-forget" operations, which is not perfect). EDIT: We also tried implementing a BufferBlock which we would use a sort of a dedicated channel for write/read operations on IVariable object (essentially - push the messages to the buffer block, consume them FIFO, and then write the changes in Zenon sequentially on the same thread so we won't get the "cross-thread" overhead which we get when trying to get the variable via IProject.VariableCollection[variableName]), but it doesn't seem to solve the issue (although the access time definitely improved). Interestingly - when we're testing multiple write cycles on that particular set of variables and actually measuring the response times we see that the write time sometimes jumps (it's pretty random, but happens every single time) in a way that access times to IVariable jumps from ~5-10ms to ~100-200ms. I am 100% confident that nothing else is trying to access any of the IProject properties (including the VariableCollection) at that time, so it is pretty unexpected.

This is a migrated post! Originally posted on 11.02.2022 by user mwieczorkiewicz. Please be aware that information can be outdated.