Diffinery

homeflare/celldpublic

celld/README.md
213 lines · 8.6 KBRaw History
1# celld
2
3Self-hosted, distributed **Durable Objects**.
4
5celld is an open-source daemon that runs Cloudflare Workers and Durable
6Objects on your own machines. Each object is its own SQLite database.
7celld addresses an object by name and replicates it to a bucket that you
8own. The bucket can be S3-compatible or Google Cloud Storage. The nodes
9coordinate through that bucket alone, with no control plane and no
10consensus. Because every object is its own small database,
11applications shard by construction — the contention and blast-radius failures
12of one shared database are designed out, not managed. A cell that no node
13holds is inactive, and an inactive cell costs nearly nothing. Learn more at
14[celld.dev](https://celld.dev) or read the
15[documentation](https://celld.dev/docs).
16
17## How it works
18
19Every `celld` node embeds V8 and executes Wrangler bundles. The fleet shares
20one bucket, which contains deployments, cell state, and small ownership
21records. The bucket can be S3-compatible or Google Cloud Storage. Object-storage compare-and-swap ensures that exactly one node owns a
22cell at a time, without a membership protocol, failure detector, or consensus
23service.
24
25celld continuously replicates each cell's SQLite database to the bucket.
26When a cell moves, or when an inactive cell activates, its new owner restores
27that database and resumes execution. The bucket is the durable source of
28truth; nodes are replaceable.
29
30## Install
31
32The installer downloads the `celld` binary (provenance is verifiable with
33`gh attestation verify`):
34
35```sh
36curl -fsSL https://celld.dev/install.sh | sh
37```
38
39Put `~/.local/bin` on your `PATH` if the installer asks you to.
40
41Worker projects deployed with `celld deploy` need
42[esbuild](https://esbuild.github.io) on `PATH`; asset-only projects do not.
43
44The installer keeps each release under `~/.local/lib/celld/releases` and points
45one symlink at the current one. To remove celld, delete the symlink and the
46releases:
47
48```sh
49rm `which celld` && rm -rf ~/.local/lib/celld
50```
51
52## Container
53
54The release image contains the `celld` binary and is published for Linux
55x86-64 and ARM64:
56
57```sh
58docker run --rm ghcr.io/denoland/celld --version
59```
60
61Persist the runtime's local state and pass the standard AWS credential
62environment through:
63
64```sh
65docker volume create celld-state
66docker run --rm --network host \
67 -e AWS_ACCESS_KEY_ID \
68 -e AWS_SECRET_ACCESS_KEY \
69 -e AWS_SESSION_TOKEN \
70 -e CELLD_WATCH=/var/lib/celld/state \
71 -v celld-state:/var/lib/celld \
72 ghcr.io/denoland/celld \
73 --bucket s3://my-cells-bucket \
74 --endpoint https://ACCOUNT.r2.cloudflarestorage.com \
75 --region auto \
76 --listen 0.0.0.0:8080 \
77 --internal-listen 10.0.0.12:8081 \
78 --advertise node-a.internal:8081
79```
80
81Drop `--endpoint` and `--region` for AWS S3. Expose port 8080 through the load
82balancer, and keep port 8081 on the private network.
83
84## Run it
85
86celld uses the standard AWS credential chain. Deploy to an S3-compatible
87bucket, then start celld against the same bucket:
88
89```sh
90celld deploy . \
91 --bucket s3://my-cells-bucket
92
93celld \
94 --bucket s3://my-cells-bucket \
95 --listen 0.0.0.0:8080 \
96 --internal-listen 10.0.0.12:8081 \
97 --advertise 10.0.0.12:8081
98```
99
100Use `--endpoint` for another S3-compatible service and `--region` when it
101cannot be inferred. A `gs://` bucket selects Google Cloud Storage. celld then
102uses the Cloud Storage XML API with generation preconditions. Authentication
103uses Application Default Credentials. celld rejects an S3 `--endpoint` for a
104`gs://` bucket, and it ignores the storage region:
105
106```sh
107celld deploy . --bucket gs://my-cells-bucket
108celld --bucket gs://my-cells-bucket --listen 0.0.0.0:8080 \
109 --internal-listen 10.0.0.12:8081 --advertise 10.0.0.12:8081
110```
111
112A fleet runs one application, and every node loads its
113latest successfully committed deployment from `deploy/current.json`. Run
114`celld --help` for the complete command line.
115Deployment objects use the documented types in `crates/celld/protocol.rs`. `celld
116deploy` invokes `esbuild` from `PATH` for Worker code, accepts the supported
117Wrangler config subset—including co-deployed or asset-only static
118assets—and writes those objects directly. Every node discovers owners and
119peers from bucket leases; there is no account or join service.
120
121Peer HTTP and the operator API use the internal listener. Put every advertised
122address on a trusted private network or an encrypted overlay such as WireGuard
123or Tailscale. Do not publish the internal port. celld rejects a literal public
124IP unless you supply `--unsafe-public-advertise`. An explicit advertised
125address requires an explicit internal-listener address. celld cannot verify a
126hostname or a translated port, so you must route the advertised address to the
127internal listener. The first current node creates `fleet/peer-auth.json` in the
128bucket. All peer requests are
129protocol-versioned, body-bound, HMAC-authenticated, clock-bounded, and
130replay-protected with that fleet secret. Treat access to the bucket and its
131credentials as fleet administrator access.
132
133## Operate a fleet
134
135`celld diagnose` enumerates every node lease by default, then performs a signed
136direct probe of each live peer:
137
138```sh
139celld diagnose --bucket s3://my-cells-bucket
140```
141
142The report keeps checking after an individual failure and distinguishes
143expired records, malformed or unsafe advertise addresses, unreachable peers,
144and incompatible protocols. It also prints each node's coarse resident-cell,
145WebSocket, RSS, CPU, file-descriptor, pressure, and shedding sample. Pass one
146or more `--peer NODE_ID` options to restrict the check.
147
148Set a hard resident-cell limit on each loaded node:
149
150```sh
151CELLD_MAX_RESIDENT_CELLS=1000 \
152celld --bucket s3://my-cells-bucket --listen 0.0.0.0:8080 \
153 --internal-listen 10.0.0.12:8081 --advertise node-a.internal:8081
154```
155
156celld enables a memory threshold at 80% of the available memory by default. Set
157`CELLD_MAX_RSS_MB` to change the threshold, or set it to `0` to disable memory
158pressure shedding. celld measures the memory that the cells hold, and not the
159resident set size of the process. The two differ, because the memory allocator
160keeps some freed pages instead of returning them to the operating system.
161Shedding a cell cannot return those pages, so a threshold on the resident set
162size holds a node in pressure after the node gives every cell back. The `/state`
163route reports both numbers.
164
165celld also applies an absolute cap to the resident set size of the process. The
166cap is 95% of the available memory. It protects the node when the allocator
167holds memory that shedding cannot return, because the operating system stops a
168process that uses more memory than the machine has. The node logs a warning when
169this cap applies.
170
171The cap is a share of the machine, and celld does not derive it from the
172threshold. A `CELLD_MAX_RSS_MB` at or above 95% of the available memory therefore reaches
173the cap. The cap is then the effective limit. The node decides on its resident
174set size, and celld reports this at startup. `CELLD_MAX_RSS_MB=0`
175disables the threshold and the cap together. When celld cannot read the size of
176the available memory, it applies a cap of 125% of an explicit threshold.
177
178Under pressure, celld durably replicates and fences the least-recently used idle
179cells. It then publishes the cells as unowned without resetting their epochs.
180Those cells become inactive, and celld refuses to reacquire new unowned cells.
181
182Each limit releases separately. The threshold releases when the memory in use
183falls to 80% of the threshold. The cap releases when the resident set size falls
184to 80% of the cap. A crossing of one limit therefore does not hold the node
185against the other.
186
187A spare receives no assignment. It acquires a released cell through the same
188bucket protocol when normal traffic reaches it. celld does not shed a cell with
189active work or a live host WebSocket.
190
191## Contributions
192
193Pull requests are disabled. Coding agents make it too easy to send a large,
194low-context change that costs maintainers more time than it saves. Thoughtful
195contributions are welcome; please understand the code, keep the patch focused,
196and respect the review time you are asking for.
197
198Send a `git format-patch` attachment to [[email protected]](mailto:[email protected]).
199
200Contributor License Agreement: By emailing a patch, you certify that you have
201the right to submit it and assign to Deno Land Inc. all rights in the patch
202that you can assign. Where a right cannot be assigned, you grant Deno Land
203Inc. a perpetual, irrevocable,
204worldwide, royalty-free, transferable, sublicensable license to use, modify,
205combine, relicense, redistribute, or publish the patch, in whole or in part,
206with or without attribution.
207
208## License
209
210[Apache-2.0](LICENSE)
211
212See the [limitations](docs/limitations.md) and
213[security](docs/security.md) pages before operating a public fleet.