Table of Contents

ILoadBalancer

Namespace
ZApplication

This object can be used to distribute load across several cycles. It is designed for the following use case.

Let's assume that a child is holding several children and its job is to update said children. The children are managed in an array, which looks like

_children : ARRAY[1..100] OF ZCore.IUnmanagedObject;

Note that the array should begin at 1.

There are some cases where it is not important to update all children at the same time. If this is the case, it may be a waste of resources to update them every cycle. This is where the load balancer comes in. It allows to set an interval, which is the time where all objects should be updated once. Depending on the number of loads, the load balancer then returns the range of children that should be updated in one specific cycle. Use the following pattern, when using the load balancer in another object.

_loadBalancer.Cyclic(); // update iterators for this specific cycle
FOR i:=_loadBalancer.IterationBegin TO _loadBalancer.IterationEnd DO
  _children[i].Cyclic();
END_FOR

Here are some example how the iterators of the load balancer behave

  1. If Interval=1s, the PLC cycletime is 1ms and there is one load.
    • In the first cycle IterationBegin=IterationEnd=1 and the load with index=1 will be updated
    • In the next 999 cycles IterationBegin>IterationEnd and therefore no load is updated and no resources are wasted.
    • In the next cycle this pattern starts over
  2. If Interval=1s, the PLC cycletime is 1ms and there are three loads
    • In the first cycle IterationBegin=IterationEnd=1 and load with index=1 will be updated
    • In the second cycle IterationBegin=IterationEnd=2 and load with index=2 will be updated
    • In the third cycle IterationBegin=IterationEnd=3 and load with index=3 will be updated
    • In the next 997 cycles IterationBegin>IterationEnd and therefore no load is updated and no resources are wasted.
    • In the next cycle this pattern starts over
  3. If Interval=1s, the PLC cycletime is 1ms and there are 2000 loads
    • In every cycle the next two consecutive loads are updated until all of them are updated within the given Interval=1s
    • When all objects are updated, the pattern starts over from load with index=1.
Note

To shuffle across multiple load balancers a random offset is set randomly for every instance.

INTERFACE ILoadBalancer

Properties

Interval

Interval (in seconds) where all loads of the balancer should be updated once. For instance, if the interval is set to 0.050s this means that every single object, which is load balanced, is updated within this timeframe. If there are only a few loads the load balancer will return iterators that will lead to loops that do not call any object.

Setting Interval=0 to disables load balancing and effectively updates all I/Os in every cycle

PROPERTY Interval : LREAL

Property Value

LREAL

Loads

Configures the total amount of loads for the balancer. Every load has the same weight and is therefore regarded as equal to any other object.

PROPERTY Loads : DINT

Property Value

DINT