mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6929] [MERGED] perf(inbounds): batch client identities for stats enrichment #6526
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#6526
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/6929
Author: @HamedSanaei
Created: 10/25/2026
Status: ✅ Merged
Merged: 10/25/2026
Merged by: @MHSanaei
Base:
main← Head:perf/inbound-stats-6926📝 Commits (6)
5ffaa09perf(inbounds): batch client identities for stats enrichment85385d2docs(tests): preserve scale helper operating notescf9ccfachore(ci): resolve upstream merge conflict for PR #69299d19803Merge branch 'main' into perf/inbound-stats-69267817816docs(inbounds): keep the #6436 reason for reading identities from clients4defd85Merge branch 'main' into perf/inbound-stats-6926📊 Changes
11 files changed (+561 additions, -38 deletions)
View changed files
📝
.github/workflows/ci.yml(+10 -0)📝
docs/architecture.md(+6 -0)📝
internal/web/service/bulk_clients_test.go(+1 -1)📝
internal/web/service/client_link.go(+36 -0)➕
internal/web/service/inbound_client_stats_benchmark_test.go(+194 -0)➕
internal/web/service/inbound_client_stats_postgres_test.go(+40 -0)➕
internal/web/service/inbound_client_stats_test.go(+215 -0)📝
internal/web/service/inbound_clients.go(+19 -20)📝
internal/web/service/inbound_clients_stale_uuid_test.go(+18 -3)📝
internal/web/service/inbound_runtime_depleted_filter_test.go(+13 -0)📝
internal/web/service/scale_helpers_test.go(+9 -14)📄 Description
Summary
Batch inbound-statistics identities in a narrow
clients/client_inboundsprojection, bounded to 400 distinct inbound IDs per query. Keep the existing full client readers for subscriptions, Xray configuration and other callers.Why
backfillClientStatspreviously loaded and converted every client field once per inbound, although enrichment only consumes UUID, email and subscription ID. This repeated SQL round trips and full-record decoding on every list read.The new reader honors the supplied transaction and returns no partial results after a failed chunk. Enrichment preserves lowercase identity/seen keys, raw email matching, client-ID append order, sibling-owned traffic outside the requested inbound set, exact counters/lifecycle/last-online fields, and fresh UUID/SubID values even if a later traffic page fails. Empty identities still clear stale fields; absent traffic is not manufactured.
Closes #6926.
Type of change
Areas affected
No schema, migration, endpoint, generated API contract or subscription-reader changes.
How was this tested?
Passed on Windows amd64 with Go 1.27.3, CGO/GCC, Node 26.12.1/npm 11.20.0, SQLite 3.53.4, and disposable PostgreSQL 18.6 and 16.15:
make verifypassed generation freshness, Go/frontend lint, format check, typecheck, all Go tests, 214 frontend test files/2,000 tests including headless browser stories, full build, Storybook build and docs-vs-panel OpenAPI comparison. Package serialization for the race run changes scheduling only; all tests and race instrumentation remain enabled.Regression-first evidence: the original code made eight clients-table queries for eight preloaded inbounds and 403 queries for 401 distinct IDs plus duplicates. Both assertions failed before the production edit, then passed at one and two queries respectively. A later identity-query failure originally partially mutated stats; the new reader leaves them untouched. Tests also exercise empty/unlinked requests, second traffic-page failure without partial append, transaction visibility/rollback, repeated backfill, mixed-case identities, successive UUID/SubID mutations and generated Xray config excluding sibling-owned depleted clients.
Actual-process HTTP smoke used a freshly built panel with a disposable SQLite DB: two VLESS inbounds shared
stats@smoke; normalized UUID/SubID were changed to22222222-2222-2222-2222-222222222222/fresh-subwhile settings stayed stale. Two full-list reads and both detail reads returned exactly one stats entry per attachment with upload 123, download 456 and last-online 1700000000123 preserved. Slim-list backfill retained its existing omission of UUID/SubID enrichment. Real master/node E2E passed; it does not claim live-Xray or firewall coverage.Measurements
Before/after fixtures were identical: 1k/10k/20k clients across eight inbounds, disjoint attachments or every tenth client additionally attached to the next inbound, plus representative full-record host-rule/reverse/WG/keepalive fields. Seed and one warmup were outside measurement; every iteration recreated inbound/stat slices.
Both SQLite and PostgreSQL completed the entire 18-workload enrichment/full-list/slim-list ladder with:
Additional matched
-benchtime=10x -count=1runs used the original production source in an isolated base snapshot and the same fixture. Representative 20k/shared enrichment results, exactly ten iterations each:All 18 workloads changed eight identity queries/op to one; traffic-query counts and result contents stayed unchanged. GORM client-observed SQL elapsed is distinct from server execution time and can include nested preload spans.
PostgreSQL
pg_stat_statementsdeltas for the same ten 20k/shared invocations, captured before fixture teardown and filtered to this database's identity SELECT shapes:stats_resetwas unchanged anddealloc=0; no cluster-wide statistics reset was used. This is a read/decoding reduction, not a WAL-reduction claim or a production latency guarantee.Review follow-up
Approved documentation-only commit
85385d2fe0db8acbc5206107b9805096ab097abdrestores the scale-helper persistent-SQLite-path option, direct-seeding rationale and dialect-specific reset notes. Production fix5ffaa09c4436043ba54fba93d5da213bcd1cd56dremains unchanged; no published history was rewritten.GOFLAGS=-p=1 make verify && GOFLAGS=-p=1 make racepassed again.Breaking changes
None.
Checklist
go build ./...and the test suite pass locally.npm run lint,npm run typecheck, andnpm run buildpass. (Executed by the full gate; this PR is backend-only.)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.