Query SLEEP
The SLEEP clause tells RioDB to suspend a query after its conditions have hit a match (or after its output action has been triggered).
RioDB often deals with stream of thousands of requests per second. Suppose the output action is to generate a system alert in a remote system. If not careful, the query could result in millions of alerts being generate in a few seconds.
To prevent this catastrophy, the SLEEP clause tells RioDB to suspend the query for an amount of time after each time the query triggers an action.
The query will automatically resume after the SLEEP time has passed.
The sleep clause is optional.
Syntax
The SLEEP value expressed as time counted in an integer followed by a character representing the time unit. ‘s’ for seconds, ‘m’ for minutes, ‘h’ for hours, ‘d’ for days.
SLEEP <integer><time unit>
Example
Seconds
sleep 30 seconds:
SELECT ...
FROM ...
WHEN...
OUTPUT (...)
SLEEP 30s;
Minutes
sleep 5 minutes:
SELECT ...
FROM ...
WHEN...
OUTPUT (...)
SLEEP 5m;
Hours
sleep 2 hours:
SELECT ...
FROM ...
WHEN...
OUTPUT (...)
SLEEP 2h;
Day
sleep 1 day:
SELECT ...
FROM ...
WHEN...
OUTPUT (...)
SLEEP 1d;
System-wide Configuration for SLEEP:
For RioDB Cloud deployments:
On the cloud, RioDB has a default setting of 1-second sleep per query. You may specify a higher value. However, if the SLEEP is not specified for a query, then RioDB will automatically assume a 1-second sleep period each time the query triggers a match. The reason for this is because if a user accidentally triggers an external OUTPUT request a million times per second for several hours, it could incur astronomical costs from the downstream service. So, this default policy is a protection.
For RioDB On-Prem deployments:
The RioDB configuration file (riodb.conf) has a property ‘min_sleep_secs’ to force a minimum SLEEP time on all queries. This prevents a catastrophic output flood if a developer submits a query forgetting the SLEEP clause.
When ‘min_sleep_secs’ is set, developers can always specify a higher SLEEP interval than the system minimum, but never lower. The ‘min_sleep_secs’ is automatically apply to all queries that lack the SLEEP clause.
Note, RioDB must be restarted in order for the ‘min_sleep_secs’ to become effecited, and it will apply to queries submitted prior to the change.