Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .changeset/admission-overload.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
default: minor
---

# zingod-grpc, zingod: one adaptive work limit, a load-balancer overload signal, no hardware knobs

- Work limit (2048) sheds only when the CPU falls behind (ready requests wait > 100 ms for a core,
15 s); disk, wallet and network waits never count. Linux PSI signals gone
- `/readyz` `down`, reason `overloaded`, while > 10% of wallets are refused or held back by a
congested uplink (60 s average; clears under 2%). Serving continues
- Connections and memory limits come from the host (`Connection cap` at startup; under 256,
zingod refuses to start)
- Per address (an IPv6 /64 = one): `[grpc] work_share_per_ip` of the work limit, default
`0.0625` (`1.0` = none, for load tests)
- Requests take a work slot only once their body has arrived; streams whose wallet stops reading
give theirs up when slots run short
- Index reads on zingod's own threads: `[grpc] read_threads` (32), address-history scans apart in
`[grpc] scan_threads` (4)
- Remove from your config, or zingod refuses to start: `[grpc.overload]`, and under `[grpc]`
`max_connections`, `max_streams_per_connection`, `max_work_streams`, `adaptive_work_streams`,
`max_subscriptions`, `max_point_reads`, `max_range_reads`, `max_scan_reads`,
`silent_timeout_secs`
- `zingod overload` removed; delete `<state_dir>/overload/` if it exists
- Metrics:
- gone: `zingod_grpc_overload_latched` (use `zingod_state_reason{reason="overloaded"}`),
`zingod_grpc_active_subscriptions`, `zingod_grpc_subscriptions_rejected_total`
- renamed: `zingod_grpc_disk_read_wait_seconds{lane}` → `zingod_grpc_read_wait_seconds{pool}`
- new: `zingod_grpc_overload_share{cause}`, `zingod_grpc_adaptive_stream_ceiling`,
`zingod_grpc_adaptive_scheduling_delay_seconds`, `zingod_grpc_parked_bytes`,
`zingod_grpc_parked_evicted_total`, `zingod_grpc_uplink_*`;
`zingod_grpc_admission_rejected_total` gains `reason`
- Logs: `Serving` = `rps`, `conns`, `refused`, `failed`, `evicted`; new `Work limit lowered` /
`restored`, `Uplink congested` / `clear`, `Overload latched` / `cleared`
48 changes: 48 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
- [Quick start](operators/quick-start.md)
- [Configuration](operators/configuration.md)
- [First sync](operators/first-sync.md)
- [Network exposure](operators/network.md)
- [Load and DoS protection](operators/dos-protection.md)
- [Monitoring](operators/monitoring.md)
- [Maintenance](operators/maintenance.md)
- [Network exposure](operators/network.md)
- [Docker](operators/docker.md)
- [Migrating from Zaino](operators/migrating-from-zaino.md)

Expand Down
2 changes: 1 addition & 1 deletion book/src/operators/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ every enabled index, and `p2p.cache_dir` if `[p2p]` is enabled.
| `[submission]` | how `SendTransaction` retries relaying |
| `[p2p]` | Zingod's own Zcash p2p peers (off by default) |
| `[serve]` | gRPC listen address, TLS, gRPC-web, state directory, drain delay |
| `[grpc]` | connection and stream limits, timeouts, trusted proxies, overload thresholds |
| `[grpc]` | [load and DoS protection](dos-protection.md) limits and timeouts, trusted proxies, shutdown grace |
| `[metrics]` | admin listener for metrics and probes (off by default) |
| `[sync]` | block fetching and finality depth |
| `[index.<name>]` | per index: `enabled` and `path` |
Expand Down
81 changes: 81 additions & 0 deletions book/src/operators/dos-protection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Load and DoS protection

Zingod refuses work it cannot take on at once instead of queueing it, so a wallet can try another
server. The defaults suit most nodes.

## Settings

