mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #7014] perf(node-sync): avoid redundant full inbound snapshots #6576
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6576
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/7014
Author: @HamedSanaei
Created: 10/29/2026
Status: 🔄 Open
Base:
main← Head:perf/node-traffic-snapshot-7007📝 Commits (4)
96e67aeperf(node-sync): reduce redundant full traffic snapshot readsfed8681docs(perf): format node snapshot measurement report0c90a62chore(merge): reconcile node snapshot caching with upstream maina92c5f9fix(nodes): harden compact snapshot reconciliation📊 Changes
48 files changed (+5286 additions, -465 deletions)
View changed files
📝
.github/workflows/ci.yml(+22 -2)📝
docs/content/docs/en/reference/api/inbounds.mdx(+14 -1)➕
docs/performance/cpu-profiles.csv(+9 -0)➕
docs/performance/cycles-postgres.csv(+49 -0)➕
docs/performance/cycles-sqlite.csv(+49 -0)➕
docs/performance/events-postgres.csv(+73 -0)➕
docs/performance/events-sqlite.csv(+73 -0)➕
docs/performance/node-traffic-snapshot-7007.md(+221 -0)➕
docs/performance/projections-postgres.csv(+13 -0)➕
docs/performance/projections-sqlite.csv(+13 -0)📝
docs/public/openapi.json(+299 -0)📝
frontend/public/openapi.json(+299 -0)📝
frontend/src/generated/examples.ts(+72 -0)📝
frontend/src/generated/schemas.ts(+217 -0)📝
frontend/src/generated/types.ts(+46 -0)📝
frontend/src/generated/zod.ts(+53 -0)📝
frontend/src/pages/api-docs/endpoints.ts(+16 -0)📝
internal/database/db.go(+15 -2)📝
internal/database/model/model.go(+2 -0)➕
internal/database/snapshot_revision.go(+91 -0)...and 28 more files
📄 Description
Summary
Reduce configuration work during the five-second node traffic poll while keeping counters and lifecycle state fresh. A capability-negotiated v1 endpoint sends configuration only after a durable revision change. The master skips reconciliation only when revision, ownership, lifecycle, membership and the complete remote-to-central inbound association validate; deployed aliases remain usable on cached ticks.
Why
The old path was
Remote.FetchTrafficSnapshot->GET /panel/api/inbounds/list-> full settings/preloads/UUID-SubID enrichment/shared-stat backfills ->SetRemoteTrafficsettings parsing andSyncInbound. Unchanged polls repeatedly paid those database, JSON and reconciliation costs.Closes #7007
Related: #7008, #7009
Implementation and compatibility
GET /panel/api/inbounds/trafficSnapshot?revision=...for admin, node-admin and node-sync. Reuse existing TLS/mTLS/outbound transport; monitor remains forbidden.SyncInbound. Keep the existing common delta, reset, renewal, dirty/justPushed, tombstone, ownership and GUID logic. Prune inactive caches.No depletion SQL, global freshness/quota semantics, heartbeat cadence, slim/full/detail response contract or frontend Inbounds behavior changes. #7008 and #7009 remain independently implementable. Existing OpenAPI paths/components were compared byte-for-value; only one route and five supporting schemas were added.
Measurements
Current matched SQLite fetch+merge reruns use 20,000 clients, eight inbounds, one/two peers, two attachments/client, twelve samples after five warmups, Go 1.27.3 and GOMAXPROCS=2:
One-peer unchanged idle/counter samples kept zero full master structural polls. In the two-peer fixture every client is shared across peers; existing ownership safeguards deliberately retain full master reconciliation. Wire/node-query work decreases there, but a large master CPU reduction is not claimed. Both cases avoided full node catalog fetches on unchanged ticks and refreshed affected peers after add/remove/config events.
Representative eight-counter writes over 4 MB of inbound configuration added about 0.30 ms on SQLite / 0.73 ms on PostgreSQL 16 when switching to generic trigger events. The 20,000-counter bounded decoder allocated 6.56 MB versus 13.82 MB, with validation CPU cost of about 43 ms versus 21 ms. These are measured tradeoffs, not claims that bounded decoding is faster.
The measurement report includes limits, current timings, repeat commands, and the original broader SQLite/PostgreSQL 18 ladders as historical results. The current end-to-end reruns use SQLite only; they isolate fetch+merge rather than the whole cron job or production latency.
Type of change
Areas affected
How was this tested?
c621ba90baseline: PASS, 404.522 seconds, zero skips; all four old/new version pairs, restart recovery and the three-panel traffic/reset chain.a92c5f9b905e1757af0e4d7d3e7b252fa354170e: CI and Docs CI.Existing API contracts, auth/scope/mTLS behavior and legacy fallbacks remain covered by the complete Go suite. No existing tests were removed, CI guards were strengthened, and the optimization remains enabled. No production deployment or live traffic was used.
Breaking changes
None for existing API/config users. Startup migration adds two hidden token columns, initializes legacy tokens and installs triggers with normal migration privileges. Metadata projections remain O(clients + attachments), catalogs consume per-node memory, SQLite structural edits incur an additional trigger update, and changed configurations deliberately retain full reconciliation cost. No new table/index/cache service is required.
Checklist
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.