Map/Reduce Yielding
One major benefit of map/reduce scripts is their ability to manage some of their own resource usage. This is made possible by a feature called yielding.
To understand yielding, note that map/reduce scripts are processed by SuiteCloud Processors. A processor is a virtual unit of processing power that runs a job.
Yielding works by checking if a job has exceeded limits after each map or reduce function finishes. If it has, job gracefully ends its execution, making it possible for other jobs to gain access to the processor. A new job replaces the one that ended. The new job has the same priority as the old one, but a later timestamp.
Yielding happens when these limits are exceeded:
-
The time limit set in the Yield After Minutes field on the script deployment record. You can set this value to any number between 3 and 60. The default is 60. For more details on this field, see Yield After Minutes.
-
The 10,000 usage unit limit per map or reduce job. For more details, see Soft Limits on Long-Running Map and Reduce Jobs.
Since the system checks these limits between function calls, yielding won't interrupt a function. Additionally, be aware that a job does not yield until it has passed one of the relevant limits.
Yielding is separate from the limits for a single map or reduce function call. Those limits are described in Hard Limits on Function Invocations. If you exceed the limit for a single function call, the system throws an SSS_USAGE_LIMIT_EXCEEDED error and stops the function, even if it's not finished.
For help understanding how the map and reduce stages can each have multiple function invocations, review Map/Reduce Key Concepts.
Yielding in map/reduce is automatic. You can't manually force a map/reduce job to yield using an API. This is different from how it worked in SuiteScript 1.0 for scheduled scripts.