Skip to main content
Aug 25, 2015 4:13 AM UTC
Question

Lua Script Resource scanRateResolution Config Option

"The scanRateResolution setting controls the frequency at which the main loop of a thing script executes in the LSR.  Once a ‘thing’ script is started it enters into a loop that executes until the script resource is shutdown.  Each iteration of this main loop takes a number of actions.  At a high level it does the following:

  • Goes through all your configured properties.  If each property’s ‘scanRate’ amount of time has expired, then the property is evaluated to see if it should be pushed.  To do this, the property handler read method for each property is called and the new value is compared to the old (if necessary).  If the property needs to be pushed to the server its is added to a temporary list of properties to be pushed.
  • The temporary list of properties is pushed to the server.  If no properties have been evaluated, or no properties need to be pushed, then this list will be empty and nothing is pushed.
  • The thing’s registration with the EMS is checked, via a call to the EMS.
  • Configured tasks are executed if the taskRate time has expired.
  • GC is ran if 5 seconds or more have elapsed.
  • The thread then sleeps for scanRateResolution milliseconds.

If you don’t need the main loop to drive  calls to your property read handlers, then you could set your scanRateResolution fairly high, causing the main loop to sleep longer between iterations.  This could have a few side effects:

  1. The registration check will happen at the scanRateResolution, unless you adjust the keepAliveRate to be greater than the scanRateResolution.
  2. You will need to set your taskRate and scanRate config properties to be greater than the scanRateResolution, or the script resource will complain during startup.  Since the scanRateResolution controls the pause of the main loop, it is the main limiting factor in how often these things happen.
  3. Shutting down the script resource can be delayed by up to scanRateResolution milliseconds, since the main loop has to exit for the script to shutdown.

The default value for the scanRateResolution is 500 milliseconds.  If however, you don't require the loop to execute that often, then you could set this value much higher, even 10,000 milliseconds or more, in order to slow the execution of the loop and save CPU load."