Repository navigation
Commit 5e431f3
committed
Keep syncs and file system work off a cluster node's event loop
* A clustered namespace's SQLite opens with syncs off. An object's
commits are durable once the bucket holds them, and a node reuses its
files only within the process that wrote them, so a sync guards
against no crash. Each sync blocked the event loop: on a loaded
Windows runner, opening a new Durable Object took three syncs of
100-420 ms in all, and a commit's WAL sync up to 235 ms. Opening 64
at once blocked the loop for 3-8 s of a 10 s burst, in turns of up to
670 ms, and the node's lease lapsed
* A cluster namespace's directory is emptied as it links, but for its
`.cluster` marker. An earlier process's files go unread: the bucket
holds the objects and their alarms, and written with no syncs, any of
them may be torn after a crash of the machine. The alarm scheduler's
database, which a later process would open, could keep the node from
starting; a facet index, which a takeover reads to find the facets'
databases it removes, could fail the takeover or leave stale facets.
Only a directory the cluster marked is emptied: an unmarked one is
claimed only if it is empty or holds nothing but the alarm
scheduler's database, which is all workerd leaves in a namespace
with no objects, and the node refuses to start over any other
* A cluster's facet indexes skip their syncs too. So does the
checkpoint that folds a cloned facet's WAL
* An object workerd evicts for being idle, kept to resume over its
files, has them synced first, on the blocking pool. A sync is where a
failed writeback reports its I/O error; if it fails, the object is
not kept, and the next request restores it from the bucket. The
cluster crate's tests skip the sync: their files are scratch, and on
macOS and Windows a sync waits for the device, which made the owner
simulation, with its hundreds of evictions, half again as slow
* A claim that finds an eviction of the object at its epoch still
running, uploading or syncing, waits for it to settle, then resumes
the object over its files rather than restoring it from the bucket at
the next epoch. The eviction awaits nothing a claim holds, so the
wait cannot deadlock; if its sync failed, the claim restores the
object from the bucket as before. An eviction counts as running from
when workerd retires the object, before the task that runs it starts
* A takeover runs on the blocking pool what it can: removing the
object's files (through a directory it opens there), creating its
copies' directory, creating and removing the restore's downloads,
and moving restored databases into place. Creating the copies'
directory took up to 334 ms on that runner
* A takeover, and an eviction's sync, holds the object: each task it
starts on the blocking pool, its restore's replay included, shares a
per-object lock, so a takeover cancelled meanwhile holds it until
the last such task is done, and the next one, at the next epoch or a
retry at the same one, waits rather than have the earlier one's
removal, move or replay run beside its own. An epoch cannot guard
these: the object's files have the same paths whatever the epoch,
and a check before each operation leaves a gap before the operation.
The lock's entry goes with its last holder, a blocking task's
included
* Each restore has a spool of its own, numbered per process. A
download's writer, which the bucket client starts and nothing awaits
once a takeover is cancelled, so writes only its own restore's
files. Earlier spools are removed where they can be: nothing reads
them, and on Windows an open file cannot be removed
* Copies, whose directories an epoch names, are not held. A takeover
keeps later epochs', empties its own, and removes earlier ones' where
it can: an earlier epoch's eviction may still be uploading from its
copies or its compaction writing them. An eviction's upload, which
can take long, so holds up no takeover at the next epoch
* What stays on the event loop: numbering a restored facet, which goes
through the namespace's storage, cloning a facet, which is
synchronous for the actor that asks, and SQLite opening an object's
files
With these, that burst takes about 0.4 s with no turn of 100 ms or
more.1 parent f09a9f0 commit 5e431f3
17 files changed
Lines changed: 754 additions & 94 deletions
File tree
- src/workerd/server
- cluster
- factory
- server
- tests/cluster
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
377 | 377 | | |
378 | 378 | | |
379 | 379 | | |
| 380 | + | |
380 | 381 | | |
381 | 382 | | |
382 | 383 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
408 | 408 | | |
409 | 409 | | |
410 | 410 | | |
411 | | - | |
412 | | - | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
413 | 418 | | |
414 | 419 | | |
415 | 420 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
162 | | - | |
163 | | - | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
164 | 171 | | |
165 | 172 | | |
166 | 173 | | |
| |||
317 | 324 | | |
318 | 325 | | |
319 | 326 | | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
320 | 333 | | |
321 | 334 | | |
322 | 335 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
77 | 78 | | |
78 | 79 | | |
| 80 | + | |
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| |||
765 | 767 | | |
766 | 768 | | |
767 | 769 | | |
768 | | - | |
| 770 | + | |
| 771 | + | |
769 | 772 | | |
770 | 773 | | |
771 | 774 | | |
772 | 775 | | |
| 776 | + | |
773 | 777 | | |
774 | 778 | | |
775 | 779 | | |
776 | 780 | | |
777 | 781 | | |
778 | 782 | | |
779 | | - | |
| 783 | + | |
| 784 | + | |
780 | 785 | | |
781 | 786 | | |
782 | 787 | | |
| |||
786 | 791 | | |
787 | 792 | | |
788 | 793 | | |
789 | | - | |
| 794 | + | |
790 | 795 | | |
791 | 796 | | |
792 | 797 | | |
793 | 798 | | |
794 | 799 | | |
795 | 800 | | |
796 | 801 | | |
797 | | - | |
| 802 | + | |
798 | 803 | | |
799 | 804 | | |
800 | 805 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
334 | 334 | | |
335 | 335 | | |
336 | 336 | | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
337 | 342 | | |
338 | 343 | | |
339 | 344 | | |
340 | | - | |
| 345 | + | |
341 | 346 | | |
342 | 347 | | |
343 | 348 | | |
| |||
751 | 756 | | |
752 | 757 | | |
753 | 758 | | |
754 | | - | |
755 | | - | |
756 | | - | |
757 | | - | |
758 | | - | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
759 | 767 | | |
760 | 768 | | |
761 | 769 | | |
| |||
779 | 787 | | |
780 | 788 | | |
781 | 789 | | |
782 | | - | |
| 790 | + | |
783 | 791 | | |
784 | 792 | | |
785 | 793 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
161 | | - | |
| 161 | + | |
162 | 162 | | |
163 | | - | |
164 | | - | |
165 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
166 | 169 | | |
167 | 170 | | |
168 | 171 | | |
| |||
0 commit comments