| Setting | Default | What it does |
| ------------------------------- | -------- | ------------------------------------------------------------------ |
| `[grpc] max_connections_per_ip` | `128` | Connections one address may open; more are closed. High because mobile carriers put many wallets behind one address. Behind a proxy, set [`trusted_proxies`](network.md#behind-a-proxy) so this counts wallets, not the proxy. |
| `[grpc] work_share_per_ip` | `0.0625` | Share of the request limit one address may use (1/16: it takes 16 addresses to fill a node). `1.0` turns it off, for load tests from a few addresses. |
| `[grpc] read_threads` | `32` | Index reads at once (blocks, tree states, transactions). |
| `[grpc] scan_threads` | `4` | Transparent-address history reads at once. Kept apart so a flood of them never slows block reads. |
| `[grpc] unread_timeout_secs` | `300` | A connection whose wallet stops reading for this long is closed. |
| `[serve] max_address_rows` | `100000` | Transparent receives one address request may walk; more is refused with `RESOURCE_EXHAUSTED`. |

An IPv6 /64 counts as one address. The thread defaults suit NVMe; for other disks:

| Disk | `read_threads` | `scan_threads` |
| ---------------------- | -------------- | -------------- |
| NVMe (default) | 32 | 4 |
| SATA SSD, cloud volume | 16 | 2 |
| HDD | 4 | 1 |

## Limits

Fixed, or sized from the host at startup:

| Limit | Value | Over it |
| -------------------------------------- | ----------------------------------------------------- | -------------------------------- |
| connections | open-file limit − 1024, or half of memory at 128 KiB each, whichever is lower | closed |
| streams per connection | 100 | refused |
| requests in progress | 2048, lowered while the CPU falls behind (down to 128) | `UNAVAILABLE` |
| request size | 64 KiB, `SendTransaction` 2 MB | `RESOURCE_EXHAUSTED` |
| request upload time | 30 s | `DEADLINE_EXCEEDED` |
| responses waiting to be read, requests still uploading | a quarter of memory | the heaviest address's fullest connection closed |
| `/readyz`, `/status` | 10 at once, then 1 per second, per connection | `429` |

- Startup logs the connection limit as `Connection cap`. Under 256, Zingod refuses to start: raise
the hard open-file limit (systemd `LimitNOFILE=`, docker `--ulimit nofile=`) or give it more
memory.
- A refusal ends a wallet's sync: pepper-sync and librustzcash do not retry.

## Browser origins

With [gRPC-web](network.md#browser-clients-grpc-web) on, any website can have browsers call your
server. Policies take effect within a second and survive restarts; the most specific one wins:

| Command | Effect |
| ------------------------------ | --------------------------------------------------------- |
| `zingod origin block <domain>` | refuse it and its subdomains with `PERMISSION_DENIED` |
| `zingod origin allow <domain>` | serve it even when a parent domain is blocked |
| `zingod origin reset <domain>` | remove its policy |
| `zingod origin` | list the policies |

An allowed origin still gets the same limits as everyone else.

## Overload

`/readyz` reports `overloaded` (`503`) once 10% or more of connections, averaged over a minute,
are refused at the request limit or held back by a congested uplink. It clears under 2%. Zingod
keeps serving the whole time; only `/readyz` changes. Refusals past `work_share_per_ip` never
count. `zingod_grpc_overload_share` shows the share by `cause`.

The uplink counts as congested when, for 30 seconds, the median of at least 10 sending
connections queues 50 ms or more, or 2% or more of bytes are resent. Connections through a trusted
proxy are not checked.

## Troubleshooting

| You see | Cause | Do this |
| --------------------------------------------------------- | ------------------------------ | ----------------------------- |
| refusals, `adaptive_stream_limit` under 2048 | CPU | more cores or nodes |
| refusals, limit at 2048, `read_wait_seconds{pool="read"}` high | disk | faster disk, more RAM |
| refusals, limit at 2048, `read_wait_seconds{pool="read"}` low | too many wallets | more nodes |
| `overload_share{cause="network"}` | uplink | more bandwidth or nodes |
| `connections_rejected_total` rising | connection limits | check `trusted_proxies` |
| `admission_rejected_total{reason="client_share"}` rising | one address sending too much | nothing: refused for you |
| `parked_evicted_total` rising | clients not reading or uploading slowly | nothing: closed for you |

Metric names are prefixed `zingod_grpc_`.
24 changes: 0 additions & 24 deletions book/src/operators/maintenance.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,6 @@ so dashboards can tell planned maintenance from a crash.

Both commands are idempotent.

## Overload

A node that is persistently short of capacity reports `down` with reason `overloaded`, so load
balancers move traffic away from it. Thresholds are set under `[grpc.overload]` (0 disables a
cause). A cause is raised after its signal stays above the threshold for the enter time, and
cleared after it stays below half the threshold for the exit time.

| Cause | Signal, per minute | Enter / exit |
| ---------------------------- | ------------------------------------------------------------- | ------------ |
| `CPU pressure`, `IO pressure` | share of time Zingod's cgroup waited (Linux PSI) | 2 / 3 min |
| `refusing work` | at least 10% of requests refused, at 1/s or more (exit: < 2%) | 5 / 5 min |

Override the detector on a running node, without a restart:

```sh
zingod overload off # never report overloaded
zingod overload on # back to automatic
zingod overload set <key> <value> # override a threshold, e.g. cpu_pressure_percent 40
zingod overload unset <key> # back to the config's value
```

Overrides are stored in `state_dir` and persist across restarts. Zingod applies them within a
second and logs a warning while any is in effect.

## systemd

```ini
Expand Down
28 changes: 16 additions & 12 deletions book/src/operators/monitoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Zingod reports a single state. The same value appears in `/readyz`, `/status`, t
| State | Meaning | `/readyz` |
| -------------- | ----------------------------------------------------------------------------------------- | --------- |
| `held` | an operator ran [`zingod hold`](maintenance.md#operator-hold) | `503` |
| `down` | cannot serve: the server is stalled or [overloaded](maintenance.md#overload), startup is waiting for a validator, or the tip is unverified and stale | `503` |
| `down` | cannot serve: the server is stalled, startup is waiting for a validator, or the tip is unverified and stale; or [overloaded](dos-protection.md#overload): still serving, new wallets belong elsewhere | `503` |
| `provisioning` | starting up, or installing an [index snapshot](first-sync.md#index-snapshot) | `503` |
| `degraded` | serving a recent tip that no trusted validator has confirmed (p2p peers supplied it) | `200` |
| `syncing` | serving, but behind the best block; or no validator's mempool is available yet | `503` |
Expand All @@ -31,8 +31,8 @@ Zingod reports a single state. The same value appears in `/readyz`, `/status`, t
| `serving` | `{start, mbps}`: gRPC egress over the last full 10-minute UTC window |
| `degraded`, `down`, `held` | `{reason, message}` |

`reason` is one of `no_validator_reachable`, `tip_unvouched`, `tip_stale`, `runtime_stalled`,
`overloaded`, `goaway_pending` or `goaway_sent`.
`reason` is one of `no_validator_reachable`, `tip_unvouched`, `runtime_stalled`, `overloaded`,
`goaway_pending` or `goaway_sent`.

## Endpoints

Expand Down Expand Up @@ -107,13 +107,17 @@ ts=… level=info target=zingod::telemetry::progress message="Syncing blocks" he

### The `Serving` line

Once a minute, the gRPC server logs a `Serving` summary: `rps` (streams completed per second) and
`conns` (open connections). It is logged at WARN if, during that minute, any request failed or
was refused, took more than a second to its first response (`slow`), stalled (`stalled`), or a
connection was refused at a limit (`conns_refused`). These fields appear only when non-zero.
Once a minute, the gRPC server logs a `Serving` summary: `rps` (requests completed per second)
and `conns` (open connections). If any request was refused (`UNAVAILABLE`, `RESOURCE_EXHAUSTED`)
or failed (`INTERNAL`, `UNKNOWN`, `DATA_LOSS`), or a connection was
[evicted](dos-protection.md#limits) that minute, it is logged at WARN with `refused`, `failed`
and `evicted` counts. The first failure of each minute is also logged as `Request failed` (ERROR)
with its message. Everything else is in the [metrics](#metrics).

- `INTERNAL`, `UNKNOWN` and `DATA_LOSS` count as failures. `UNAVAILABLE` and
`RESOURCE_EXHAUSTED` count as refusals. Other codes are client errors, counted in
`zingod_grpc_requests_total{code}`.
- The first failure of each minute is also logged as `Request failed` (ERROR), and the first
refusal not caused by capacity as `Request unavailable` (WARN).
Load events, each logged once as it starts and ends (see [Load and DoS protection](dos-protection.md)):

| Starts (WARN) | Ends (INFO) | Fields |
| --------------------------------------------- | ---------------------- | --------------------------------------- |
| `Work limit lowered`: the CPU fell behind | `Work limit restored` | `limit`, `cpu_wait_ms` |
| `Uplink congested` | `Uplink clear` | `queue_delay_ms`, `retransmitted_percent` |
| `Overload latched`: `/readyz` 503 | `Overload cleared` | `refused_percent`, `network_percent`, `connections` |
41 changes: 5 additions & 36 deletions book/src/operators/network.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ Zingod has two listeners:

Connections to validators are plain HTTP JSON-RPC.

Limits on connections, streams and reads are set under `[grpc]`; see the
[reference](configuration.md#reference). When a limit is reached, the request is refused, not
queued.
Limits on connections, requests and reads are set under `[grpc]`; see
[Load and DoS protection](dos-protection.md).

## TLS

Expand Down Expand Up @@ -46,36 +45,12 @@ after changing the listen address, delete `cert.pem`.
allowing any origin. Native gRPC is unaffected.

Enabling it makes the server usable from any website. A popular site embedding it can send load
proportional to its own traffic.

`zingod origin` manages per-origin policy. Changes apply within a second and persist until
changed:

| Command | Effect |
| ------------------------------- | -------------------------------------------------------------- |
| `zingod origin block <domain>` | refuse requests from the origin with `PERMISSION_DENIED` |
| `zingod origin allow <domain>` | serve the origin even when a parent domain is blocked |
| `zingod origin reset <domain>` | remove the origin's policy |
| `zingod origin` | list the policies in effect |

- Policies apply to the registrable domain and its subdomains. The most specific policy wins, so
`allow app.example.com` can override `block example.com`.
- Every origin that is not blocked meets the same limits as any other client. Clients can set any
`Origin` header, so an origin never lifts a limit.
- `zingod_grpc_origin_requests_total{verdict}` counts browser requests by policy. To find an
abusive origin, check your proxy or edge logs.
proportional to its own traffic. To refuse a site, see [Browser
origins](dos-protection.md#browser-origins).

Over HTTP/1.1, browsers open one connection per in-flight stream, each counting against
`max_connections_per_ip`. Serve over TLS so browsers use HTTP/2.

## Stream timeouts

Streams have no total time limit. Two settings close streams that stop making progress:

- `unread_timeout_secs`: the client stopped reading. The connection is closed.
- `silent_timeout_secs`: the server has had nothing to send. The stream ends with `UNAVAILABLE`.
`GetMempoolStream` is exempt.

## Behind a proxy

Behind a proxy, every connection comes from the proxy's address, so `max_connections_per_ip` would
Expand Down Expand Up @@ -113,10 +88,4 @@ stream {
For HAProxy, use `server zingod 127.0.0.1:8137 send-proxy-v2` in a `mode tcp` backend.

If your proxy cannot send the header, leave `trusted_proxies` empty and raise
`max_connections_per_ip` to `max_connections`.

## Open files

Each connection uses a file descriptor. At startup, Zingod raises its soft `RLIMIT_NOFILE` to the
hard limit and refuses to start if `max_connections` plus 1024 does not fit. Raise the hard limit
(`LimitNOFILE=` in systemd, `--ulimit nofile=` in Docker) or lower `max_connections`.
`max_connections_per_ip` past the connection limit Zingod logs at startup (`Connection cap`).
Loading
Loading