Timeout parameter

Release 1.3 - ...

The timeout parameter of macros allows to control the duration of execution of the macro.

Smartsite SXML CopyCode image Copy Code
<se:for from="1" to="6" timeout="5">
 <p>{datetime.now()}</p>
 {sys.thread.sleep(500)}
</se:for>

The above macro writes 6 lines, requiring 500 ms per line. The se:for takes 3 s and is guarded with a timeout of 5 s. No timeout occurs and the macro produces the result as expected.

Smartsite SXML CopyCode image Copy Code
<se:for from="1" to="8" timeout="3">
 <p>{datetime.now()}</p>
 {sys.thread.sleep(500)}
</se:for>

The above macro attempts to write 8 lines. The se:for would take 4 s and is guarded with a timeout of 3 s. The macro causes an error: "Module Timeout (3000 milliseconds) expired".

Smartsite SXML CopyCode image Copy Code
<se:for from="1" to="50">
 <p>{datetime.now()}</p>
 {sys.thread.sleep(500)}
</se:for>

The above macro attempts to write 50 lines. The se:for would take 25 s. The macro causes an error: "Module Timeout (20000 milliseconds) expired". A default timeout of 20 s is applied.

Purposes

The timeout parameter serves two purposes.

  • For long running operations it is possible to set the timeout parameter to a larger value than the default of 20 s. The purpose is to avoid a timeout to occur after 20 s.
  • For complex operations, perhaps depending on external conditions, perhaps containing several retry mechanisms it is possible to limit the execution time to a maximum, for example to 300 s, at the cost of an error. The purpose is to detect potentially endless loops and to abort the operation in order to free resources.

There is no configuration parameter for the default timeout of 20 s. It is recommended to set individual timeouts on a per-case basis.

Macros supporting the timeout

The following macros support the timeout mechanism.

  • DoWhile
  • For
  • SqlQuery
  • While

Many other macros accept a timeout parameter, currently ignoring the the parameter.

How to apply the mechanism

In order to apply the timeout mechanism consider the following.

  • The mechanisme is not preemptive: a running se macro will not be interrupted when the allotted time has expired. A regular se macro - not one of the macros listed above - may run for an inderminated period of time without being aborted. The period may exceed the default timeout of 20 s. No error is signalled if the macro takes more than 20 s.
  • The looping macros DoWhile, For and While perform a timeout check after each loop iteration. These macros signal an error if the check after a numer of iterations reveals that the allotted time has been exceeded. Each individual loop iteration is again not preemptive; one loop iteration is allowed te complete no matter the amount of time required.
  • The SqlQuery macro performs a timeout check before and after actual execution of the query. Once the query has been started it is allowed to complete, regardless the time this takes. The timeout check after query execution allows to detect and signal long-running queries, but will not abort a long running query.

For nested se macros consider the following.

  • It is possible to set a timout on some outer se macro, which is typically a looping macro.
  • The purpose may be to reduce the timout to some value less than the default of 20 s. With each loop iteration the timeout will be checked. The logic enclosed in the loop may consists of several macros. The amount of time required by each inner macro is not of particular interest; an error will be signalled if the total amount of time required for all inner macros and all loop iterations so far exceeds the timeout specified for the loop.
  • It is still possible that a regular inner macro takes substantial time, perhaps more than the default of 20 s, perhaps more than the time allotted to the loop. Executing the regular inner macro will not cause an error, the looping outer macro will signal the error.
  • The purpose may also be to increase the timeout value for the outer looping macro, to avoid a timeout to occur after 20 s. In this case it is required to check the enclosed logic for inner macros that may take more than 20 s on individual basis, otherwise a timout error will still occur for these inner macros, despite raising the timeout value for the outer macro. Looping macros and the SqlQuery macro need to be checked; regular macros need not be checked because they will not cause the timeout error.

---