In Cloudflare Workers, what is the difference between CPU time and wall time, and which one does the CPU limit count?
answer
- two clocks per invocation
- waiting is not computing
- limits.cpu_ms in the Wrangler file
- 10 ms free, 30 s paid default
basics
~20 sCPU time counts only the Worker's code actually running; wall time also includes waiting on fetch(), KV or a database. The CPU limit counts CPU time: 10 ms on Workers Free, 30 seconds by default on Workers Paid, up to 5 minutes.
solid answer
~40 sA Worker invocation has two clocks. **Wall time** is elapsed time from start to finish, including every `await` on a `fetch()` subrequest, a KV read or a database query. **CPU time** is only the time the isolate spends executing the Worker's JavaScript or WebAssembly, so a request that waits four seconds on a slow origin may use 3 ms of CPU. The CPU limit counts CPU time: 10 ms per request on Workers Free, and on Workers Paid a default of 30 seconds that `limits.cpu_ms` can raise to 300,000 ms (5 minutes) or lower to cap runaway code. An HTTP request has no hard wall-time limit while the client stays connected. Going over the CPU limit ends the invocation with Error 1102 and the outcome `exceededCpu`.
code
json · 8 lines{
"name": "image-metadata",
"main": "src/index.js",
"compatibility_date": "2026-10-01",
"limits": {
"cpu_ms": 60000
}
}go deeper
Recall the two clocks: CPU time is code running, wall time includes waiting. Know the headline numbers, 10 ms on Free and 30 seconds by default on Paid.
Explain why awaiting I/O is free against the CPU limit, how limits.cpu_ms raises the Paid limit to 5 minutes or lowers it as a guard, and that Error 1102 marks an overrun.
Show you measure before tuning: read CPU and wall time in Workers Logs, profile hot paths with DevTools, and remember wrangler dev does not enforce limits.cpu_ms and, in production, Date.now() does not tick during execution.
Treat the CPU limit as a cost and safety control: when a team should raise it for heavy work, lower it to fail fast, or move heavy computation off the request path.
## Two clocks for one invocation Every time a Cloudflare Worker handles an event, the platform measures two different durations: - **Wall time** (wall-clock time): the total elapsed time from the start of the invocation to its end, including time spent waiting on the network, on storage and on other asynchronous work. - **CPU time**: only the time the CPU spends actually executing the Worker's code, JavaScript or WebAssembly, inside its V8 isolate. The difference matters because most Workers spend most of their life waiting. A geolocation redirect Worker that reads one value and returns a `302` may finish in a few milliseconds of wall time and well under a millisecond of CPU. An API Worker that awaits a slow origin for four seconds has four seconds of wall time and perhaps 3 ms of CPU time. ## What counts as CPU time Cloudflare's limits documentation states the rule directly: waiting on network requests does **not** count toward CPU time. In practice: - **Counts**: parsing a large body with `JSON.parse()`, hashing or encrypting data, rendering HTML, running a regular expression over a big string, building a large response in memory. - **Does not count**: the time between calling `fetch()` and getting the response, an `env.KV.get()` round trip, a D1 or Durable Object call, or any other awaited I/O. The image-metadata Worker that parses multi-megabyte JSON uploads is the kind that spends real CPU; Cloudflare's own figure is about 2.2 ms per request for the average Worker and 10-20 ms for heavier work such as server-side rendering or parsing large payloads. ## The limits by plan | Limit | Workers Free | Workers Paid | |---|---|---| | CPU time per HTTP request | 10 ms | 30 seconds by default, up to 5 minutes | | Wall time per HTTP request | no hard limit while the client is connected | no hard limit while the client is connected | | Work after the response through `ctx.waitUntil()` | up to 30 seconds | up to 30 seconds | Other event types have their own CPU and wall-time ceilings, covered with handlers and Cron Triggers. ## A worked example Suppose the image-metadata Worker handles one upload like this: it awaits an R2 read for about 300 ms, parses the JSON for 40 ms of CPU, and awaits a database write for another 80 ms. Its wall time is roughly 420 ms, but only the parsing and the small amount of code around the awaits is CPU time, so about 40 ms is charged against the CPU limit. On Workers Free that is four times the 10 ms limit, and a Worker doing it on every upload would be terminated with Error 1102. On Workers Paid it uses a tiny fraction of the 30-second default. The slow R2 and database calls make the response slower for the user, yet they never bring the Worker closer to Error 1102. ## Setting `limits.cpu_ms` On Workers Paid the CPU limit is a per-Worker setting in the Wrangler configuration file (or the dashboard), in milliseconds: ```json { "limits": { "cpu_ms": 60000 } } ``` The maximum is `300000` (5 minutes). Cloudflare kept 30 seconds as the default when the ceiling was raised in 2025 so that a buggy loop cannot quietly run up CPU charges, and the same key can set a *lower* value as a guard. Two caveats from the Wrangler documentation: 1. The `limits` settings are enforced only when the Worker runs on Cloudflare's network, not under local `wrangler dev`, so a local run that finishes proves nothing about the limit. 2. Each isolate has some built-in flexibility for a Worker that goes over the configured limit only occasionally; a Worker that hits it consistently is terminated. ## What happens past the limit, and how to measure it When an invocation exceeds its CPU limit, the client receives **Error 1102** with the message `Worker exceeded resource limits`; the dashboard lists it as `Exceeded CPU Time Limits` and analytics and Logpush record the outcome `exceededCpu`. To see how close a Worker runs to the limit: - **Workers Logs** shows CPU time and wall time on each invocation log. - **Tail Workers and Logpush** carry both values at the top level of the trace event. - **CPU profiling with Chrome DevTools** against a local run shows which functions burn the time. What does *not* work is timing code with `Date.now()` inside a deployed Worker. To blunt timing side-channel attacks, the Workers runtime returns the time of the last I/O from `Date.now()`, and the value does not advance while code executes, so a tight loop between two calls reads as zero.
- Why can a Worker that takes four seconds to respond use only a few milliseconds of CPU time?Because CPU time stops while the Worker waits. Each `await` on a `fetch()` subrequest, a KV read or a database query parks the invocation, and the isolate's CPU is free to run other requests. Only the code that runs between those waits, such as parsing and building the response, is charged against the CPU limit.
- Why would a team set limits.cpu_ms lower than the 30-second default?To cap runaway code. A Worker that should never need more than a second of CPU can set `cpu_ms` to 1000, so an accidental infinite loop or a pathological input fails fast with Error 1102 instead of burning 30 seconds of billed CPU per request. The cap is enforced only on Cloudflare's network, not under `wrangler dev`.
- Awaiting a slow fetch() burns CPU time against the Worker's limit.
- Workers Paid caps CPU at 30 seconds with no way to raise it.
- The 10 ms free-plan limit is a wall-clock timeout on the whole request.
- A local wrangler dev run enforces limits.cpu_ms, so passing locally proves production fits.
- Timing a loop with Date.now() inside a deployed Worker shows its CPU cost.
Assumes Workers limits as of 2026-10-10: the Paid CPU ceiling rose from 30 seconds to 5 minutes in March 2025, and 30 seconds stayed the default.