Skip to content

Let an idle cloud install and its database sleep - #58

Merged
qfeuilla merged 1 commit into
mainfrom
deploy
Oct 9, 2026
Merged

qfeuilla merged 1 commit into
mainfrom
deploy

Conversation

@qfeuilla

@qfeuilla qfeuilla commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

An idle GCP install never scaled to zero and kept Neon awake. Causes and fixes:

  • Early wakes: the next tick was booked at the end of a grid as wide as the wait, so a 6h wait landed at a random earlier point, again and again. A wake now lands at the moment asked, rounded up to the second.
  • Looks "just in case": a loop with nothing left now sleeps until a write wakes it (role_loop_due.due_ms may be empty, one released migration); sweeps no write wakes run on the role's next pass once their interval passed; only a look a loop asked for books a wake.
  • Idle polling: serverless dispatcher and broker processes ran every loop on its safety timer for their whole life. They now look on a timer only while they have work.
  • Reconnecting a sleeping database: the LISTEN connection is kept only while the process is busy (Listening::WhileBusy, a Busy guard held by every request to the end of its body, a broker line, and work that outlives its request). A connection Neon closes while the process is quiet stays down until work arrives, and that reconnect does not ring every role.
  • Cloud Build Pub/Sub: every build in the GCP project woke the dispatcher; a build now announces itself when it starts, and the subscription is removed.
  • Editor: VS Code closes its live streams to a remote install after 5 minutes away, and reopens them when the person returns.
  • Neon: Tangle creates it at 0.25 to 1 CU, asleep after 5 minutes.
  • Terminate warning wording for an instance's infra.
  • MEMORY: two rules: keep the hot path fast, keep the install able to scale to zero.

Checked locally: nextest (3387), doc tests, clippy, parse-only build, examples, db tests (740), JS packages, extension compile, docs, terraform validate, and four e2e tests (a run, an infra stop and cancel, a drain, a program starting instance infra). The behaviour on a real GCP install is not tested here.

…cloud streams when away, and start Neon at its smallest size

- A wake lands where it was asked for (the next whole second), not at a random point inside a grid as wide as the wait.
- Nothing is looked at "just in case": a loop with nothing left sleeps until a write wakes it (role_loop_due.due_ms may be empty), a sweep runs on the role's next pass once its interval passed, and only a look a loop asked for books a wake.
- A serverless writer runs its loops' safety looks only while it has work, listens to the database only while busy (a connection lost while quiet stays down until work arrives), and rings every role only after a real loss.
- Background work that outlives a request (a lifecycle command, a run's delivery, a program's infra start) and a broker line keep the process listening until they end.
- A build announces itself when it starts; the Cloud Build Pub/Sub push that woke the dispatcher for every build in the project is gone.
- The VS Code extension closes its live streams to a remote install after 5 minutes away and reopens them on return.
- Tangle's database skill creates Neon at 0.25 to 1 CU, asleep after 5 minutes, and the cost notes match.
- The per-instance terminate warning names the instance's infra plainly.
- MEMORY: keep the hot path fast and the install able to scale to zero.
@qfeuilla
qfeuilla merged commit 4905688 into main Oct 9, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant