Table of Contents

LoadBalancerUM

Namespace
ZApplication
Implements
FUNCTION_BLOCK LoadBalancerUM IMPLEMENTS ZCore.IUnmanagedObject, ZApplication.ILoadBalancer (
 [output] IterationBegin : DINT,
 [output] IterationEnd : DINT)

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.

Outputs

IterationBegin DINT

Index of the first object to be updated in this cycle

IterationEnd DINT

Index of the last object to be updated in this cycle. ``IterationEndmay be the same value asÌtBegin`, which means that only the object with the corresponding index should be updated

Constructor

FB_init

METHOD FB_init (
 [input] bInitRetains : BOOL,
 [input] bInCopyCode : BOOL) : BOOL

Inputs

bInitRetains BOOL
bInCopyCode BOOL

Returns

BOOL

Properties

Interval

PROPERTY Interval : LREAL

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 Value

LREAL

Loads

PROPERTY Loads : DINT

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 Value

DINT

Methods

Cyclic

METHOD Cyclic ()

This method must be implemented by any function block that implements IUnmanagedObjects. The method must be called from the creator of the object, it is not automatically taken care of from the framework.

UpdateLoadDistribution

METHOD PROTECTED UpdateLoadDistribution ()

Based on the number of loads and the update interval this method calculates to total amount of buckets and how loads are distributed amongst them.