mirror of
https://github.com/jasonxu114514/opencode2api.git
synced 2026-12-06 08:03:47 +00:00
feat(warp): preload half the pool and register without a fixed gap
Registrations were paced by a fixed 12-second gap, which made a cold pool and a 429 replacement wait minutes for capacity. Remove the gap: the registrar now issues registrations back to back in the background, serialized by the pool's create mutex, and only a rejected attempt backs off (doJSON still honours Retry-After). Keep half of warp.pool_size (at least one) hot as a preload: the first exit still gates readiness, the rest register in the background, and desiredLocked/scaleDown treat the preload as a floor so idle surplus is still retired after 60 seconds but the warm bench survives. A 429 or 403 removes the exit from the ring and the next request uses a preloaded exit immediately. /healthz reports warp.preload, and the WebUI and all four READMEs describe the behaviour.
This commit is contained in:
1 parent
b8b1454a0e
commit
7d34bdde33
9 files changed
+51
-45
No files matched your search
@@ -234,7 +234,7 @@ Free models never need a Zen key: with `anonymous: true` they are served by the
|
||||
|
||||
The tunnel lives inside the gateway process: it registers a WARP device, speaks WireGuard over UDP to Cloudflare, and terminates in a userspace network stack. It needs no TUN device, root, `NET_ADMIN`, or routing-table change, but the host or container must be able to send UDP to Cloudflare's endpoint (port `2408`). Registration and the `warp=on` trace probe run at startup; if WARP cannot initialize, startup fails instead of silently falling back to proxies. Enabling it through the WebUI is also fail-closed: a bad value returns an error and the previous runtime keeps serving.
|
||||
|
||||
`warp.pool_size` (1–32, default `2`) is an upper bound, not a fixed count. The active ring follows concurrency: one exit per in-flight lease plus a spare, at least one, and never more than the configured maximum. Surplus exits that stay idle for 60 seconds are retired, so a burst scales the ring up and a quiet period scales it back down. An exit answered with 429 or 403 is retired immediately — a free-model request keeps switching to another exit and only returns the last 429 to the client once `retry.max_attempts` is spent — and the retired exit is re-registered in the background right away (registrations remain paced by Cloudflare's 12-second API limit, so a larger maximum also warms up more slowly; size it to your peak free-model concurrency). `warp.stack` selects `ipv6` (default), `ipv4`, or `dual`.
|
||||
`warp.pool_size` (1–32, default `2`) is an upper bound, not a fixed count. The first exit registers synchronously and gates readiness; the pool then registers half of the ceiling (at least one) in the background, so a burst finds warm exits instead of waiting for registrations. The active ring follows concurrency: one exit per in-flight lease plus a spare, never more than the maximum. Surplus exits that stay idle for 60 seconds are retired, so a quiet period scales back down. An exit answered with 429 or 403 is retired immediately and a pre-registered exit takes its place — a free-model request keeps switching to another exit and only returns the last 429 to the client once `retry.max_attempts` is spent — and the retired exit is re-registered in the background right away. Registrations are serialized but no longer spaced by a fixed delay. `warp.stack` selects `ipv6` (default), `ipv4`, or `dual`.
|
||||
|
||||
The upstream free quota is scoped to the egress block, so rotation only helps when a replacement leaves from a different one: an IPv6 exit is keyed and cooled by its `/64` for 30 minutes, an IPv4 exit by its `/32`. Cloudflare's WARP IPv4 egress is usually one shared NAT address, which other users routinely exhaust; the IPv6 stack gets an egress derived from the outer WireGuard source. Set `warp.source_ipv6` to an IPv6 prefix routed to the host (usually a `/64`), with the default `ipv6` stack to make every exit bind its own source address from that prefix. The prefix needs `IPV6_FREEBIND` on Linux (the gateway sets it) or addresses already assigned to an interface. Endpoint family is not probed in advance: the handshake tries IPv6 endpoints first and falls back to IPv4 ones when none answer (the exit then egresses from the shared address). Leave `source_ipv6` empty to keep the host's default source address. On networks whose WARP egress pool is saturated every fresh exit can still answer 429; the gateway then churns exits without ever surfacing a 429 before the attempt budget is spent. `/healthz` reports a `warp` block and answers 503 while WARP is enabled but no exit is active; `no_healthy_proxies` only blocks readiness when WARP is off or Go keys need proxies. Diagnostics acquire an exit but never rotate or penalize it. Turning WARP off restores proxy routing for the free lanes.
|
||||
|
||||
@@ -287,7 +287,7 @@ See [config.example.json](config.example.json) for a complete starting configura
|
||||
| `zen_keys`, `go_keys` | At least one upstream key is required unless anonymous access is enabled. |
|
||||
| `anonymous` | `false`. |
|
||||
| `warp.enabled` | `false`; free-lane traffic leaves through Cloudflare WARP and no proxy. |
|
||||
| `warp.pool_size` | `2`; upper bound on WARP exits (the active ring follows concurrency), 1–32. |
|
||||
| `warp.pool_size` | `2`; upper bound on WARP exits (half pre-registered in the background; the active ring follows concurrency), 1–32. |
|
||||
| `warp.stack` | `ipv6`; `ipv6`, `ipv4`, or `dual`. |
|
||||
| `warp.source_ipv6` | empty; IPv6 prefix (`/64`) each exit binds its outer source from; requires `stack = "ipv6"`. |
|
||||
| `prefer` | `go`; accepts `go` or `zen`. |
|
||||
|
||||
Reference in new issue
Block a user