|
| 1 | +--- |
| 2 | +title: Run Workers for up to 5 minutes of CPU-time |
| 3 | +description: Workers now support up to 5 minutes of CPU time per request. Allowing more CPU-intensive workloads. |
| 4 | +products: |
| 5 | + - workers |
| 6 | +date: 2025-03-25T17:00:00Z |
| 7 | +--- |
| 8 | + |
| 9 | +import { Render, TypeScriptExample, WranglerConfig } from "~/components"; |
| 10 | + |
| 11 | +You can now run a Worker for up to 5 minutes of CPU time for each request. |
| 12 | + |
| 13 | +Previously, Workers could only run for up to 30 seconds of CPU time. This meant that |
| 14 | +some compute-intensive tasks were impossible to do with a Worker. For instance, |
| 15 | +a user might want to take the cryptographic hash of a large file from R2. If |
| 16 | +this computation ran for over 30 seconds, the Worker request would have previously |
| 17 | +timed out. |
| 18 | + |
| 19 | +By default, Workers are still limited to 30 seconds of CPU time. This protects developers |
| 20 | +from incurring accidental cost due to buggy code. |
| 21 | + |
| 22 | +By changing the `cpu_ms` value in your Wrangler configuration, you can opt in to |
| 23 | +any value up to 300000 (5 minutes). |
| 24 | + |
| 25 | +<WranglerConfig> |
| 26 | + |
| 27 | +```jsonc |
| 28 | +{ |
| 29 | + // ...rest of your configuration... |
| 30 | + "limits": { |
| 31 | + "cpu_ms": 300000, |
| 32 | + }, |
| 33 | + // ...rest of your configuration... |
| 34 | +} |
| 35 | +``` |
| 36 | + |
| 37 | +</WranglerConfig> |
| 38 | + |
| 39 | +:::note |
| 40 | +CPU time is the amount of time the CPU actually spends doing work during a given request. |
| 41 | +If a Worker's request makes a sub-request and waits for that request to come back before |
| 42 | +doing additional work, this time spent waiting **is not** counted towards CPU time. |
| 43 | + |
| 44 | +Workers were able to run for more than 30 seconds of total time prior to this change, only |
| 45 | +CPU time was limited. |
| 46 | +::: |
| 47 | + |
| 48 | +For more information, see documentation on [Wrangler configuration for `cpu_ms`](/workers/wrangler/configuration/#limits) |
| 49 | +and on [Workers CPU time limits](/workers/platform/limits/#cpu-time). |
0 commit comments