Performance validation
Maglane's capacity depends on active route count, check intervals, shared workspace ownership, response sizes, and storage throughput. A small successful installation does not establish how it behaves with millions of routes. Use this guide when releasing a backend change or sizing a deployment.
Goal
Measure API latency, errors, checker/scraper backlog, database growth, and statistics drops under a representative sustained workload. Choose the acceptable latency and growth budgets before the run.
| Check | What it can establish | What it leaves open |
|---|---|---|
| Unit and integration regressions | Correctness and bounded operation counts for controlled fixtures. | Full-system throughput and long-running resource growth. |
| Component benchmarks | Cost per queue cycle, decode, or checker request on the measured host. | Production networking, shared-tenant persistence, and outage behavior. |
| Smoke gate | The load scripts, authentication, snapshots, and log collection work. | Production capacity and durability. |
| Release gate | Sustained behavior for the recorded dataset, hardware, and test duration. | Different workloads and longer unmeasured periods. |
Retained local rehearsal fixtures sign in once when the backend becomes ready and keep the new token in private fixture state. A week-old fixture can contain an expired token even when its signing key is intact. Login and protected API failures must still fail validation; do not suppress a 401 or extend token lifetimes to make a run pass. Recovery must accept the token held before backup and reject the separately revoked token after restoration. Observer errors and failed preparation runs remain failures, with no sustained-load credit.
The backend walkthrough explains which components these measurements cover. Testing lists the correctness checks to run before expensive load validation.
Prepare an isolated target
Use a dedicated Maglane installation, PostgreSQL database, and Redis service. The harness imports data and changes storage volume; queue regression fixtures can flush their configured database. Do not point them at a live installation.
- Migrate and start the target at the proposed component versions.
- Seed the intended number of active routes, sources, workspaces, and shared ownership. Use reachable controlled judges and representative proxy behavior.
- Set the checker/scraper concurrency and intervals you intend to deploy.
- Install
k6and Docker with Compose support on the load runner. - Supply a dedicated test account/token and a backend log source for the whole run. An empty log file does not satisfy the drop check.
- Record hardware, container limits, component/dependency versions, shard counts, retention settings, and dataset size before starting.
Run the default capacity profile with PROXY_QUEUE_ENCRYPT_CREDENTIALS=false.
If the deployment opts into queue encryption, repeat the same matrix with it
enabled and report its measured capacity separately.
From the maglane repository root, prepare the API target and token:
export MAGLANE_BASE_URL=http://127.0.0.1:5656
export MAGLANE_REGISTER_IF_MISSING=false
read -rs -p 'Dedicated test account bearer token: ' MAGLANE_TOKEN
export MAGLANE_TOKEN
The harness uses this account's default workspace. Confirm it is the workspace whose dataset you prepared. To target an installer-created stack in another directory, also set the distribution harness inputs:
export MAGLANE_COMPOSE_FILE=/absolute/path/to/installation/docker-compose.yml
export MAGLANE_ENV_FILE=/absolute/path/to/installation/.env
See the distribution harness README for suite-specific rates, virtual users, and fixture controls.
Go and dependency upgrades
Use the Go version declared in maglane-backend/go.mod and run the full backend
checks described in Testing. For before/after
comparisons, run the plaintext queue decode, Redis dequeue/requeue, checker HTTP,
and client-cache churn benchmarks from the harness README.
The HTML scraper uses golang.org/x/net v0.62.0 to address GO-2026-6860, a reachable HTML-parser allocation vulnerability. Its module graph also upgrades x/crypto, x/sys, x/text and x/sync. Retain the dependency scan and full normal/race, vet and build results for this exact graph, then repeat recovery, smoke and the entire load gate. Results from the preceding graph cannot qualify the upgrade.
Use the same host, toolchain settings, dataset, and dependency configuration. Record allocations, time per operation, and throughput. For checker/queue changes, count added cryptographic operations, JSON encodes, Redis commands, and database queries per check. Current plaintext payloads must reuse the stored route hash, and normal requeues must leave the payload untouched.
Include stalled dependencies and reconnects in comparisons. For example, the
Redis client 9.22 defaults changed read/write timeouts from 3 to 5 seconds,
retry backoff from 8ms/512ms to 10ms/1s, and idle TCP keep-alive probing from
five minutes to 30 seconds. Explicit single-mode REDIS_URL values still
override the client defaults. A normal-path benchmark does not expose those
outage latencies.
Include cold dashboard reads when validating dashboard snapshots. A warm view is
one joined read; a view of a snapshot older than 30 seconds starts at most one
build per workspace across the cluster and waits at most two seconds. Record
the build-time distribution of ordinary million-route workspaces separately
from request latency, together with checker throughput and projection lag while
builds run. Ordinary builds must finish within DASHBOARD_BUILD_DEADLINE; set
the deadline and DASHBOARD_BUILD_CLUSTER_LIMIT from these measurements. After
a lease expires, its statements stop at their statement timeout, so measure how
long expired builds overlap their successors. Cold preparation time provides no
credit toward the unchanged load durations or latency budgets. A private diagnostic alone does not establish a capacity
improvement or release readiness.
During startup queue loading, select each physical route once when it has an active owner. Shared routes must still hydrate every active workspace and their existing credentials. Measure enumeration alongside checker and projection work on the million-route profile. A stopped page comparison cannot establish startup readiness or replace the unchanged recovery, smoke and load gates.
Test matrix
| Suite | Script | Default duration | Primary focus | Gate criteria |
|---|---|---|---|---|
| Seed | scripts/perf/k6/seed.js | until the pool is imported | one import of the whole proxy pool before the start snapshot | every import valid and a proxy visible afterwards |
| Read-heavy | scripts/perf/k6/read-path.js | 30m | the UI's first-load requests: proxy list, filters, dashboard, viewer, check history | error budget, request coverage, latency, and dropped arrivals |
| Write-heavy | scripts/perf/k6/write-path.js | 30m | sustained POST /api/addProxies ingestion from the proxy pool | error budget, request coverage, latency, and dropped arrivals |
| Mixed soak | scripts/perf/k6/mixed-soak.js | gate default 24h; standalone script 2h | long-running mixed reads + writes | per-scenario thresholds plus growth/drop budgets below |
| Growth budget | scripts/perf/assert-snapshot-delta.sh | N/A | queue and DB growth across test window | queue/db deltas within configured limits |
| Drop budget | scripts/perf/check-drop-budget.sh | N/A | proxy statistics queue drop protection | dropped_total must be less than or equal to configured budget |
Release gate procedure
Run from the maglane distribution repository root:
cd scripts/perf
./run-gate.sh
The default release gate seeds the proxy pool, captures the start snapshot,
then runs 30-minute read and write suites plus a 24-hour mixed soak. It rejects
shorter soaks, skipped drop checks and missing/empty log sources. For a short
functional check, run PERF_GATE_MODE=smoke ./run-gate.sh. Smoke mode does not
establish production capacity.
Each scenario has an error budget: 1% of requests for reads and 2% for imports.
A request counts against it when any check fails, including an HTTP 200
response with GraphQL errors or malformed import/statistics data. Each scenario
must make a request, and statistics scenarios require an existing proxy in the
selected workspace. Missing proxies abort setup. They do not substitute a
different workload. Each scenario may drop at most
PERF_MAX_DROPPED_ITERATION_RATIO (default 0.001) of its scheduled arrivals,
so short runs allow no drops.
Proxy pool
Imports draw from a finite pool, and the gate imports the whole pool before its
start snapshot. The suites' imports therefore repeat existing routes, and the
queue growth budget measures growth from other sources. By default the pool
holds 10,000 generated routes in the RFC 5737 documentation networks
(192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24). These addresses are
never routed on the public internet, so checks of these routes cannot reach a
third-party host, and every one checks as dead. Set PERF_PROXY_POOL_SIZE to
the route count you intend to measure, or set PERF_PROXY_FIXTURE_FILE to a
file of controlled, reachable proxies on an isolated network. Seeding fails when
no proxy is visible afterwards, for example because the blacklist rejected the
pool.
For full soak proof:
cd scripts/perf
PERF_SOAK_DURATION=24h ./run-gate.sh
For extended soak:
cd scripts/perf
PERF_SOAK_DURATION=72h ./run-gate.sh
Default growth/drop budgets
Configured in scripts/perf/assert-snapshot-delta.sh and scripts/perf/check-drop-budget.sh:
PERF_MAX_PROXY_QUEUE_DEPTH_DELTA=50000PERF_MAX_SCRAPESITE_QUEUE_DEPTH_DELTA=5000PERF_MAX_PROXY_STATISTICS_ROW_DELTA=25000000PERF_MAX_PROXY_STATISTICS_RESPONSE_ROWS_DELTA=250000PERF_MAX_PROXY_STATISTICS_BYTES_DELTA=16106127360PERF_MAX_DATABASE_BYTES_DELTA=21474836480PERF_PROXY_STAT_DROPS_BUDGET=0
Tune these to your hardware/profile and enforce them in CI/CD.
Authentication inputs
Every suite in one gate run uses the same account. Provide one of:
MAGLANE_TOKENMAGLANE_USER_EMAILandMAGLANE_USER_PASSWORD
Without either, run-gate.sh registers a new account with a random password
and saves its credentials to perf-account.env in the artifact directory. This
needs public registration, which the production Compose file disables; use a
token there.
Running with a local backend
You can run Postgres/Redis in Docker Compose and run backend from source (go run) for pre-push validation.
In that setup, pass backend logs to the drop-budget check:
# terminal 1
cd maglane-backend
go run ./cmd/maglane 2>&1 | tee /tmp/maglane-backend.log
# terminal 2
cd maglane/scripts/perf
PERF_BACKEND_LOG_FILE=/tmp/maglane-backend.log ./run-gate.sh
Drop-budget log source can be controlled with:
PERF_DROP_BUDGET_SOURCE=auto(default)PERF_DROP_BUDGET_SOURCE=composePERF_DROP_BUDGET_SOURCE=filePERF_DROP_BUDGET_SOURCE=skip, available only in smoke mode
Snapshots sum the legacy queues and all supported shard names, proxy shards
0 through 127 and scrape shards 0 through 63. This includes older shard
layouts after a shard-count change. A short atomic aggregate makes exactly 194
constant-time cardinality reads without scanning the Redis keyspace, so payload
key count does not increase its Redis work. Keep these bounds aligned with the
backend's supported limits. Statistics byte measurements include the partitioned parent,
all descendant partitions and their indexes. Redis authentication is passed to
the snapshot client. The gate saves start/end snapshots and JSON summaries for
all k6 suites. Its log window starts before the first suite; retain backend logs
for the complete run, including rotations.
Record route count, tenant sharing, active checker/scraper load, hardware, retention settings and dependency versions with release evidence. Include outages, import/delete churn, month boundaries, idle tunnels and a backup restore exercise. Use a representative 24-to-72-hour soak for release evidence. Regression tests and a short smoke run cannot establish that capacity or months of stability.
For a reproducible local baseline, the distribution repository includes
scripts/recovery.
It prepares one million authenticated routes shared across eight workspaces,
runs controlled checker/scraper services, rehearses coordinated recovery into
fresh volumes, and starts the corrected gate with telemetry. Its internal Docker
network prevents external requests. This Linux workflow needs a locally built
backend image, k6, Go, Python, and sufficient RAM and disk for the recorded profile.
Review its README before running it.
The baseline cycles imports through a finite existing pool using
PERF_PROXY_FIXTURE_FILE. That measures repeated ingestion. Record new-route
imports and deletion separately, and report the measured protocols, proxy
latency, resource limits, and maintenance settings with the result. A pending
24-hour run is incomplete evidence.
The local baseline retains an unknown Redis consumer lag as null. When stream
deletions make lag unavailable, it uses stream length plus pending IDs as an
upper bound on outstanding work. This can count an entry twice; it cannot omit
an unread entry or a pending ID whose payload was deleted. Existing backlog
limits and persistence-credit deductions apply to that larger bound. Missing
streams or groups and malformed diagnostics still fail validation.
Regression coverage and upgrade constraints
Statistics replay protection and persisted reputation refresh require the
proxy_statistic_events and proxy_reputation_refreshes tables. Run the
backend's --migrate-only job before starting upgraded backends, and stop
previous checker instances during the upgrade so all workers use lease renewal
and fenced completion.
The updated queue marks leases in scheduling scores. Previous checker versions
cannot safely share the queue with new workers. Bulk requeue preserves active
checks; expired leases remain available for normal recovery. Imports retain a
route in its owned shard until its worker completes.
Old and current hashes for the same route also reconcile atomically when a
worker encounters the old alias. The worker merges workspace owners, consumes
the alias, and preserves an active current lease without starting another
check. No queue flush or additional database migration is required for this
reconciliation. Keep the encryption key stable and the shard count consistent
across instances.
Real-service regression fixtures
Set MAGLANE_TEST_POSTGRES_DSN and MAGLANE_TEST_REDIS_URL to disposable services
when running the backend regression suites. They cover partial pending stream
recovery, duplicate usage accounting, rotator counts at 65,536 candidates,
usage writes with one million routes, uptime selection with unrelated history,
and source count coalescing.
Set MAGLANE_TEST_QUEUE_REDIS_URL to a separate empty disposable Redis database
to exercise queue races against real Redis. That fixture flushes its database.
These regressions include bulk requeue during an active check, imports from
legacy and other configured shards, and statistics cancellation followed by
replay of a 5,001-event batch. Unset REDIS_URL and redisUrl during full suites
so connection-failure fixtures can override their addresses.
Bulk deletion
Bulk proxy deletion has a separate PostgreSQL regression. From maglane-backend,
using an isolated test database:
MAGLANE_TEST_BULK_DELETE_ROUTES=70000 \
go test ./internal/database -run '^TestBulkProxyDeletion' -count=1 -v -timeout=10m
Keep MAGLANE_TEST_POSTGRES_DSN set for this command. The fixture includes
41 overlapping sources, four checker rules, tagged overrides, and shared route
ownership. It checks that source health refreshes once, orphan lookups stay
within PostgreSQL's parameter limit, and counts remain correct after a later
batch fails. Measure endpoint completion under normal checker and scraper load
as well; this fixture measures database work and excludes Redis cleanup and
live checker-snapshot refresh. This correction requires no schema or
configuration change.
Queue alias migration
Alias migration regressions cover concurrent aliases, current claims and
imports during migration preparation, stale source leases, and expired current
leases with plaintext and encrypted compatibility payloads. The separate
BenchmarkProxyQueueLegacyRekey benchmark measures migration with eight
existing owners and one added owner. Compare its cost separately from ordinary
plaintext queue throughput.
Shutdown and replay
On shutdown, the backend waits for producers to stop before canceling usage and statistics consumers. After statistics and reputation writers stop, read models refresh proxy filters, then drain all queued scrape-source statistics batches. Redis stays open until these stages finish. The SIGTERM regression checks both proxy filters and source counters in stream and memory modes, with more source associations than fit in one refresh batch. Statistics stream workers leave unacknowledged entries pending for recovery. The ledger prevents committed entries from counting twice. Pending entries from another consumer become recoverable after at least one minute idle. The volatile in-memory fallback retries its unfinished final buffer, with each flush bounded by a shared 30-second preparation/write deadline. It remains active until empty, so the overall background shutdown deadline reports an error if draining cannot finish. A forced exit has no durable recovery for results that exist only in memory.
Asynchronous read models
Reputation workers drain persisted requests continuously. Watch
maglane_proxy_reputation_refresh_pending and
maglane_proxy_reputation_refresh_oldest_age_seconds during sustained tests.
Tune worker count and batch size against database load. The defaults do not
establish capacity for a tens-of-millions installation.
Source health counts update in a separate coalescing loop, every 30 seconds for up to 100 source/workspace pairs by default. Large backlogs require more time or an adjusted batch size. Proxy-list health keeps its own refresh loop. Source notification work no longer recounts the pool after every route update; the coalesced refresh still aggregates the affected source pool.
Proxy-list refresh batches count workspace/route pairs. Shared owners of one physical route are grouped within that limit so the statement can reuse route metadata. An upsert still checks each owner's current evidence and lifecycle state, and orders writes by workspace and route. Grouping adds no capacity guarantee: measure current projection lag and write/index costs under the full resource profile. A failed clean drain still requires stopped-writer repair.
Unchanged proxy-list rows are filtered before the upsert acquires conflict locks. Changed and missing rows retain the existing null-safe conflict check. Validate every projected content field, unchanged timestamps and concurrent row locks. The filter adds a projection lookup inside the existing statement; measure its read cost alongside avoided locks. A stopped comparison that ran the original first cannot attribute later latency or WAL reductions to this filter, and cannot qualify readiness or load capacity.
Pending physical route IDs drain in sorted rounds to retain index locality. An unseen queued route reads the latest committed evidence when processed; invalidations for in-flight routes remain queued for another round. Sorting adds memory and CPU work, so include a large pending set in measurements and verify that new invalidations and failed prefixes survive until drained.
Include repeated imports of existing management in the workload. Those imports preserve lifecycle and usage counters without recounting the whole inventory; actual new ownership still refreshes authoritative capacity and peak usage. Measure import transaction/lock time alongside statistics and projection lag. Check mixed new/existing rows, finite quotas, encrypted credentials and deletion between the ownership conflict check and credential update. A no-addition import must neither resurrect deleted ownership nor write unchanged billing usage.
Periodic alive-count snapshots join a scoped active-ownership input to current evidence. Validate both sparse and dense evidence, one and multiple workspaces, protocol overrides, legacy generations and inactive ownership. PostgreSQL must avoid an ownership lookup for every alive result in the dense case. Record shared reads and temporary-file I/O: the scoped join can trade more temporary I/O for fewer repeated index probes. Stopped-data equivalence and query timings do not establish sustained capacity or replace recovery, smoke or load gates.
Dashboard country counts, reputation counts and top-proxy selection share one materialized active-workspace projection in a snapshot build. Measure the build's complete duration. Record base-table reads and temporary-file I/O together: sharing the input reduces repeated scans but can increase temporary storage. Check tenant/lifecycle scope, null scores, tie order, cancellation and retained history. Query equivalence or lower read counts cannot replace the full load gate.
Dashboard check figures read the workspace's monthly usage rows in the same statement as the snapshot: two primary-key range reads over about one row per month, independent of route count and of other workspaces.
After a recognized projection child deadline, the updater retains a smaller statement width within that owner batch. Two consecutive full-width commits using at most a quarter of the child timeout allow growth toward the configured ceiling. A successful full-width commit taking more than half of the child timeout also halves the next width, retaining its committed prefix without a retry interval. Short tails do not trigger this change; new batches still start at ordinary width. Record failed attempts, successful widths, round trips and write/index costs together. Verify that timing-based growth preserves contiguous progress, source-only retries, concurrent invalidations and clean drain behavior. The ordinary pair ceiling, invocation count, timer and timeout remain unchanged; smaller statements and unit delay fixtures do not establish sustained capacity.
Long-running storage growth
Ledger maintenance persists a replay floor before retiring event identities.
Measure proxy_statistic_events and its indexes and proxy_statistic_streams. Monitor pending age and maintenance progress; an old pending
event delays retirement. Accelerated regressions do not establish stability over
months. Sustained soaks should include dependency outages, import/delete churn,
month boundaries, and idle tunnels.