Throttling database inserts and updates

In this example, we will show you how to throttle database updates during peak hours. Designed specifically to control database inserts, the throttleDB module includes code nuances particular to this type of process. We also offer a generic throttling module that you can apply to most other resources (such as web servers).

If you have any questions please contact us at support@interfaceware.com.

Note: We’ve assumed that peak hours are on weekdays between 10:30am to 3:30pm, but you can modify the code to match your own particular situation.

How It Works

The process for the throttleDB module is quite simple:

  1. It finds the current time.
  2. It checks to see if it falls within the specified peak time.
  3. If it does, then database access is throttled.

To see the throttleDB module in action:

  1. Create a channel with a ‘To Translator’ destination component.
  2. Open the ‘To Translator’ script and import this project zip file: Throttled_To_Translator.zip

Here is the cut-and-paste code for main():

local throttled = require 'throttleDB'

function main(Data)
   local T = MapData(Data)
   if T then
      throttled.DoDataMerge(T, db.SQL_SERVER, 'Test', '', '')
   end
end

function MapData(Data)
   local Msg, Name = hl7.parse{vmd='demo.vmd', data=Data}
   local Out = db.tables{vmd='demo.vmd', name=Name}

   -- Map data from Msg to Out here

   return Out
end

Get the latest version of the throttleDB.lua module from our repository.

Note: The util.sleep() function does not take up any extra CPU cycles! It simply pauses the thread that the call is made on (and nothing else).

See Also

Leave A Comment?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.