Skip to content

Commit 7bf2097

Browse files
authored
Rewrite Workers Memory Limits docs
1 parent e55a85a commit 7bf2097

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/content/docs/workers/platform/limits.mdx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,19 @@ Routes in fail closed mode will display a Cloudflare `1027` error page to visito
148148

149149
## Memory
150150

151-
Only one Workers instance runs on each of the many global Cloudflare global network servers. Each Workers instance can consume up to 128 MB of memory. Use [global variables](/workers/runtime-apis/web-standards/) to persist data between requests on individual nodes. Note however, that nodes are occasionally evicted from memory.
151+
Each [isolate](/workers/reference/how-workers-works/#isolates) your Worker's code runs in can consume up to 128 MB of memory. This includes both memory used by the JavaScript heap, and memory explicitly allocated in [WebAssembly](/workers/runtime-apis/webassembly/). Note that this limit is per-isolate, not per-invocation of your Worker. A single isolate can handle many concurrent requests.
152152

153-
If a Worker processes a request that pushes the Worker over the 128 MB limit, the Cloudflare Workers runtime may cancel one or more requests. To view these errors, as well as CPU limit overages:
153+
If at any point in time an isolate running your Worker uses more than 128 MB of memory, rather than immediately failing with an error, the Workers runtime will attempt to allow in-flight requests to that isolate to complete, and will create a new isolate for your Worker. In this process, the Workers runtime still may cancel one or more incoming requests, but ensures that if your Worker exceeds memory limits, it is automatically restarted as gracefully as possible.
154+
155+
To view out-of-memory errors (OOM), as well as CPU limit overages:
154156

155157
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and select your account.
156158
2. Select **Workers & Pages** and in **Overview**, select the Worker you would like to investigate.
157159
3. Under **Metrics**, select **Errors** > **Invocation Statuses** and examine **Exceeded Memory**.
158160

159-
Use the [TransformStream API](/workers/runtime-apis/streams/transformstream/) to stream responses if you are concerned about memory usage. This avoids loading an entire response into memory.
161+
To avoid exceeding memory limits, where possible you should avoid buffering large objects or responses in memory, and instead use streaming APIs such as [`TransformStream`](/workers/runtime-apis/streams/transformstream/) or [`node:stream`](/workers/runtime-apis/nodejs/streams/) to stream responses. Manipulating streams allows you to avoid buffering entire responses in memory.
160162

161-
Using DevTools locally can help identify memory leaks in your code. See the [memory profiling with DevTools documentation](/workers/observability/dev-tools/memory-usage/) to learn more.
163+
You can also use Chrome DevTools in local development to identify memory leaks in your code. See the [memory profiling with DevTools documentation](/workers/observability/dev-tools/memory-usage/) to learn more.
162164

163165
---
164166

@@ -334,4 +336,4 @@ Review other developer platform resource limits.
334336

335337
- [KV limits](/kv/platform/limits/)
336338
- [Durable Object limits](/durable-objects/platform/limits/)
337-
- [Queues limits](/queues/platform/limits/)
339+
- [Queues limits](/queues/platform/limits/)

0 commit comments

Comments
 (0)