Performance by default
mistri keeps an App fast by counting round trips to the database, because the distance to it, not the CPU, is what a person waits for.
What mistri does
Section titled “What mistri does”- Reads that belong together share one round trip: a record page, boot, or page loader runs its parallel
Promise.allqueries on one sharedREPEATABLE READsnapshot connection, pipelined into a single flight (requirespg >= 8.20; see One request’s time). - The first page of a tenant App on PostgreSQL is five round trips on first entry (one on reload): discovery and admission, and the App’s payload with the page’s own reads. The bell’s unread count is asked after the page has drawn.
- Connections come from one shared pool per database, and people arriving at once are let in a few at a time, in order, instead of all at once.
- Platform tests hold budgets: a read at most three round trips, a command at most six, a first page at most sixteen.
What you do
Section titled “What you do”Feel the distance while you build. A database on your laptop answers in a fraction of a millisecond, so a request that makes forty round trips looks instant until it is deployed.
npx @mistriwork/mistri dev --db-latency 20--db-latency <ms> (or MISTRI_DEV_DB_LATENCY) delays every database round trip by that long. It is refused under NODE_ENV=production and when serving a build. While you develop, each request that touched the database logs its cost:
mistri: GET /api/records/lead 200: 2 round trips, db 41 ms, cpu 3 msA request over its budget says so, and links here.
Index what the App reads. mistri check compares the access paths an App declares (a related list’s foreign key, a list’s sort and fixed filter, a tenant’s ownership column, a search box) with the PostgreSQL index list and prints index-missing with the CREATE INDEX line that fixes it: information under 10,000 estimated rows, a warning above. --no-index-check skips it. See check codes.
Hold a budget in the App’s own tests:
import { roundTrips } from '@mistriwork/mistri/testing';
const page = await manager.request('/api/records/lead');assert.ok(roundTrips(page) <= 3);roundTrips is Preview. Last, run mistri check --deploy to see how many connections the pools open against your database’s limit, and keep the database in the same region as the container.
What it measured
Section titled “What it measured”A field deployment: a half-vCPU container with the database about 16 ms away.
| Load | Result |
|---|---|
| One person | list page 0.8 to 0.95 s, record 0.9 to 1.1 s, a save 0.6 s |
| 25 people for one hour | p50 181 ms, p95 587 ms |
| 75 people | p95 1.5 s at 17 requests a second |
See performance and pools for sizing the pools and reading the meters.