By default, each Dynamic Worker invocation uses your Workers plan limits for CPU time and subrequests. Custom limits let you programmatically enforce lower limits on the Dynamic Worker's resource usage.
You can set limits for the maximum CPU time and number of subrequests per invocation. If a Dynamic Worker reaches either limit, it immediately throws an exception.
Specify custom limits as part of the Worker code:
const worker = env.LOADER.get("my-worker", async () => {
return {
compatibilityDate: "$today",
mainModule: "index.js",
modules: { "index.js": code },
limits: { cpuMs: 10, subRequests: 5 },
};
});You can also specify limits as part of the getEntrypoint() call:
// Get the Worker's default entrypoint with custom limits.
// If limits were already specified as part of the Worker code,
// the lower of the two limits is used.
const entrypoint = worker.getEntrypoint(null, { limits: { cpuMs: 10, subRequests: 5 } });
await entrypoint.fetch(...);