JavaScript Execution - Alfresco Content Services - 23.4 - 23.4 - Ready - Alfresco - external

Alfresco Content Services

Platform
Alfresco
Product
Alfresco Content Services
Release
23.4
License

The repository can execute server-side JavaScript from different places as webscripts, workflows, or folder rules. This section shows how to limit these scripts execution regarding duration, memory usage, and call stack depth. This is useful to prevent long running scripts or high memory consumption.

The memory, time and call stack depth limits, if enabled, will only apply to scripts that have been uploaded to the repository by users, all the other scripts deployed at application server level (classpath) won’t be affected by these limits.

Property Description
scripts.execution.optimizationLevel This property allows you to configure the Rhino optimization level:
  • When set to -1, the interpretive mode is used.
  • When set to 0, no optimizations are performed.
  • When set to 1-9, optimizations are performed.
The default value is 0.
scripts.execution.maxScriptExecutionSeconds The number of seconds a script is allowed to run. If script execution exceeds the configured seconds, it will be stopped.To enable this limit, set the property with a value bigger than zero. The default value is -1 (disabled).
scripts.execution.maxStackDepth The maximum stack depth (call frames) allowed in a single invocation of the interpreter.This configuration only works for scripts compiled with interpretive mode, which means the optimization level will always be -1, overriding the value from the scripts.execution.optimizationLevel property.As the interpreter doesn’t use the Java stack but rather manages its own stack in the heap memory, a runaway recursion in interpreted code would eventually consume all available memory and cause an error. This setting helps prevent such situations.To enable this limit, set the property with a value bigger than zero. The default value is -1 (disabled).
scripts.execution.maxMemoryUsedInBytes The maximum memory (in bytes) a script is allowed to use. If script execution exceeds the configured memory, it will be stopped.To enable this limit, set the property with a value bigger than zero. The default value is -1 (disabled).If you would like to use this setting, 10000000 bytes (10 MB) is a reasonable value for custom scripts. This configuration only works with the supported JVM.
scripts.execution.observerInstructionCount The number of instructions that will trigger the observer that applies the memory and time limits.The value may vary depending on the optimization level.This configuration allows you to monitor the script execution and needs to be set to a value bigger than zero so that the time and memory limits work. The default value is 5000 so there is no need to initially change the property when enabling time or memory limits.This property is not linear, for example the instruction count here is not the number of Javascript instructions. A Javascript line can correspond to hundreds (or thousands) of lines for the observer. A value between 5000-10000 is suitable for this setting.