perf(node-sync): avoid redundant full inbound snapshots (#7014)

Every five seconds the master fetched each node's complete inbound list, settings JSON and enrichment included, parsed it and reconciled every client, whether anything had changed or not.

A node that advertises traffic-snapshot-v1 now answers a revisioned endpoint: counters and lifecycle state on every poll, inbound configuration and attachments only when its revision changed. The master skips structural parsing and client reconciliation while the node's revision, its own rows for that node, the lifecycle state and the full remote-to-central inbound mapping are all unchanged; anything else falls back to the full merge. Old and new panels keep talking through the previous endpoints.

Revisions come from a hidden per-row token on inbounds and clients, maintained by database triggers on SQLite and PostgreSQL so that direct and background writes count too. Counter and timestamp updates leave it alone. The triggers are dropped before migrations and recreated after them, and the previous build runs unchanged on a database that carries them.

Measured here at 20,000 clients on one node, per idle poll: master SQL statements 551 -> 44, node statements 55 -> 4, transfer 23.0 MB -> 4.8 MB. When every client is shared between nodes the ownership checks keep the full master merge, so only the node and the transfer get cheaper. The node still reads every membership and counter on each poll.

Closes #7007
This commit is contained in:
Hamed
2026-11-29 18:38:51 +03:30
committed by GitHub
parent a9d22498c2
commit 1ec55aed30
41 changed files with 4813 additions and 478 deletions
+22 -2
View File
@@ -43,7 +43,8 @@ jobs:
- name: Test
run: |
go list ./... | grep -v '/frontend/node_modules/' > /tmp/go-packages.txt
go test -shuffle=on -count=1 $(cat /tmp/go-packages.txt)
mapfile -t go_packages < /tmp/go-packages.txt
go test -shuffle=on -count=1 "${go_packages[@]}"
postgres-durable-first:
runs-on: ubuntu-latest
@@ -193,6 +194,16 @@ jobs:
exit 1
fi
- name: PostgreSQL node snapshot regressions
run: |
set -o pipefail
go test -p=1 ./internal/database ./internal/web/service -run '^(TestSnapshotRevisionsDirectWritesAndRollback|TestNodeSnapshotUnchangedAvoidsSettingsAndDetectsDirectEdits|TestNodeSnapshotMergeSkipsUnchangedStructureAndPreservesDeltas|TestNodeSnapshotReadDoesNotHoldTrafficWriter|TestNodeSnapshotCanceledReadReleasesConnection|TestNodeSnapshotReopenInvalidatesCatalog|TestNodeSnapshotCachedAliasPreservesTraffic|TestNodeSnapshotAliasInvalidCacheFallsBack|TestNodeSnapshotAliasValidatesEntireMapping|TestNodeSnapshotAliasQuotaDisableAndRenewal|TestSnapshotRevisionPostgresTypeDDL|TestSnapshotRevisionMigrationRecreationAndReopen)$' -count=1 -v | tee /tmp/postgres-node-snapshot.log
passed=$(grep -c -- '^--- PASS' /tmp/postgres-node-snapshot.log || true)
if [ "$passed" -ne 12 ]; then
echo "expected 12 passing node snapshot tests, got $passed" >&2
exit 1
fi
- name: PostgreSQL schema and migration tests
run: |
set -o pipefail
@@ -323,7 +334,8 @@ jobs:
run: |
go list ./... | grep -v '/frontend/node_modules/' > /tmp/go-packages.txt
# internal/web/service runs ~10x slower under -race and overruns the 10m default.
go test -race -shuffle=on -count=1 -timeout 25m $(cat /tmp/go-packages.txt)
mapfile -t go_packages < /tmp/go-packages.txt
go test -race -shuffle=on -count=1 -timeout 25m "${go_packages[@]}"
# A real master and node panel, each its own process, driven through node sync.
# A SKIP here means the binary was never handed over, so it fails the job.
@@ -335,6 +347,14 @@ jobs:
with:
go-version-file: go.mod
cache: true
- name: Build legacy node protocol baseline
run: |
baseline_ref=c621ba9014a6aa21fd7c9ecf45655e44e24ebf13
git fetch --no-tags --depth=1 origin "$baseline_ref"
baseline_src=$(mktemp -d)
git archive "$baseline_ref" Makefile go.mod go.sum main.go internal scripts/install-amneziawg-kernel.sh | tar -x -C "$baseline_src"
(cd "$baseline_src" && make dist-stub && go build -o "$RUNNER_TEMP/x-ui-node-baseline" .)
echo "XUI_NODE_E2E_OLD_BINARY=$RUNNER_TEMP/x-ui-node-baseline" >> "$GITHUB_ENV"
- name: Master + node end to end
run: |
set -o pipefail