# CPU Time and Database

> Where to tune the Worker: the CPU limit, how far the database is, and Hyperdrive's query cache.

*Canonical: https://makerkit.dev/docs/void-cloudflare/operations/cpu-and-database*

---

Three settings decide most of what a request costs. Change one only for a reason you measured in Workers Logs or Cloudflare's metrics.

## CPU Time per Request

`worker.limits.cpu_ms` in `apps/web/void.config.ts` sets how much CPU time one request may use, from 1 to 300000 ms.

```ts
export default defineConfig({
  worker: { limits: { cpu_ms: 30000 } },
});
```

- **Workers Paid** allows up to 300000 ms; **Workers Free** only 10 ms, too little for password hashing. The kit needs Paid ([Deployment](../deployment/overview)).
- It is CPU time, not waiting: waiting for the database or a fetch is free.
- Raise it only when a request is cut off for CPU. If one route needs minutes of CPU, it belongs in a queue job ([Background Jobs](../outbox/overview)), not a request.

## Where the Database Is

Every query is a round trip from the Worker to your database, and Hyperdrive keeps connections to it pooled and warm. A far database costs more than anything in your code.

- Create the database in the region closest to most of your visitors.
- For pages that run several queries, try Smart Placement (Cloudflare dashboard → your Worker → Settings → Placement): it runs the Worker near the database. Compare before and after; it can make a page with one query slower ([Placement](https://developers.cloudflare.com/workers/configuration/placement/)).
- Count queries per page in a loader before anything else. A request has one database connection, so queries run one after another even inside `Promise.all`: fewer queries (a join, one combined query) is what saves round trips.

## Hyperdrive's Query Cache

Hyperdrive caches `SELECT` results for up to 60 seconds by default, and `void deploy` leaves it on. For this app it is off by design: a cached read keeps a revoked session, or a member removed from an organization, alive for up to a minute. Turn it off once after the first deploy ([Production Deploys](../deployment/production)) and check it in the dashboard (Hyperdrive → your config → Caching). The [health check](./health) is meaningful only with the cache off.

## Connections

The deployed Worker connects through the `HYPERDRIVE` binding. `DATABASE_URL` is for deploys and local work and is never a Worker secret ([Production Deploys](../deployment/production)).
