You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/durable-objects/best-practices/access-durable-objects-storage.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,11 +14,11 @@ A Durable Object's [in-memory state](/durable-objects/reference/in-memory-state/
14
14
15
15
## Access storage
16
16
17
-
We recommend all new <GlossaryTooltipterm="Durable Object class">Durable Object classes</GlossaryTooltip> use the SQLite storage backend. Key-value storage backend remains for backwards compatibility, and a migration path from key-value storage to SQL storage for existing Durable Object classes will be offered in the future.
17
+
We recommend all new <GlossaryTooltipterm="Durable Object class">Durable Object classes</GlossaryTooltip> use the SQLite storage backend. [Key-value storage backend](/durable-objects/reference/durable-objects-migrations/#create-durable-object-class -with-key-value-storage) remains for backwards compatibility, and a migration path from key-value storage to SQL storage for existing Durable Object classes will be offered in the future.
18
18
19
19
[Storage API methods](/durable-objects/api/storage-api/#methods) are available on `ctx.storage` parameter passed to the Durable Object constructor. Storage API has SQL APIs and key-value APIs. Only Durable Object classes with a SQLite storage backend can access SQL API.
20
20
21
-
### Wrangler configuration for SQLite-backed Durable Objects
21
+
### Create SQLite-backed Durable Object class
22
22
23
23
Use `new_sqlite_classes` on the migration in your Worker's Wrangler file:
Durable Objects are a special kind of Worker, so [Workers Limits](/workers/platform/limits/) apply according to your Workers plan. In addition, Durable Objects have specific limits as listed in this page.
12
12
13
-
- If you exceed any one of these limits, further operations of that type will fail with an error.
14
-
- Daily free limits reset at 00:00 UTC.
13
+
## SQLite-backed Durable Objects general limits
15
14
16
-
## SQlite Durable Object general limits
17
-
18
-
| Feature | Limit for class with SQLite storage backend |
| Number of Objects | Unlimited (within an account or of a given class) |
21
-
| Maximum Durable Object namespaces | 500 (identical to the [script limit](/workers/platform/limits/)) |
22
-
| Storage per class | Unlimited |
23
-
| Storage per Durable Object | 10 GB |
24
-
| Key size | Key and value combined cannot exceed 2 MB |
25
-
| Value size | Key and value combined cannot exceed 2 MB |
26
-
| WebSocket message size | 1 MiB (only for received messages) |
27
-
| CPU per request | 30 seconds (default) / configurable to 5 minutes of [active CPU time](/workers/platform/limits/#cpu-time)[^1]|
28
-
29
-
[^1]: Each incoming HTTP request or WebSocket *message* resets the remaining available CPU time to 30 seconds. This allows the Durable Object to consume up to 30 seconds of compute after each incoming network request, with each new network request resetting the timer. If you consume more than 30 seconds of compute between incoming network requests, there is a heightened chance that the individual Durable Object is evicted and reset.
30
-
31
-
[^2]: Durable Objects both bills and measures storage based on a gigabyte <br/> (1 GB = 1,000,000,000 bytes) and not a gibibyte (GiB). <br/>
| Number of Objects | Unlimited (within an account or of a given class) |
18
+
| Maximum Durable Object namespaces | 500 (identical to the [script limit](/workers/platform/limits/)) |
19
+
| Storage per class | Unlimited |
20
+
| Storage per Durable Object | 10 GB [^1]|
21
+
| Key size | Key and value combined cannot exceed 2 MB |
22
+
| Value size | Key and value combined cannot exceed 2 MB |
23
+
| WebSocket message size | 1 MiB (only for received messages) |
24
+
| CPU per request | 30 seconds (default) / configurable to 5 minutes of [active CPU time](/workers/platform/limits/#cpu-time)[^2]|
25
+
26
+
<Detailsheader="Footnotes"open={true}>
27
+
1: Durable Objects both bills and measures storage based on a gigabyte <br/> (1 GB = 1,000,000,000 bytes) and not a gibibyte (GiB). <br/>
32
28
33
-
<Detailsheader="Footnotes">
34
-
1: Each incoming HTTP request or WebSocket *message* resets the remaining available CPU time to 30 seconds. This allows the Durable Object to consume up to 30 seconds of compute after each incoming network request, with each new network request resetting the timer. If you consume more than 30 seconds of compute between incoming network requests, there is a heightened chance that the individual Durable Object is evicted and reset.
29
+
2: Each incoming HTTP request or WebSocket *message* resets the remaining available CPU time to 30 seconds. This allows the Durable Object to consume up to 30 seconds of compute after each incoming network request, with each new network request resetting the timer. If you consume more than 30 seconds of compute between incoming network requests, there is a heightened chance that the individual Durable Object is evicted and reset. CPU time per request invocation [can be increased](/durable-objects/platform/limits/#increasing-durable-object-cpu-limits).
35
30
</Details>
36
31
37
-
### Increase Durable Object CPU limits
38
-
39
-
Durable Objects are Worker scripts, and share the same [per invocation CPU limits](/workers/platform/limits/#worker-limits) as any Workers do. Note that CPU time is active processing time: not time spent waiting on network requests, storage calls, or other general I/O, which do not count towards your CPU time or Durable Objects compute consumption.
32
+
### SQL storage limits
40
33
41
-
By default, the maximum CPU time per Durable Objects invocation (HTTP request, WebSocket message, or Alarm) is set to 30 seconds, but can be increased for all Durable Objects associated with a Durable Object definition by setting `limits.cpu_ms` in your Wrangler configuration:
| Number of Objects | Unlimited (within an account or of a given class) |
79
53
| Maximum Durable Object namespaces | 500 (identical to the [script limit](/workers/platform/limits/)) |
80
-
| Storage per account | 50 GB (can be raised by contacting Cloudflare) [^2]|
54
+
| Storage per account | 50 GB (can be raised by contacting Cloudflare) [^1]|
81
55
| Storage per class | Unlimited |
82
56
| Storage per Durable Object | Unlimited |
83
57
| Key size | 2 KiB (2048 bytes) |
84
58
| Value size | 128 KiB (131072 bytes) |
85
59
| WebSocket message size | 1 MiB (only for received messages) |
86
-
| CPU per request | 30s (including WebSocket messages) [^1]|
60
+
| CPU per request | 30s (including WebSocket messages) [^2]|
87
61
88
62
<Detailsheader="Footnotes">
89
63
1: Durable Objects both bills and measures storage based on a gigabyte <br/> (1 GB = 1,000,000,000 bytes) and not a gibibyte (GiB). <br/>
90
64
91
-
2: Each incoming HTTP request or WebSocket *message* resets the remaining available CPU time to 30 seconds. This allows the Durable Object to consume up to 30 seconds of compute after each incoming network request, with each new network request resetting the timer. If you consume more than 30 seconds of compute between incoming network requests, there is a heightened chance that the individual Durable Object is evicted and reset.
65
+
2: Each incoming HTTP request or WebSocket *message* resets the remaining available CPU time to 30 seconds. This allows the Durable Object to consume up to 30 seconds of compute after each incoming network request, with each new network request resetting the timer. If you consume more than 30 seconds of compute between incoming network requests, there is a heightened chance that the individual Durable Object is evicted and reset. CPU time per request invocation [can be increased](/durable-objects/platform/limits/#increasing-durable-object-cpu-limits).
### Create Durable Object class with key-value storage
77
+
78
+
We recommend all new <GlossaryTooltipterm="Durable Object class">Durable Object classes</GlossaryTooltip> use the SQLite storage backend. Key-value storage backend remains for backwards compatibility.
79
+
80
+
Use `new_classes` on the migration in your Worker's Wrangler file:
81
+
82
+
<WranglerConfig>
83
+
84
+
```toml
85
+
[[migrations]]
86
+
tag = "v1"# Should be unique for each entry
87
+
new_classes = ["MyDurableObject"] # Array of new classes
88
+
```
89
+
90
+
</WranglerConfig>
91
+
76
92
## Delete migration
77
93
78
94
Running a Delete migration will delete all Durable Objects associated with the deleted class, including all of their stored data.
Copy file name to clipboardExpand all lines: src/content/partials/durable-objects/do-plans-note.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,8 +5,8 @@
5
5
:::note
6
6
Durable Objects are available both on Workers Free and Workers Paid plans.
7
7
8
-
-**Workers Free plan**: Only Durable Objects with SQLite storage backend are available.
8
+
-**Workers Free plan**: Only Durable Objects with [SQLite storage](/durable-objects/best-practices/access-durable-objects-storage/#wrangler-configuration-for-sqlite-backed-durable-objects) are available.
9
9
-**Workers Paid plan**: Durable Objects with both SQLite storage and key-value storage are available.
10
10
11
-
If you wish to downgrade from a Workers Paid plan to a Workers Free plan, you must first ensure that you have deleted all namespaces for Durable Objects with key-value storage backend.
11
+
If you wish to downgrade from a Workers Paid plan to a Workers Free plan, you must first ensure that you have deleted all Durable Object namespaces with key-value storage backend.
- If you exceed any one of these limits, further operations of that type will fail with an error.
12
+
- Daily free limits reset at 00:00 UTC.
13
+
10
14
Durable Objects are billed only while the Durable Object is active (includes the <GlossaryTooltipterm="request context"> request context</GlossaryTooltip>).
| Requests |Capped at 100,000 per day | 1 million, + $0.15/million<br/> Includes HTTP requests, RPC sessions<sup>1</sup>, WebSocket messages<sup>2</sup>, and alarm invocations |
15
-
| Duration<sup>3</sup> |Capped at <br/> 13,000 GB-s per day | 400,000 GB-s, + $12.50/million GB-s<sup>4,5</sup> |
@@ -42,26 +46,30 @@ await durableObjectStub.cat(); // billed as a request
42
46
43
47
The [Durable Objects Storage API](/durable-objects/api/storage-api) is only accessible from within Durable Objects. Pricing depends on the type of storage your Durable Objects use.
44
48
45
-
-**SQLite-storage backed Durable Objects (recommended)**: This is the default storage used by Durable Objects. You can use SQLite-storage backed Durable Objects without a Workers Paid plan, or unlock higher limits with a Workers paid plan.
49
+
-**SQLite-backed Durable Objects (recommended)**: This is the recommended storage for new Durable Object classes. Workers Free plan can only create and access SQLite-backed Durable Objects.
46
50
-**Key-value storage backed Durable Objects**: This is only available on the Workers Paid plan.
<sup>1</sup> Rows read and rows written included limits and rates match D1, Cloudflare's serverless SQL database, [pricing](/d1/platform/pricing/).
63
+
<sup>1</sup> Rows read and rows written included limits and rates match [D1 pricing](/d1/platform/pricing/), Cloudflare's serverless SQL database.
60
64
61
65
<sup>2</sup> Key-value methods like `get()`, `put()`, `delete()`, or `list()` store and query data in a hidden SQLite table and are billed as rows read and rows written.
62
66
63
67
<sup>3</sup> Each `setAlarm` is billed as a single row written.
64
68
69
+
<sup>4</sup> Deletes are counted as rows_written.
70
+
71
+
<sup>5</sup> Durable Objects will be billed for stored data until the data is removed. Once the data is removed, the object will be cleaned up automatically by the system.
0 commit comments