TBEL Overview
ThingsBoard Expression Language (TBEL) is a lightweight scripting language purpose-built for IoT data transformation. It is a fork of MVEL with additional security constraints and built-in memory management.
TBEL is the default scripting engine for Script calculated fields, rule engine filter and transformation nodes, and other server-side scripting contexts.
Motivation
Section titled “Motivation”Prior to TBEL, ThingsBoard used Nashorn (the JDK-bundled JavaScript engine) for server-side scripting. Nashorn was deprecated in JDK 11 and removed in JDK 15 — leaving two alternatives:
- GraalVM JavaScript — excellent but carries a heavy runtime footprint and licensing constraints that make it impractical for most self-hosted deployments.
- Remote JS Executors — Node.js processes that receive scripts over the message queue. They work, but add inter-process communication latency and consume extra system resources.
TBEL was created to provide a fast, secure, zero-dependency scripting option that runs inside the JVM without external processes.
TBEL vs Nashorn
Section titled “TBEL vs Nashorn”TBEL delivers roughly 1 000× better performance for typical transformation scripts.
| Metric | Nashorn | TBEL |
|---|---|---|
1 000 iterations of return msg.temperature > 20 |
~16 000 ms | ~12 ms |
| Startup cost per script | High (JIT compilation) | Negligible |
| Memory isolation | Weak | Strong (per-execution memory limit) |
| Security sandbox | Manual, error-prone | Built-in (restricted class access) |
TBEL vs JS Executors
Section titled “TBEL vs JS Executors”| Aspect | Remote JS Executors | TBEL |
|---|---|---|
| Additional process | Yes (Node.js) | No |
| Network/queue overhead | Yes | No |
| Language | Full ES6+ JavaScript | MVEL-based (Java-like) |
| Use case | Complex scripts that need full JS ecosystem | Typical IoT transformations |
Script limits
Section titled “Script limits”Each TBEL script call runs within limits, so that one script can’t slow down or exhaust the server. The limits apply wherever TBEL runs: rule nodes and calculated fields.
| Limit | Default | Environment variable | Error message |
|---|---|---|---|
| Input size | 100,000 characters | TBEL_MAX_TOTAL_ARGS_SIZE |
Script input arguments exceed maximum allowed total args size of 100000 symbols |
| Result size | 300,000 characters | TBEL_MAX_RESULT_SIZE |
Script invocation result exceeds maximum allowed size of 300000 symbols |
| Memory per call | 8 MB | TBEL_MAX_MEMORY_LIMIT_MB |
Script memory overflow! |
| Time per call | 500 ms | TBEL_MAX_REQUEST_TIMEOUT |
Script timeout! |
The script itself can be up to 50,000 characters long (TBEL_MAX_SCRIPT_BODY_SIZE).
The size errors show the limit that is in effect. The result is measured as the length of its JSON form.
How the input size is counted. The input is everything the script receives, measured as text. A string counts by its length, and any other value by the length of its JSON form:
- Rule node: The input is the message, its metadata, and the message type.
- Calculated field: The arguments count by their estimated size in memory.
Repeated failures block the script
Section titled “Repeated failures block the script”A call that exceeds the input size, result size, memory, or time limit counts as an error for that script. Errors in the script’s own logic, like calling a method on a null value, don’t count.
When a script reaches three errors (TBEL_MAX_ERRORS), each within 60 seconds (TBEL_MAX_BLACKLIST_DURATION_SEC)
of the previous one, ThingsBoard blocks it. Every call then fails immediately with
Script invocation is blocked due to maximum error count 3, scriptId <id>!, including calls with valid input.
A few oversized or slow messages therefore stop the regular ones too: a rule node sends every message to its Failure connection.
The block ends 60 seconds after the last counted error. Saving a change to the rule node, or restarting the service, clears it right away. Each server keeps its own count, so in a cluster a script can be blocked on one server and still run on another.
Choosing the limits
Section titled “Choosing the limits”Set the limits on every service that runs the script, then restart it. See How to change configuration, and the TBEL parameters in the configuration reference.
- Set
TBEL_MAX_TOTAL_ARGS_SIZEabove your largest input. - Raise
TBEL_MAX_RESULT_SIZE,TBEL_MAX_MEMORY_LIMIT_MB, andTBEL_MAX_REQUEST_TIMEOUTalong with it. The result can be larger than the input it came from, so a message that passes the input check can still fail on result size, memory, or time. - If oversized messages are rare but expected, raise
TBEL_MAX_ERRORSor lowerTBEL_MAX_BLACKLIST_DURATION_SEC. Each such message then fails on its own instead of blocking the script. The same settings decide how quickly a script that keeps timing out is stopped, so a slow script can hold the thread pool for longer. - Larger limits cost more CPU and memory per call. All TBEL scripts on a server share one thread pool
(
TBEL_THREAD_POOL_SIZE), so long calls on large inputs can delay other scripts. The wait counts toward their time limit, so a delayed script can time out and be blocked too. - You can also split large batches into smaller messages before sending them to ThingsBoard.
Next steps
Section titled “Next steps”- Language Guide — syntax, data types, collections, and control flow.
- Helper Functions — encoding, byte parsing, hex conversion, date/time, geofencing, and more.
Was this helpful?