From 08fe2ab5762990611f5a1d99a82f484ec0512633 Mon Sep 17 00:00:00 2001 From: Mike Nomitch Date: Mon, 24 Mar 2025 14:29:05 -0700 Subject: [PATCH 1/5] Adds changelog entry for cpu_ms limit bump --- .../workers/2025-03-25-higher-cpu-limits.mdx | 48 +++++++++++++++++++ .../docs/workers/wrangler/configuration.mdx | 4 +- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/content/changelog/workers/2025-03-25-higher-cpu-limits.mdx diff --git a/src/content/changelog/workers/2025-03-25-higher-cpu-limits.mdx b/src/content/changelog/workers/2025-03-25-higher-cpu-limits.mdx new file mode 100644 index 000000000000000..10e2b302cda7777 --- /dev/null +++ b/src/content/changelog/workers/2025-03-25-higher-cpu-limits.mdx @@ -0,0 +1,48 @@ +--- +title: Run Workers for up to 5 minutes of CPU-time +description: Workers now support up to 5 minutes of CPU time per request. Allowing more CPU-intensive workloads. +products: + - workers +date: 2025-03-25T17:00:00Z +--- + +import { Render, TypeScriptExample, WranglerConfig } from "~/components"; + +You can now run a Worker for up to 5 minutes of CPU time for each request. + +Previously, each Workers request ran for a maximum of 30 seconds of CPU time. This +meant that some compute-intensive tasks were impossible to do with a Worker. For instance, +a user might want to take the cryptographic hash of a large file from R2. If +this computation ran for over 30 seconds, the Worker request would have timed out. + +By default, Workers are still limited to 30 seconds of CPU time. This protects developers +from incurring accidental cost due to buggy code. + +By changing the `cpu_ms` value in your Wrangler configuration, you can opt in to +any value up to 300,000 (5 minutes). + + + +```jsonc +{ + // ...rest of your configuration... + "limits": { + "cpu_ms": 300000, + }, + // ...rest of your configuration... +} +``` + + + +:::note +CPU time is the amount of time the CPU actually spends doing work during a given request. +If a Worker's request makes a sub-request and waits for that request to come back before +doing additional work, this time spent waiting **is not** counted towards CPU time. + +Worker requests could run for more than 30 seconds of total time prior to this change — only +CPU time was limited. +::: + +For more information, see the documentation on [Wrangler configuration for `cpu_ms`](/workers/wrangler/configuration/#limits) +and on [Workers CPU time limits](/workers/platform/limits/#cpu-time). diff --git a/src/content/docs/workers/wrangler/configuration.mdx b/src/content/docs/workers/wrangler/configuration.mdx index ee0fe9fd34087c0..1a43e19ec38e77c 100644 --- a/src/content/docs/workers/wrangler/configuration.mdx +++ b/src/content/docs/workers/wrangler/configuration.mdx @@ -398,7 +398,9 @@ watch_dir = "build_watch_dir" ## Limits -You can impose limits on your Worker's behavior at runtime. Limits are only supported for the [Standard Usage Model](/workers/platform/pricing/#example-pricing-standard-usage-model). Limits are only enforced when deployed to Cloudflare's network, not in local development. The CPU limit can be set to a maximum of 30,000 milliseconds (30 seconds). +You can impose limits on your Worker's behavior at runtime. Limits are only supported for the [Standard Usage Model](/workers/platform/pricing/#example-pricing-standard-usage-model). +Limits are only enforced when deployed to Cloudflare's network, not in local development. The CPU limit +can be set to a maximum of 300,000 milliseconds (5 minutes).
From 5a1884774780678ee8d6701d6355c081079fb6c7 Mon Sep 17 00:00:00 2001 From: Rita Kozlov Date: Tue, 25 Mar 2025 09:21:24 -0400 Subject: [PATCH 2/5] update limits page --- src/content/docs/workers/platform/limits.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/content/docs/workers/platform/limits.mdx b/src/content/docs/workers/platform/limits.mdx index 90997a39b01638f..f998184096001e6 100644 --- a/src/content/docs/workers/platform/limits.mdx +++ b/src/content/docs/workers/platform/limits.mdx @@ -62,7 +62,7 @@ Cloudflare does not enforce response limits on response body sizes, but cache li | ------------------------ | ------------------------------------------ | ---------------- | | [Request](#request) | 100,000 requests/day
1000 requests/min | No limit | | [Worker memory](#memory) | 128 MB | 128 MB | -| [CPU time](#cpu-time) | 10 ms | 30 s HTTP request
15 min [Cron Trigger](/workers/configuration/cron-triggers/) | +| [CPU time](#cpu-time) | 10 ms | 5 min HTTP request
15 min [Cron Trigger](/workers/configuration/cron-triggers/) | | [Duration](#duration) | No limit | No limit for Workers.
15 min duration limit for [Cron Triggers](/workers/configuration/cron-triggers/), [Durable Object Alarms](/durable-objects/api/alarms/) and [Queue Consumers](/queues/configuration/javascript-apis/#consumer) | ### Duration @@ -82,7 +82,7 @@ CPU time is the amount of time the CPU actually spends doing work, during a give Using DevTools locally can help identify CPU intensive portions of your code. See the [CPU profiling with DevTools documentation](/workers/observability/dev-tools/cpu-usage/) to learn more. -You can also set a custom limit on the amount of CPU time that can be used during each invocation of your Worker. To do so, navigate to the Workers section in the Cloudflare dashboard. Select the specific Worker you wish to modify, then click on the "Settings" tab where you can adjust the CPU time limit. +You can also set a [custom limit](/workers/wrangler/configuration/#limits) on the amount of CPU time that can be used during each invocation of your Worker. To do so, navigate to the Workers section in the Cloudflare dashboard. Select the specific Worker you wish to modify, then click on the "Settings" tab where you can adjust the CPU time limit. :::note From 06f2adc84419b6361aa148ad92d67bec1712787b Mon Sep 17 00:00:00 2001 From: Rita Kozlov <2414910+rita3ko@users.noreply.github.com> Date: Tue, 25 Mar 2025 09:38:50 -0400 Subject: [PATCH 3/5] Update src/content/changelog/workers/2025-03-25-higher-cpu-limits.mdx Co-authored-by: Brendan Irvine-Broque --- src/content/changelog/workers/2025-03-25-higher-cpu-limits.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/changelog/workers/2025-03-25-higher-cpu-limits.mdx b/src/content/changelog/workers/2025-03-25-higher-cpu-limits.mdx index 10e2b302cda7777..4d9adee00398455 100644 --- a/src/content/changelog/workers/2025-03-25-higher-cpu-limits.mdx +++ b/src/content/changelog/workers/2025-03-25-higher-cpu-limits.mdx @@ -12,7 +12,7 @@ You can now run a Worker for up to 5 minutes of CPU time for each request. Previously, each Workers request ran for a maximum of 30 seconds of CPU time. This meant that some compute-intensive tasks were impossible to do with a Worker. For instance, -a user might want to take the cryptographic hash of a large file from R2. If +you might want to take the cryptographic hash of a large file from R2. If this computation ran for over 30 seconds, the Worker request would have timed out. By default, Workers are still limited to 30 seconds of CPU time. This protects developers From 46d362bdfa900e04c01463740a9fa9e3ed3195cf Mon Sep 17 00:00:00 2001 From: Rita Kozlov Date: Tue, 25 Mar 2025 09:41:25 -0400 Subject: [PATCH 4/5] clarify wall clock vs cpu time --- .../changelog/workers/2025-03-25-higher-cpu-limits.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/content/changelog/workers/2025-03-25-higher-cpu-limits.mdx b/src/content/changelog/workers/2025-03-25-higher-cpu-limits.mdx index 4d9adee00398455..6700b3d606c72fd 100644 --- a/src/content/changelog/workers/2025-03-25-higher-cpu-limits.mdx +++ b/src/content/changelog/workers/2025-03-25-higher-cpu-limits.mdx @@ -3,14 +3,14 @@ title: Run Workers for up to 5 minutes of CPU-time description: Workers now support up to 5 minutes of CPU time per request. Allowing more CPU-intensive workloads. products: - workers -date: 2025-03-25T17:00:00Z +date: 2025-03-26T17:00:00Z --- import { Render, TypeScriptExample, WranglerConfig } from "~/components"; You can now run a Worker for up to 5 minutes of CPU time for each request. -Previously, each Workers request ran for a maximum of 30 seconds of CPU time. This +Previously, each Workers request ran for a maximum of 30 seconds of CPU time — that is the time that a Worker is actually performing a task (we still allowed unlimited wall-clock time, in case you were waiting on slow resources). This meant that some compute-intensive tasks were impossible to do with a Worker. For instance, you might want to take the cryptographic hash of a large file from R2. If this computation ran for over 30 seconds, the Worker request would have timed out. From 87a3a8a502a865540a6db93bf6a5356b8585842d Mon Sep 17 00:00:00 2001 From: Rita Kozlov Date: Tue, 25 Mar 2025 09:48:43 -0400 Subject: [PATCH 5/5] mention workflows & queues --- .../changelog/workers/2025-03-25-higher-cpu-limits.mdx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/content/changelog/workers/2025-03-25-higher-cpu-limits.mdx b/src/content/changelog/workers/2025-03-25-higher-cpu-limits.mdx index 6700b3d606c72fd..f810adc33e558af 100644 --- a/src/content/changelog/workers/2025-03-25-higher-cpu-limits.mdx +++ b/src/content/changelog/workers/2025-03-25-higher-cpu-limits.mdx @@ -44,5 +44,7 @@ Worker requests could run for more than 30 seconds of total time prior to this c CPU time was limited. ::: -For more information, see the documentation on [Wrangler configuration for `cpu_ms`](/workers/wrangler/configuration/#limits) +For more information on the updates limits, see the documentation on [Wrangler configuration for `cpu_ms`](/workers/wrangler/configuration/#limits) and on [Workers CPU time limits](/workers/platform/limits/#cpu-time). + +For building long-running tasks on Cloudflare, we also recommend checking out [Workflows](/workflows/) and [Queues](/queues/). \ No newline at end of file